]> Creatis software - bbtkGEditor.git/blobdiff - lib/EditorGraphicBBS/bbsKernelEditorGraphic/wxVtkSceneManager.cxx
First prototype works. Basic boxes construction, evenct handling and colors represent...
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsKernelEditorGraphic / wxVtkSceneManager.cxx
index f238a734a9c25eb2e12e679edbbce0a900047804..bbe321e5195144670282d474a359aaf0a5c1a2bb 100644 (file)
@@ -50,10 +50,11 @@ 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,9 +66,6 @@ namespace bbtk
                        
                   act->SetMapper(map);
                        
-                       /////////////////////
-
-
                   vtkPoints *_pts = vtkPoints::New();
                        _pts->SetNumberOfPoints(4);
 
@@ -95,16 +93,10 @@ namespace bbtk
                        _pointVtkActor->SetMapper(_bboxMapper);
 
                        getRenderer()->AddActor(_pointVtkActor);
-
                        
-*/
+                       // ******* TO ERASE *******
                        /////////////////////
-
-                  //getRenderer()->AddActor(act);
-               
-                  //getRenderer()->Render();
-
-
+                       
                }
        }
 
@@ -125,27 +117,30 @@ namespace bbtk
 
                _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
 
+               // Important to activate the 2D interaction system
                wxVTKRenderWindowInteractor *iren = _baseView->GetWxVTKRenderWindowInteractor();
                interactorstylebaseview->SetInteractor ( iren );
                iren->SetInteractorStyle(interactorstylebaseview);
                interactorstylebaseview->SetwxVtkBaseView(_baseView);
-
-               //_baseView->GetRenderer()->SetActiveCamera(_baseView->GetCamera());
-           //_baseView->GetRenderer()->ResetCamera ();
-               //_baseView->GetCamera()->SetParallelProjection(true);
                
                _baseView->GetRenderer()->SetBackground(0.9,0.9,0.9);
                _baseView->GetRenderer()->GradientBackgroundOff();
                _baseView->Refresh();
+
        }
 
        //=========================================================================
 
        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);
@@ -153,44 +148,39 @@ 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 yy =  windowHeight-y;
+               
+               //z value is not important yet, because it is only used a parallel projection
                double zz = 0;
+
                _baseView->TransCoordScreenToWorld(xx,yy,zz);
                model->setInicPoint(xx,yy,zz);
+               
                model->addObserver(view);
 
                //Iterate and create the input ports
                std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap = descriptor->GetInputDescriptorMap();
                std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
 
-               //ERASE
-               cantTemp=0;
-
                for(itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput)
                {
                        BlackBoxInputDescriptor *desc = itInput->second;
                        createGInputPort(desc,model);
-                       
-                       //ERASE
-                       cantTemp+=2;
                }
 
-
                //Iterate and create the output ports
                std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap = descriptor->GetOutputDescriptorMap();
                std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
 
-               //ERASE
-               cantTemp=0;
 
                for(itOutput = descriptorOutMap.begin();itOutput != descriptorOutMap.end(); ++itOutput)
                {
                        BlackBoxOutputDescriptor *desc = itOutput->second;
                        createGOutputPort(desc,model);
                        
-                       //ERASE
-                       cantTemp+=2;
                }
 
 
@@ -203,8 +193,9 @@ 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);
@@ -225,19 +216,9 @@ namespace bbtk
                vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
                GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
 
-               model->registerInBox(blackBox);
+               model->registerInBox(blackBox,GOUTPUTPORT);
                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);
-
                //Associates the view with the correspondent renderer and the  model.
                //(NOTE: Refresh is only made by the view)
                view->setModel(model);
@@ -262,19 +243,9 @@ namespace bbtk
                vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
                GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
 
-               model->registerInBox(blackBox);
+               model->registerInBox(blackBox,GINPUTPORT);
                blackBox->addInputPort(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);
 
                //Associates the view with the correspondent renderer and the  model.
                //(NOTE: Refresh is only made by the view)
@@ -311,16 +282,9 @@ namespace bbtk
                return _baseView->GetRenWin();
        }
        //=========================================================================
-       
-       void wxVtkSceneManager::refreshRenderWindow()
-       {
-               _baseView->GetRenWin()->Render();
-       }
-       //=========================================================================
 
        bool wxVtkSceneManager::OnMouseMove()
        {
-               //cout<<"RaC wxVtkSceneManager::OnMouseMove "<<endl;
                return true;
        }
        //=========================================================================