]> 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 23ea678c0a0d21ca6bfe58265e8a10e5256724d4..daa6327c157cceea4e7cd481750fa60fa7654e82 100644 (file)
@@ -41,96 +41,23 @@ 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, -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);
-                       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);
-
-                       
-                       
-                                       
-                  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 );
-
-                       vtkActor *_pointVtkActor2       =       vtkActor::New();
-                       vtkPolyDataMapper* _bboxMapper2         =       vtkPolyDataMapper::New();
-
-                       _bboxMapper2->SetInput(_pd2);
-                       _pointVtkActor2->SetMapper(_bboxMapper2);
-
-                       getRenderer()->AddActor(_pointVtkActor2);
-
-                       */
-                       // ******* TO ERASE *******
-                       /////////////////////
+                       _worldState=NOTHING_HAPPENS;
                        
                }
+
+               
        }
 
 
@@ -199,17 +126,16 @@ namespace bbtk
                _baseView->TransCoordScreenToWorld(xx,yy,zz);
                model->setInicPoint(xx,yy,zz);
                
-               int cantObjects = _objects.size();
-               cantObjects++;
+               _numBoxes++;
                std::stringstream stream;
                
-               if(cantObjects<10)
+               if(_numBoxes<10)
                {
-                       stream << "Box0" << cantObjects;
+                       stream << "Box0" << _numBoxes;
                }
                else
                {
-                       stream << "Box" << cantObjects;
+                       stream << "Box" << _numBoxes;
                }
                std::string arraystring = stream.str();
 
@@ -254,15 +180,12 @@ 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 
-               _objects.push_back(controller);
-
                int newId = _controllers.size();
                controller->setId(newId);
                _controllers[newId] = controller;
@@ -309,7 +232,7 @@ namespace bbtk
                //Associates the controller with the correspondent model and view
                controller->setModelAndView(model,view);
 
-               model->notifyObservers();
+               model->notifyObservers(_idManager);
 
                //Register the controller of the new object
                registerController((InteractorStyleMaracas*) controller);
@@ -323,35 +246,65 @@ namespace bbtk
 
        void wxVtkSceneManager::createGConnector(GPortModel* startPort)
        {
-               manualContourControler* manContourControl       = new manualContourControler();
-               GConnectorView* manViewerContour        = new GConnectorView();
+               int type = GCONNECTOR;
+
+               manualConnectorContourController* manContourControl     = new manualConnectorContourController();
+               manualConnectorContourView* manContourView      = new manualConnectorContourView();
                manualContourModel* manContourModel     = new manualContourModel();
-               manContourModel->SetCloseContour(false);
 
-               manViewerContour->SetModel( manContourModel );
-               manViewerContour->SetWxVtkBaseView( _baseView );
-               manViewerContour->SetRange( 0.5 );
-               manViewerContour->SetZ( 900 );
+               GConnectorController* connectorcontroller = new GConnectorController();                         
+               GConnectorModel* connectorModel = new GConnectorModel();
+               GConnectorView* connectorView = new GConnectorView();
+               connectorModel->setGObjectType(type);
 
-               manViewerContour->SetColorNormalContour(0, 0, 1);
-               manViewerContour->SetColorEditContour(0.5, 0.5, 0.5);
-               manViewerContour->SetColorSelectContour(1, 0.8, 0);
-               manViewerContour->SetWidthLine(1);
+               manContourModel->SetCloseContour(false);
+               connectorModel->setStartPort(startPort);
 
-               manContourControl->SetModelView( manContourModel , manViewerContour );
-               manContourControl->Configure();
-               int i,sizeLstPoints = manContourModel->GetSizeLstPoints();
+               manContourView->SetModel( manContourModel );
+               manContourView->SetWxVtkBaseView( _baseView );
+               manContourView->SetRange( 0.5 );
+               manContourView->SetZ( 900 );
 
-               for ( i=0; i<sizeLstPoints; i++ )
-               {
-                       manViewerContour->AddPoint();
-               }
+               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 );
+               
                manContourControl->CreateNewManualContour();
 
-               manViewerContour->RefreshContour();
+               manContourView->RefreshContour();
+
+
+               double x,y,z;
+               connectorModel->getInicPoint(x,y,z);
+
+               manContourControl->SetState(1);
+               manContourModel->SetCloseContour(false);
+               
+               manContourModel->AddPoint(x,y,z);
+               manContourView->AddPoint();
+
+               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);
 
-               registerController((InteractorStyleMaracas*) manContourControl);
+               int newId = _controllers.size();
+               connectorcontroller->setId(newId);
+               _controllers[newId] = connectorcontroller;
 
        }
 
@@ -385,25 +338,68 @@ namespace bbtk
 
        //=========================================================================
        
-       void wxVtkSceneManager::update(int idObservable,int command)
+       void wxVtkSceneManager::update(int idController,int command)
        {
                
-               if(command==INIT_CREATION_CONTOUR)
+               if(command == INIT_CREATION_CONTOUR)
                {       
-                       GObjectController* cont = _controllers[idObservable];
-                       if(cont->getGObjectType() == GPORT)
-                       {
-                               GPortController* controller = (GPortController*)cont;
-                               vtkGPortView* view = (vtkGPortView*)controller->getView();
+                       GObjectController* cont = _controllers[idController];
+                       GPortModel* startOutputPort = (GPortModel*)cont->getModel();
+                       createGConnector(startOutputPort);
 
-                               if(view->getState() == CREATING_CONTOUR)
+                       // The last one is the controller of the connector
+                       for(int i=0;i<_controllers.size()-1;i++)
+                       {
+                               GObjectController* cont = _controllers[i];
+                               if(cont->getGObjectType() == GPORT )
                                {
-                                       //pre: The port in this state is an output port                                 
-                                       GPortModel* startOutputPort = (GPortModel*)controller->getModel();
-                                       createGConnector(startOutputPort);
+                                       GPortModel* port = (GPortModel*)cont->getModel();
+                                       if(port->getPortType()==GINPUTPORT)
+                                       {
+                                               cont->SetActive(true);
+                                       }
+                                       else
+                                       {
+                                               cont->getView()->setState(NOTHING_HAPPENS);
+                                               cont->SetActive(false);
+                                       }
                                }
+                               else
+                               {
+                                       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);                                                          
+                       }
                }
        }