]> Creatis software - bbtkGEditor.git/blobdiff - lib/EditorGraphicBBS/bbsKernelEditorGraphic/wxVtkSceneManager.cxx
*** empty log message ***
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsKernelEditorGraphic / wxVtkSceneManager.cxx
index e476c03cf225682f21c2d718023058d3a18dedd0..f238a734a9c25eb2e12e679edbbce0a900047804 100644 (file)
@@ -53,6 +53,7 @@ namespace bbtk
 
                        configureBaseView();
 
+                       /*//JUST TO TEST
                        vtkConeSource *cone = vtkConeSource::New();
        
                   cone->SetResolution(10);
@@ -95,8 +96,8 @@ namespace bbtk
 
                        getRenderer()->AddActor(_pointVtkActor);
 
-
-
+                       
+*/
                        /////////////////////
 
                   //getRenderer()->AddActor(act);
@@ -120,13 +121,22 @@ namespace bbtk
 
        void wxVtkSceneManager::configureBaseView()
        {
-               vtkInteractorStyleImage *temp = vtkInteractorStyleImage::New();
-               _baseView->GetWxVTKRenderWindowInteractor()->SetInteractorStyle(temp);
-               _baseView->GetRenderer()->SetActiveCamera(_baseView->GetCamera());
-           _baseView->GetRenderer()->ResetCamera ();
-               _baseView->GetCamera()->SetParallelProjection(true);
-               _baseView->Refresh();
+               vtkInteractorStyleBaseView2D *interactorstylebaseview = vtkInteractorStyleBaseView2D::New();
 
+               _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
+
+               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();
        }
 
        //=========================================================================
@@ -136,30 +146,146 @@ namespace bbtk
                int type = GBLACKBOX;
 
                //Create the MVC Objects
-               GObjectModel *model = GObjectsMVCFactory::getInstance()->createGObjectModel(type);
+               GBlackBoxModel *model = (GBlackBoxModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
                vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
                GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
                
+               BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxName);
+               
                //Prepares the initial model
                double xx = x;
-               double yy = y;
-               double zz = 900;
-
+               double yy =  _baseView->GetRenWin()->GetSize()[1]-y;
+               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;
+               }
+
 
                //Associates the view with the correspondent renderer and the  model.
                //(NOTE: Refresh is only made by the view)
-               model->setInicPoint(xx,yy,zz);
                view->setModel(model);
-               view->setRenderer(_baseView->GetRenderer());
+               view->setBaseView(_baseView);
                view->initVtkObjects();
                
+               //Associates the controller with the correspondent model and view
+               controller->setModelAndView(model,view);
+
                //Refresh renderwindow with new objects
                refreshRenderWindow();
+               
+               //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::createGOutputPort(BlackBoxOutputDescriptor *desc,GBlackBoxModel *blackBox)
+       {
+               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);
+               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);
+               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::createGInputPort(BlackBoxInputDescriptor *desc,GBlackBoxModel *blackBox)
+       {
+               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);
+               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)
+               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);
        }
 
@@ -192,6 +318,11 @@ namespace bbtk
        }
        //=========================================================================
 
+       bool wxVtkSceneManager::OnMouseMove()
+       {
+               //cout<<"RaC wxVtkSceneManager::OnMouseMove "<<endl;
+               return true;
+       }
        //=========================================================================
 }  // EO namespace bbtk