]> Creatis software - bbtkGEditor.git/blobdiff - lib/EditorGraphicBBS/bbsKernelEditorGraphic/wxVtkSceneManager.cxx
Important change in the project to visualize the contour when the output was selected...
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsKernelEditorGraphic / wxVtkSceneManager.cxx
index 73dcda3d84d0856026e6eda7b2dce6c55391ee62..7370b197621b13d3564a857ce4f0e97320845d33 100644 (file)
@@ -50,10 +50,12 @@ namespace bbtk
                        
                        _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(parent);
                        registerController(this);
-
                        configureBaseView();
 
-                       /* JUST TO TEST
+                       ///// ******* TO ERASE *******
+                       //JUST TO TEST
+                       //              
+                       /*
                        vtkConeSource *cone = vtkConeSource::New();
        
                   cone->SetResolution(10);
@@ -65,16 +67,13 @@ namespace bbtk
                        
                   act->SetMapper(map);
                        
-                       /////////////////////
-
-
                   vtkPoints *_pts = vtkPoints::New();
                        _pts->SetNumberOfPoints(4);
 
-                       _pts->SetPoint(0, -1    , -1    , 0 );
-                       _pts->SetPoint(1,  1    , -1    , 0 );
-                       _pts->SetPoint(2,  1    ,  1    , 0 );
-                       _pts->SetPoint(3, -1    ,  1    , 0 );
+                       _pts->SetPoint(0, -100  , -100  , 900 );
+                       _pts->SetPoint(1,  100  , -100  , 900 );
+                       _pts->SetPoint(2,  100  ,  100  , 900 );
+                       _pts->SetPoint(3, -100  ,  100  , 900 );
        
                        vtkCellArray *lines = vtkCellArray::New();
                        lines->InsertNextCell(5);
@@ -96,18 +95,45 @@ namespace bbtk
 
                        getRenderer()->AddActor(_pointVtkActor);
 
-                       */
+                       
+                       
+                                       
+                  vtkPoints *_pts2 = vtkPoints::New();
+                       _pts2->SetNumberOfPoints(4);
+
+                       _pts2->SetPoint(0, -105 , -100  , -50 );
+                       _pts2->SetPoint(1,  100 , -100  , -50 );
+                       _pts2->SetPoint(2,  100 ,  100  , -50 );
+                       _pts2->SetPoint(3, -105 ,  100  , -50 );
+       
+                       vtkCellArray *lines2 = vtkCellArray::New();
+                       lines2->InsertNextCell(5);
+                       lines2->InsertCellPoint(0);
+                       lines2->InsertCellPoint(1);
+                       lines2->InsertCellPoint(2);
+                       lines2->InsertCellPoint(3);
+                       lines2->InsertCellPoint(0);
 
-                       /////////////////////
+                       vtkPolyData *_pd2 = vtkPolyData::New();
+                       _pd2->SetPoints( _pts2 );
+                       _pd2->SetLines( lines2 );
 
-                  //getRenderer()->AddActor(act);
-               
-                  //getRenderer()->Render();
+                       vtkActor *_pointVtkActor2       =       vtkActor::New();
+                       vtkPolyDataMapper* _bboxMapper2         =       vtkPolyDataMapper::New();
 
+                       _bboxMapper2->SetInput(_pd2);
+                       _pointVtkActor2->SetMapper(_bboxMapper2);
 
+                       getRenderer()->AddActor(_pointVtkActor2);
+
+                       */
+                       // ******* TO ERASE *******
+                       /////////////////////
+                       
                }
        }
 
+
        //=========================================================================
        void wxVtkSceneManager::disconnectDrop()
        {
@@ -121,12 +147,24 @@ namespace bbtk
 
        void wxVtkSceneManager::configureBaseView()
        {
-               vtkInteractorStyleImage *style = vtkInteractorStyleImage::New();
-               _baseView->GetWxVTKRenderWindowInteractor()->SetInteractorStyle(style);
-               //_baseView->GetRenderer()->SetActiveCamera(_baseView->GetCamera());
-           //_baseView->GetRenderer()->ResetCamera ();
-               //_baseView->GetCamera()->SetParallelProjection(true);
+               vtkInteractorStyleBaseView2D *interactorstylebaseview = vtkInteractorStyleBaseView2D::New();
+
+               _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
+
+               // Important to activate the 2D interaction system
+               wxVTKRenderWindowInteractor *iren = _baseView->GetWxVTKRenderWindowInteractor();
+               interactorstylebaseview->SetInteractor ( iren );
+               iren->SetInteractorStyle(interactorstylebaseview);
+               interactorstylebaseview->SetwxVtkBaseView(_baseView);
+               
+               double posCamera[3];
+               _baseView->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
+               _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0,0,1000);
+               _baseView->GetRenderer()->GetActiveCamera()->GetPosition(posCamera);
+               _baseView->GetRenderer()->ResetCamera();
+               _baseView->GetRenderer()->ResetCameraClippingRange();
                
+
                _baseView->GetRenderer()->SetBackground(0.9,0.9,0.9);
                _baseView->GetRenderer()->GradientBackgroundOff();
                _baseView->Refresh();
@@ -136,9 +174,14 @@ namespace bbtk
 
        void wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxName)
        {
+
+               int windowWidth=_baseView->GetRenWin()->GetSize()[0];
+               int windowHeight=_baseView->GetRenWin()->GetSize()[1];
+
                int type = GBLACKBOX;
 
                //Create the MVC Objects
+               
                GBlackBoxModel *model = (GBlackBoxModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
                vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
                GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
@@ -146,27 +189,51 @@ namespace bbtk
                BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxName);
                
                //Prepares the initial model
+               //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height  
+
                double xx = x;
-               double yy =  _baseView->GetRenWin()->GetSize()[1]-y;
-               double zz = 0;
+               double yy =  windowHeight-y;
+               
+               //z value is not important yet, because it is only used a parallel projection
+               double zz = 900;
+
                _baseView->TransCoordScreenToWorld(xx,yy,zz);
                model->setInicPoint(xx,yy,zz);
-               //model->addObserver(view);
+               
+               int cantObjects = _objects.size();
+               cantObjects++;
+               std::stringstream stream;
+               stream << "Box " << cantObjects;
+               std::string arraystring = stream.str();
+
+               model->setBBTKName(arraystring);
+               model->setBBTKType(boxName);
+                               
+               model->addObserver(view);
+               model->addObserver(this);
 
                //Iterate and create the input ports
-               std::map<std::string, BlackBoxInputDescriptor*> descriptorMap = descriptor->GetInputDescriptorMap();
-               std::map<std::string, BlackBoxInputDescriptor*>::iterator it;
+               std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap = descriptor->GetInputDescriptorMap();
+               std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
 
-               //ERASE
-               cantTemp=0;
+               int i=0;
+               for(itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput)
+               {
+                       BlackBoxInputDescriptor *desc = itInput->second;
+                       createGInputPort(desc,model,i);
+                       i++;
+               }
 
-               for(it = descriptorMap.begin(); it != descriptorMap.end(); ++it)
+               //Iterate and create the output ports
+               std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap = descriptor->GetOutputDescriptorMap();
+               std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
+
+               i=0;
+               for(itOutput = descriptorOutMap.begin();itOutput != descriptorOutMap.end(); ++itOutput)
                {
-                       BlackBoxInputDescriptor *desc = it->second;
-                       createGInputPort(desc,model);
-                       
-                       //ERASE
-                       cantTemp+=2;
+                       BlackBoxOutputDescriptor *desc = itOutput->second;
+                       createGOutputPort(desc,model,i);
+                       i++;
                }
 
 
@@ -179,16 +246,21 @@ namespace bbtk
                //Associates the controller with the correspondent model and view
                controller->setModelAndView(model,view);
 
-               //Refresh renderwindow with new objects
-               refreshRenderWindow();
+               //Resgiter change to the observers of the actual model
+               model->setChanged();
+               model->notifyObservers();
                
+               //Register the controller of the new object
                registerController((InteractorStyleMaracas*) controller);
 
+               //Add the object to the objects list (only boxes and connectors)
+               _objects.push_back(model);
+
        }
 
        //=========================================================================
 
-       void wxVtkSceneManager::createGInputPort(BlackBoxInputDescriptor *desc,GBlackBoxModel *blackBox)
+       void wxVtkSceneManager::createGOutputPort(BlackBoxOutputDescriptor *desc,GBlackBoxModel *blackBox, int pos)
        {
                int type = GPORT;
 
@@ -197,19 +269,11 @@ namespace bbtk
                vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
                GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
 
-               model->registerInBox(blackBox);
-               blackBox->addInputPort(model);
-
+               model->registerInBox(blackBox,GOUTPUTPORT, pos);
+               blackBox->addOutputPort(model);
                
-               //Prepares the initial model
-               double xx = 0;
-               double yy = 0;
-               double zz = 0;
-               blackBox->getInicPoint(xx,yy,zz);
-
-               xx++;
-               yy+=cantTemp;
-               model->setInicPoint(xx,yy,zz);
+               model->addObserver(view);
+               model->addObserver(this);
 
                //Associates the view with the correspondent renderer and the  model.
                //(NOTE: Refresh is only made by the view)
@@ -219,11 +283,14 @@ namespace bbtk
                
                //Associates the controller with the correspondent model and view
                controller->setModelAndView(model,view);
+
+               //Register the controller of the new object
+               registerController((InteractorStyleMaracas*) controller);
        }
 
        //=========================================================================
 
-       void wxVtkSceneManager::createGOutputPort(BlackBoxOutputDescriptor *desc,GBlackBoxModel *blackBox)
+       void wxVtkSceneManager::createGInputPort(BlackBoxInputDescriptor *desc,GBlackBoxModel *blackBox, int pos)
        {
                int type = GPORT;
 
@@ -232,8 +299,57 @@ namespace bbtk
                vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
                GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
 
-               model->registerInBox(blackBox);
-               blackBox->addOutputPort(model);
+               model->registerInBox(blackBox,GINPUTPORT,pos);
+               blackBox->addInputPort(model);
+
+               model->addObserver(view);
+               model->addObserver(this);
+
+               //Associates the view with the correspondent renderer and the  model.
+               //(NOTE: Refresh is only made by the view)
+               view->setModel(model);
+               view->setBaseView(_baseView);
+               view->initVtkObjects();
+               
+               //Associates the controller with the correspondent model and view
+               controller->setModelAndView(model,view);
+
+               //Register the controller of the new object
+               registerController((InteractorStyleMaracas*) controller);
+       }
+
+       //=========================================================================
+
+       void wxVtkSceneManager::createGConnector(GPortModel* startPort)
+       {
+               manualContourControler* manContourControl       = new manualContourControler();
+               GConnectorView* manViewerContour        = new GConnectorView();
+               manualContourModel* manContourModel     = new manualContourModel();
+
+               
+               manViewerContour->SetModel( manContourModel );
+               manViewerContour->SetWxVtkBaseView( _baseView );
+               manViewerContour->SetRange( 0.5 );
+               manViewerContour->SetZ( 900 );
+
+               manViewerContour->SetColorNormalContour(0, 0, 1);
+               manViewerContour->SetColorEditContour(0.5, 0.5, 0.5);
+               manViewerContour->SetColorSelectContour(1, 0.8, 0);
+               manViewerContour->SetWidthLine(1);
+
+               manContourControl->SetModelView( manContourModel , manViewerContour );
+               manContourControl->Configure();
+               int i,sizeLstPoints = manContourModel->GetSizeLstPoints();
+               //std::cout<<"RaC wxVtkSceneManager::createGConnector "<<this<<" size:"<<sizeLstPoints<<std::endl;
+               for ( i=0; i<sizeLstPoints; i++ )
+               {
+                       manViewerContour->AddPoint();
+               }
+
+               manContourControl->CreateNewManualContour();
+               manViewerContour->RefreshContour();                     
+               registerController((InteractorStyleMaracas*) manContourControl);
+
        }
 
        //=========================================================================
@@ -258,19 +374,38 @@ namespace bbtk
                return _baseView->GetRenWin();
        }
        //=========================================================================
-       
-       void wxVtkSceneManager::refreshRenderWindow()
-       {
-               _baseView->GetRenWin()->Render();
-       }
-       //=========================================================================
 
        bool wxVtkSceneManager::OnMouseMove()
        {
-               //cout<<"RaC wxVtkSceneManager::OnMouseMove "<<endl;
                return true;
        }
+
        //=========================================================================
+       
+       void wxVtkSceneManager::update(int command)
+       {
+               
+               if(command==INIT_CREATION_CONTOUR)
+               {
+                       for(int i = 0; i<_objects.size();i++)
+                       {
+                               if(_objects[i]->getGObjectType() == GBLACKBOX)
+                               {
+                                       
+                                       GPortModel* startOutputPort=((GBlackBoxModel*)_objects[i])->getStartOutputPort();
+                                       createGConnector(startOutputPort);
+
+                               }
+                               else
+                               {
+                                       // The others must not react to events
+                               }
+                       }
+               }
+       }
+
+       //=========================================================================
+
 }  // EO namespace bbtk
 
 // EOF