]> Creatis software - bbtkGEditor.git/blobdiff - lib/EditorGraphicBBS/bbsKernelEditorGraphic/wxVtkSceneManager.cxx
Organizing code, the state now is in the view and the general render was simplified...
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsKernelEditorGraphic / wxVtkSceneManager.cxx
index 7370b197621b13d3564a857ce4f0e97320845d33..23ea678c0a0d21ca6bfe58265e8a10e5256724d4 100644 (file)
@@ -135,14 +135,18 @@ namespace bbtk
 
 
        //=========================================================================
+
        void wxVtkSceneManager::disconnectDrop()
        {
                _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
        }
+
        //=========================================================================
+
        wxVtkSceneManager::~wxVtkSceneManager()
        {
        }
+
        //=========================================================================
 
        void wxVtkSceneManager::configureBaseView()
@@ -157,14 +161,9 @@ namespace bbtk
                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()->ResetCamera(-100,100,-100,100,900,1000);
                
-
                _baseView->GetRenderer()->SetBackground(0.9,0.9,0.9);
                _baseView->GetRenderer()->GradientBackgroundOff();
                _baseView->Refresh();
@@ -203,7 +202,15 @@ namespace bbtk
                int cantObjects = _objects.size();
                cantObjects++;
                std::stringstream stream;
-               stream << "Box " << cantObjects;
+               
+               if(cantObjects<10)
+               {
+                       stream << "Box0" << cantObjects;
+               }
+               else
+               {
+                       stream << "Box" << cantObjects;
+               }
                std::string arraystring = stream.str();
 
                model->setBBTKName(arraystring);
@@ -220,7 +227,7 @@ namespace bbtk
                for(itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput)
                {
                        BlackBoxInputDescriptor *desc = itInput->second;
-                       createGInputPort(desc,model,i);
+                       createGInputPort(GINPUTPORT,i,model,desc);
                        i++;
                }
 
@@ -232,7 +239,7 @@ namespace bbtk
                for(itOutput = descriptorOutMap.begin();itOutput != descriptorOutMap.end(); ++itOutput)
                {
                        BlackBoxOutputDescriptor *desc = itOutput->second;
-                       createGOutputPort(desc,model,i);
+                       createGOutputPort(GOUTPUTPORT,i,model,desc);
                        i++;
                }
 
@@ -253,44 +260,32 @@ namespace bbtk
                //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);
+               //Add the object to the objects list 
+               _objects.push_back(controller);
+
+               int newId = _controllers.size();
+               controller->setId(newId);
+               _controllers[newId] = controller;
 
        }
 
        //=========================================================================
 
-       void wxVtkSceneManager::createGOutputPort(BlackBoxOutputDescriptor *desc,GBlackBoxModel *blackBox, int pos)
+       void wxVtkSceneManager::createGInputPort(int portType, int posinBox,GBlackBoxModel *blackBox, BlackBoxInputDescriptor *desc)
        {
-               int type = GPORT;
-
-               //Create the MVC Objects
-               GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
-               vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
-               GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
-
-               model->registerInBox(blackBox,GOUTPUTPORT, pos);
-               blackBox->addOutputPort(model);
-               
-               model->addObserver(view);
-               model->addObserver(this);
+               createGPort(portType,posinBox,blackBox);
+       }
 
-               //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::createGOutputPort(int portType, int posinBox,GBlackBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
+       {
+               createGPort(portType,posinBox,blackBox);
        }
 
        //=========================================================================
 
-       void wxVtkSceneManager::createGInputPort(BlackBoxInputDescriptor *desc,GBlackBoxModel *blackBox, int pos)
+       void wxVtkSceneManager::createGPort(int portType, int posInBox,GBlackBoxModel *blackBox)
        {
                int type = GPORT;
 
@@ -299,9 +294,9 @@ namespace bbtk
                vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
                GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
 
-               model->registerInBox(blackBox,GINPUTPORT,pos);
-               blackBox->addInputPort(model);
-
+               model->registerInBox(blackBox,portType, posInBox);
+               blackBox->addOutputPort(model);
+               
                model->addObserver(view);
                model->addObserver(this);
 
@@ -314,8 +309,14 @@ namespace bbtk
                //Associates the controller with the correspondent model and view
                controller->setModelAndView(model,view);
 
+               model->notifyObservers();
+
                //Register the controller of the new object
                registerController((InteractorStyleMaracas*) controller);
+               
+               int newId = _controllers.size();
+               controller->setId(newId);
+               _controllers[newId] = controller;
        }
 
        //=========================================================================
@@ -325,8 +326,8 @@ namespace bbtk
                manualContourControler* manContourControl       = new manualContourControler();
                GConnectorView* manViewerContour        = new GConnectorView();
                manualContourModel* manContourModel     = new manualContourModel();
+               manContourModel->SetCloseContour(false);
 
-               
                manViewerContour->SetModel( manContourModel );
                manViewerContour->SetWxVtkBaseView( _baseView );
                manViewerContour->SetRange( 0.5 );
@@ -340,14 +341,16 @@ namespace bbtk
                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();                     
+
+               manViewerContour->RefreshContour();
+
                registerController((InteractorStyleMaracas*) manContourControl);
 
        }
@@ -382,25 +385,25 @@ namespace bbtk
 
        //=========================================================================
        
-       void wxVtkSceneManager::update(int command)
+       void wxVtkSceneManager::update(int idObservable,int command)
        {
                
                if(command==INIT_CREATION_CONTOUR)
-               {
-                       for(int i = 0; i<_objects.size();i++)
+               {       
+                       GObjectController* cont = _controllers[idObservable];
+                       if(cont->getGObjectType() == GPORT)
                        {
-                               if(_objects[i]->getGObjectType() == GBLACKBOX)
-                               {
-                                       
-                                       GPortModel* startOutputPort=((GBlackBoxModel*)_objects[i])->getStartOutputPort();
-                                       createGConnector(startOutputPort);
+                               GPortController* controller = (GPortController*)cont;
+                               vtkGPortView* view = (vtkGPortView*)controller->getView();
 
-                               }
-                               else
+                               if(view->getState() == CREATING_CONTOUR)
                                {
-                                       // The others must not react to events
+                                       //pre: The port in this state is an output port                                 
+                                       GPortModel* startOutputPort = (GPortModel*)controller->getModel();
+                                       createGConnector(startOutputPort);
                                }
                        }
+                       
                }
        }