]> Creatis software - bbtkGEditor.git/blobdiff - lib/EditorGraphicBBS/bbsKernelEditorGraphic/wxVtkSceneManager.cxx
Stable version ... The connection is correctly painted :)
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsKernelEditorGraphic / wxVtkSceneManager.cxx
index 3c79b612fdb903cd3395cce040e00b83d389ba1d..daa6327c157cceea4e7cd481750fa60fa7654e82 100644 (file)
@@ -41,79 +41,39 @@ namespace bbtk
 
 
        //=========================================================================
-       wxVtkSceneManager::wxVtkSceneManager(wxDropTarget *parent, wxVtk3DBaseView *baseView,int id)
+       wxVtkSceneManager::wxVtkSceneManager(wxDropTarget *parent, wxVtk3DBaseView *baseView,int idManager)
        {
-               _id=id;
+               _numBoxes=0;
+               _idManager=idManager;
                _baseView=baseView;
+               _idLastController=0;
+
                if( _baseView!=NULL )
                {
-                       
                        _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(parent);
                        registerController(this);
                        configureBaseView();
-
-                       ///// ******* TO ERASE *******
-                       //JUST TO TEST
-                       //
-                       
-                       
-                       
-                       vtkConeSource *cone = vtkConeSource::New();
-       
-                  cone->SetResolution(10);
-                       
-                  vtkPolyDataMapper *map = vtkPolyDataMapper::New();
-                  map->SetInput(cone->GetOutput());
-                       
-                  vtkActor *act = vtkActor::New();
-                       
-                  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 );
-       
-                       vtkCellArray *lines = vtkCellArray::New();
-                       lines->InsertNextCell(5);
-                       lines->InsertCellPoint(0);
-                       lines->InsertCellPoint(1);
-                       lines->InsertCellPoint(2);
-                       lines->InsertCellPoint(3);
-                       lines->InsertCellPoint(0);
-
-                       vtkPolyData *_pd = vtkPolyData::New();
-                       _pd->SetPoints( _pts );
-                       _pd->SetLines( lines );
-
-                       vtkActor *_pointVtkActor        =       vtkActor::New();
-                       vtkPolyDataMapper* _bboxMapper          =       vtkPolyDataMapper::New();
-
-                       _bboxMapper->SetInput(_pd);
-                       _pointVtkActor->SetMapper(_bboxMapper);
-
-                       getRenderer()->AddActor(_pointVtkActor);
-
-                       
-                       
-                       // ******* TO ERASE *******
-                       /////////////////////
+                       _worldState=NOTHING_HAPPENS;
                        
                }
+
+               
        }
 
+
        //=========================================================================
+
        void wxVtkSceneManager::disconnectDrop()
        {
                _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
        }
+
        //=========================================================================
+
        wxVtkSceneManager::~wxVtkSceneManager()
        {
        }
+
        //=========================================================================
 
        void wxVtkSceneManager::configureBaseView()
@@ -128,10 +88,12 @@ namespace bbtk
                iren->SetInteractorStyle(interactorstylebaseview);
                interactorstylebaseview->SetwxVtkBaseView(_baseView);
                
+               _baseView->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
+               _baseView->GetRenderer()->ResetCamera(-100,100,-100,100,900,1000);
+               
                _baseView->GetRenderer()->SetBackground(0.9,0.9,0.9);
                _baseView->GetRenderer()->GradientBackgroundOff();
                _baseView->Refresh();
-
        }
 
        //=========================================================================
@@ -159,11 +121,27 @@ namespace bbtk
                double yy =  windowHeight-y;
                
                //z value is not important yet, because it is only used a parallel projection
-               double zz = 0;
+               double zz = 900;
 
                _baseView->TransCoordScreenToWorld(xx,yy,zz);
                model->setInicPoint(xx,yy,zz);
                
+               _numBoxes++;
+               std::stringstream stream;
+               
+               if(_numBoxes<10)
+               {
+                       stream << "Box0" << _numBoxes;
+               }
+               else
+               {
+                       stream << "Box" << _numBoxes;
+               }
+               std::string arraystring = stream.str();
+
+               model->setBBTKName(arraystring);
+               model->setBBTKType(boxName);
+                               
                model->addObserver(view);
                model->addObserver(this);
 
@@ -175,7 +153,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++;
                }
 
@@ -187,7 +165,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++;
                }
 
@@ -202,20 +180,35 @@ namespace bbtk
                controller->setModelAndView(model,view);
 
                //Resgiter change to the observers of the actual model
-               model->setChanged();
-               model->notifyObservers();
+               model->notifyObservers(_idManager);
                
                //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 
+               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)
+       {
+               createGPort(portType,posinBox,blackBox);
+       }
+
+       //=========================================================================
+
+       void wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBlackBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
+       {
+               createGPort(portType,posinBox,blackBox);
+       }
+
+       //=========================================================================
+
+       void wxVtkSceneManager::createGPort(int portType, int posInBox,GBlackBoxModel *blackBox)
        {
                int type = GPORT;
 
@@ -224,7 +217,7 @@ namespace bbtk
                vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
                GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
 
-               model->registerInBox(blackBox,GOUTPUTPORT, pos);
+               model->registerInBox(blackBox,portType, posInBox);
                blackBox->addOutputPort(model);
                
                model->addObserver(view);
@@ -239,70 +232,79 @@ namespace bbtk
                //Associates the controller with the correspondent model and view
                controller->setModelAndView(model,view);
 
+               model->notifyObservers(_idManager);
+
                //Register the controller of the new object
                registerController((InteractorStyleMaracas*) controller);
+               
+               int newId = _controllers.size();
+               controller->setId(newId);
+               _controllers[newId] = controller;
        }
 
        //=========================================================================
 
-       void wxVtkSceneManager::createGInputPort(BlackBoxInputDescriptor *desc,GBlackBoxModel *blackBox, int pos)
+       void wxVtkSceneManager::createGConnector(GPortModel* startPort)
        {
-               int type = GPORT;
+               int type = GCONNECTOR;
 
-               //Create the MVC Objects
-               GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
-               vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
-               GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
+               manualConnectorContourController* manContourControl     = new manualConnectorContourController();
+               manualConnectorContourView* manContourView      = new manualConnectorContourView();
+               manualContourModel* manContourModel     = new manualContourModel();
 
-               model->registerInBox(blackBox,GINPUTPORT,pos);
-               blackBox->addInputPort(model);
+               GConnectorController* connectorcontroller = new GConnectorController();                         
+               GConnectorModel* connectorModel = new GConnectorModel();
+               GConnectorView* connectorView = new GConnectorView();
+               connectorModel->setGObjectType(type);
 
-               model->addObserver(view);
-               model->addObserver(this);
+               manContourModel->SetCloseContour(false);
+               connectorModel->setStartPort(startPort);
 
-               //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();
+               manContourView->SetModel( manContourModel );
+               manContourView->SetWxVtkBaseView( _baseView );
+               manContourView->SetRange( 0.5 );
+               manContourView->SetZ( 900 );
+
+               manContourView->SetColorNormalContour(0, 0, 1);
+               manContourView->SetColorEditContour(0.5, 0.5, 0.5);
+               manContourView->SetColorSelectContour(1, 0.8, 0);
+               manContourView->SetWidthLine(1);
+
+               manContourControl->SetModelView( manContourModel , manContourView );
                
-               //Associates the controller with the correspondent model and view
-               controller->setModelAndView(model,view);
+               manContourControl->CreateNewManualContour();
 
-               //Register the controller of the new object
-               registerController((InteractorStyleMaracas*) controller);
-       }
+               manContourView->RefreshContour();
 
-       //=========================================================================
 
-       void wxVtkSceneManager::createGConnector(GPortModel* startPort)
-       {
-               manualContourControler* manContourControl       = new manualContourControler();
-               manualViewContour* manViewerContour     = new manualViewContour();
-               manualContourModel* manContourModel     = new manualContourModel();
+               double x,y,z;
+               connectorModel->getInicPoint(x,y,z);
 
+               manContourControl->SetState(1);
+               manContourModel->SetCloseContour(false);
                
-               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();
-               for ( i=0; i<sizeLstPoints; i++ )
-               {
-                       manViewerContour->AddPoint();
-               }
+               manContourModel->AddPoint(x,y,z);
+               manContourView->AddPoint();
 
-               manContourControl->CreateNewManualContour();
-               manViewerContour->RefreshContour();                     
-               registerController((InteractorStyleMaracas*) manContourControl);
+               manContourModel->AddPoint(x,y,z);
+               manContourView->AddPoint();
+
+               int bak= manContourControl->GetNumberOfPointsManualContour() - 1;
+               manContourControl->_bakIdPoint=bak;
+               manContourView->Refresh();
+
+               manContourControl->SetMoving( false );
+
+               registerController((InteractorStyleMaracas*) connectorcontroller);
+
+               connectorcontroller->setManualContourController(manContourControl);             
+               connectorModel->setManualContourModel(manContourModel);
+               connectorView->setManualContourView(manContourView);
+               connectorcontroller->setModelAndView(connectorModel,connectorView);
+
+               int newId = _controllers.size();
+               connectorcontroller->setId(newId);
+               _controllers[newId] = connectorcontroller;
 
        }
 
@@ -336,27 +338,67 @@ namespace bbtk
 
        //=========================================================================
        
-       void wxVtkSceneManager::update(int command)
+       void wxVtkSceneManager::update(int idController,int command)
        {
                
-               if(command==INIT_CREATION_CONTOUR)
-               {
-                       std::cout<<"wxVtkSceneManager::update size:"<<_objects.size()<<std::endl;
-                       for(int i = 0; i<_objects.size();i++)
+               if(command == INIT_CREATION_CONTOUR)
+               {       
+                       GObjectController* cont = _controllers[idController];
+                       GPortModel* startOutputPort = (GPortModel*)cont->getModel();
+                       createGConnector(startOutputPort);
+
+                       // The last one is the controller of the connector
+                       for(int i=0;i<_controllers.size()-1;i++)
                        {
-                               std::cout<<"wxVtkSceneManager::update type:"<<_objects[i]->getGObjectType()<<std::endl;
-                               if(_objects[i]->getGObjectType() == GBLACKBOX)
+                               GObjectController* cont = _controllers[i];
+                               if(cont->getGObjectType() == GPORT )
                                {
-                                       
-                                       GPortModel* startInputPort=((GBlackBoxModel*)_objects[i])->getStartInputPort();
-                                       std::cout<<"wxVtkSceneManager::update "<<startInputPort<<std::endl;
-                                       createGConnector(startInputPort);
-
+                                       GPortModel* port = (GPortModel*)cont->getModel();
+                                       if(port->getPortType()==GINPUTPORT)
+                                       {
+                                               cont->SetActive(true);
+                                       }
+                                       else
+                                       {
+                                               cont->getView()->setState(NOTHING_HAPPENS);
+                                               cont->SetActive(false);
+                                       }
                                }
                                else
                                {
-                                       // The others must not react to events
+                                       cont->getView()->setState(NOTHING_HAPPENS);
+                                       cont->SetActive(false);
+                               }                               
+                       }
+                       _worldState = CREATING_CONTOUR;
+               }
+               else if(command == FIN_CREATION_CONTOUR && _worldState == CREATING_CONTOUR)
+               {
+                       
+                       _worldState = NOTHING_HAPPENS;
+                       int id = _controllers.size()-1;
+                       GObjectController* cont = _controllers[id];                     
+                       GConnectorModel* modelContour = (GConnectorModel*)cont->getModel();
+
+                       GObjectController* finPort = _controllers[idController];
+                       if(finPort->getGObjectType() == GPORT)
+                       {
+                               GPortModel* modelPort = (GPortModel*)finPort->getModel();
+                               modelContour->setEndPort(modelPort);
+                       }                       
+
+                       manualConnectorContourController* manCont = ((GConnectorController*)cont)->getManualContourController();                        
+                       manualConnectorContourView* connView = (manualConnectorContourView*)manCont->GetManualViewBaseContour();
+                       connView->Refresh();
+
+                       for(int i=0;i<_controllers.size();i++)
+                       {
+                               GObjectController* cont = _controllers[i];
+                               if(cont->getView()!=NULL)
+                               {
+                                       cont->getView()->setState(NOTHING_HAPPENS);
                                }
+                               cont->SetActive(true);                                                          
                        }
                }
        }