]> Creatis software - bbtkGEditor.git/blobdiff - lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxVtkSceneManager.cxx
*** empty log message ***
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsWxGUIEditorGraphic / wxVtkSceneManager.cxx
index 3c8825175f33f32c5ba19337e7bcf54b4a42cf02..5c8e2106dc569c61634e2ebbb6c1e4765d43ccc4 100644 (file)
@@ -36,6 +36,10 @@ Version:   $Revision$
 
 #include "wxVtkSceneManager.h"
 
+ #include <vtkPolygon.h>
+ #include <vtkUnstructuredGrid.h>
+
+
 namespace bbtk
 {
 
@@ -43,12 +47,12 @@ namespace bbtk
        //=========================================================================
        wxVtkSceneManager::wxVtkSceneManager(wxGEditorTabPanel *parent, wxVtk3DBaseView *baseView,int idManager)
        {
-               _parent = parent;
-               _numBoxes=0;
-               _idManager=idManager;
-               _baseView=baseView;
-               _startDragging=false;
-               _isComplexBox=false;
+               _parent                 = parent;
+               _numBoxes               = 0;
+               _idManager              = idManager;
+               _baseView               = baseView;
+               _startDragging  = false;
+               _isComplexBox   = false;
 
                if( _baseView!=NULL )
                {
@@ -61,8 +65,8 @@ namespace bbtk
                        registerController(this);
                        
                }
-               _idConnectionInCreation=-1;
-               _contLastId=0;
+               _idConnectionInCreation = -1;
+               _contLastId                             = 0;
 
        }
 
@@ -103,6 +107,85 @@ namespace bbtk
                _baseView->GetRenderer()->SetBackground(0.9,0.9,0.9);
                _baseView->GetRenderer()->GradientBackgroundOff();
                _baseView->Refresh();
+               
+               // Actos Port_Text 
+               _textActor = vtkTextActor3D::New();
+               _textActor->SetPosition(  -9999 , -9999 , 900 );
+               _textActor->SetInput( "<void>" );
+               _textActor->GetTextProperty()->SetFontSize(40);
+               _textActor->GetTextProperty()->BoldOn();
+               _textActor->GetTextProperty()->SetColor(PORTTEXT_NH_R,PORTTEXT_NH_G,PORTTEXT_NH_B);
+               
+               _baseView->GetRenderer()->AddActor( _textActor );
+               
+               
+               // Actor  Fill_Port_Text
+               
+               //------------
+               double                          xInic                           = 0;
+               double                          yInic                           = 0;
+               double                          zInic                           = 900;
+/*
+               vtkCellArray            *strip                          = vtkCellArray::New();
+               vtkPolyData                     *pdFill                         = vtkPolyData::New();
+               _fillObjectActor                                                = vtkActor::New();
+                                                       _fillPolyMapper         = vtkPolyDataMapper::New();
+*/
+printf ("EED wxVtkSceneManager::configureBaseView 1...\n");
+
+               vtkPolygon *aPolygon = vtkPolygon::New();
+               _fillObjectActor                                                = vtkActor::New();
+
+                                                       _pts                            = vtkPoints::New();     
+//ups4 EED Borrame
+               _pts->SetNumberOfPoints(7);
+               _pts->InsertPoint(0, xInic              , yInic         , zInic );
+               _pts->InsertPoint(1, xInic+50   , yInic         , zInic );
+               _pts->InsertPoint(2, xInic+50   , yInic+50      , zInic );
+               _pts->InsertPoint(3, xInic+25           , yInic+50      , zInic );
+               _pts->InsertPoint(4, xInic+20           , yInic+55      , zInic );
+               _pts->InsertPoint(5, xInic+15           , yInic+50      , zInic );
+               _pts->InsertPoint(6, xInic              , yInic+50      , zInic );
+
+/*
+               strip->InsertNextCell(8);
+               strip->InsertCellPoint(0);
+               strip->InsertCellPoint(1);
+               strip->InsertCellPoint(2);
+               strip->InsertCellPoint(0);
+               strip->InsertCellPoint(3);
+               pdFill->SetPoints( _pts );
+               pdFill->SetStrips( strip );
+               _fillPolyMapper->SetInput(pdFill);
+*/
+
+printf ("EED wxVtkSceneManager::configureBaseView 2...\n");
+
+               aPolygon->GetPointIds()->SetNumberOfIds(7);
+               aPolygon->GetPointIds()->SetId(0, 0);
+               aPolygon->GetPointIds()->SetId(1, 1);
+               aPolygon->GetPointIds()->SetId(2, 2);
+               aPolygon->GetPointIds()->SetId(3, 3);
+               aPolygon->GetPointIds()->SetId(4, 4);
+               aPolygon->GetPointIds()->SetId(5, 5);
+               aPolygon->GetPointIds()->SetId(6, 6);
+
+printf ("EED wxVtkSceneManager::configureBaseView 3...\n");
+
+               vtkUnstructuredGrid *aPolygonGrid = vtkUnstructuredGrid::New();
+               aPolygonGrid->Allocate(1, 1);
+               aPolygonGrid->InsertNextCell(aPolygon->GetCellType(), aPolygon->GetPointIds());
+               aPolygonGrid->SetPoints(_pts);
+printf ("EED wxVtkSceneManager::configureBaseView 4...\n");
+               _aPolygonMapper = vtkDataSetMapper::New();
+               _aPolygonMapper->SetInput(aPolygonGrid);
+               _fillObjectActor->SetMapper(_aPolygonMapper);
+printf ("EED wxVtkSceneManager::configureBaseView 5...\n");
+               _fillObjectActor->GetProperty()->SetColor(PORTFILL_NH_R,PORTFILL_NH_G,PORTFILL_NH_B);
+               _aPolygonMapper->Modified();
+
+               _baseView->GetRenderer()->AddActor( _fillObjectActor );         
+printf ("EED wxVtkSceneManager::configureBaseView fin...\n");
        }
 
        //=========================================================================
@@ -135,7 +218,6 @@ namespace bbtk
        }
 
        //=========================================================================
-//ups1 eed
        void wxVtkSceneManager::configGBlackBox(int idBox, double xIn, double yIn, double zIn, std::string name, bool boxExecutable,double xEn,double yEn,double zEn)
        {
                GObjectController *cont = _controllers[idBox];
@@ -394,7 +476,7 @@ namespace bbtk
 
                model->notifyObservers(_idManager);
 
-               int newId = addObjectController(controller);
+               addObjectController(controller);
 
                return (GPortController*)controller;
        }
@@ -606,6 +688,8 @@ namespace bbtk
        bool wxVtkSceneManager::OnMouseMove()
        {
                int X,Y;
+               bool okStatusMessage    = false;
+               bool okPortMessage              = false;
                wxVTKRenderWindowInteractor *wxVTKiren;
                wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
                wxVTKiren->GetEventPosition(X,Y);
@@ -644,25 +728,64 @@ namespace bbtk
                else if(_worldState == NOTHING_HAPPENS || _worldState == INIT_CREATION_CONTOUR)
                {
                        std::map<int, GObjectController*>::iterator it;
-
+                       double px, py, pz;
                        for(it = _controllers.begin(); it != _controllers.end(); ++it)
                        {
                                GObjectController *desc = it->second;
-                               int type = desc->getGObjectType();
-                               int state = desc->getView()->getState();
+                               int type                                = desc->getGObjectType();
+                               int state                               = desc->getView()->getState();
+                               desc->getModel()->getCenter(px,py,pz);
                                
                                if(state == HIGHLIGHTED){
-
+                                       okStatusMessage = true;
                                        updateStatusBar(desc->getStatusText());
                                        if(type==GBLACKBOX)
                                        {
                                                GBlackBoxModel *mod = (GBlackBoxModel*)desc->getModel();
                                                _parent->displayBlackBoxInfo(mod->getBBTKPackage(),mod->getBBTKType());
-                                       }
-                               }
-                       }
+                                       } // if GBLACKBOX
+                                       if(type==GPORT)
+                                       {
+                                               // PortText
+                                               okPortMessage   =       true;
+                                               py=py+5;
+                                               _textActor->SetInput( desc->getStatusText().c_str() );
+                                               _textActor->SetScale(0.1);
+                                               _textActor->SetPosition(  px-25 ,py , pz+2 );
+                                               
+                                               // FillPortText
+                                               px=px-35;
+                                               py=py-2;
+/*
+                                               _pts->SetPoint(0, px            , py            , 900+1 );
+                                               _pts->SetPoint(1, px+150        , py            , 900+1 );
+                                               _pts->SetPoint(2, px+150        , py+7          , 900+1 );
+                                               _pts->SetPoint(3, px-150+40     , py+7          , 900+1 );
+                                               _pts->SetPoint(4, px-150+40-5   , py+7+5        , 900+1 );
+                                               _pts->SetPoint(5, px-150+40-10  , py+7          , 900+1 );
+                                               _pts->SetPoint(6, px            , py+7          , 900+1 );
+*/                                             
+                                               _fillObjectActor->SetScale(1);
+                                               _fillObjectActor->SetPosition(px,py,1);
+                                               _aPolygonMapper->Modified();
+                                       } // if GPORT
+
+                               } // for controllers it
+                       } 
+               }
+//ups4 EED Borrame             
+               if (okStatusMessage==false) 
+               {
+                       updateStatusBar("");
                }
                
+               if (okPortMessage==false) 
+               {
+                       _textActor->SetScale(0.0001);
+                       _fillObjectActor->SetScale(0.0001);
+               }
+               
+
                return true;
        }
 
@@ -1028,6 +1151,7 @@ namespace bbtk
                std::string script = "";
                script+="# BBTK GEditor Script\n";
                script+="# ----------------------\n";
+               script+="\n";
                if(existsExec)
                {
                        script+="include std\n"; // EED
@@ -1039,6 +1163,7 @@ namespace bbtk
                                script+=packages[i];
                                script+="\n";
                        }
+                       script+="\n";
 
                        // script+="include std\n"; // JPR
 
@@ -1060,7 +1185,7 @@ namespace bbtk
                                        GPortModel* inputPort = inputs[j];
                                        if(inputPort->isValueSet())
                                        {
-                                               script+="set ";
+                                               script+="  set ";
                                                script+=model->getBBTKName();
                                                script+=".";
                                                script+=inputPort->getBBTKName();
@@ -1069,9 +1194,12 @@ namespace bbtk
                                                script+="\n";
                                        }
                                }
+                               script+="\n";
 
                        }
 
+                       script+="\n";
+
                        for(i = 0; i<(int)connections.size();i++)
                        {
                                script+="connect ";
@@ -1096,6 +1224,7 @@ namespace bbtk
                                script+="\n";
                        }
 
+                       script+="\n";
                        for(i = 0; i<(int)execBoxes.size();i++)
                        {
                                script+="exec ";
@@ -1510,11 +1639,16 @@ namespace bbtk
 
                                        getline(inputStream,line);//FIN_COMPLEX_PORT
 
-                                       int idInputPort = createGComplexBoxInputPort(inputPortName);
-                                       GObjectController *cont = _controllers[idInputPort];
-                                       GBoxModel *cbmod = (GBoxModel*)cont->getModel();
-                                       cbmod->setInicPoint(xIn,yIn,zIn);
-                                       cbmod->notifyObservers(_idManager);
+                                       configGComBoxInputOutputPort(true, inputPortName,xIn,yIn,zIn);
+
+//ups3 EED Borrame
+//                                     int idInputPort = createGComplexBoxInputPort(inputPortName);
+//                                     GObjectController *cont = _controllers[idInputPort];
+//                                     GBoxModel *cbmod = (GBoxModel*)cont->getModel();
+//                                     cbmod->setInicPoint(xIn,yIn,zIn);
+//                                     cbmod->notifyObservers(_idManager);
+
+                                       
                                } // for input complex box
 
 
@@ -1560,12 +1694,15 @@ namespace bbtk
 
                                        getline(inputStream,line);//FIN_COMPLEX_PORT
 
+                                       configGComBoxInputOutputPort(false, outputPortName,xIn,yIn,zIn);
+                                       
+//ups 3 EED Borrame
+//                                     int idOutputPort = createGComplexBoxOutputPort(outputPortName);
+//                                     GObjectController *cont = _controllers[idOutputPort];
+//                                     GBoxModel *cbmod = (GBoxModel*)cont->getModel();
+//                                     cbmod->setInicPoint(xIn,yIn,zIn);
+//                                     cbmod->notifyObservers(_idManager);
                                        
-                                       int idOutputPort = createGComplexBoxOutputPort(outputPortName);
-                                       GObjectController *cont = _controllers[idOutputPort];
-                                       GBoxModel *cbmod = (GBoxModel*)cont->getModel();
-                                       cbmod->setInicPoint(xIn,yIn,zIn);
-                                       cbmod->notifyObservers(_idManager);
                                } // for output complex box
 
                        } // complex box
@@ -1681,7 +1818,7 @@ namespace bbtk
                                } // while              
 
 //EED                          bbmod->notifyObservers(_idManager);
-                       } // boxes
+                       } // for boxes
 
                        /// CONNECTIONS
                        //----------
@@ -1712,7 +1849,7 @@ namespace bbtk
                                result = strtok( NULL, delims );
                                std::string nameEndPort(result);
 
-                               configGConnetion(_isComplexBox, nameStartBox, nameStartPort, nameEndBox, nameEndPort);
+                               configGConnetion(nameStartBox, nameStartPort, nameEndBox, nameEndPort);
 //ups 3 EED Borrame
 /*                             
                                std::vector<int> lstB   = getBlackBoxes();                              
@@ -1779,37 +1916,101 @@ namespace bbtk
         } // start
 
        }
+       //=========================================================================
 
+       
+       
+       //=========================================================================     
+       void wxVtkSceneManager::configGComBoxInputOutputPort(bool inputoutput, std::string portName, double xIn, double yIn,double zIn)
+       {
+               int idPort;
+               if (inputoutput==true)
+               {
+                       idPort = createGComplexBoxInputPort(portName);
+               } else  {
+                       idPort = createGComplexBoxOutputPort(portName);
+               }
+               GObjectController *cont = _controllers[idPort];
+               GBoxModel *cbmod                = (GBoxModel*)cont->getModel();
+               cbmod->setInicPoint(xIn,yIn,zIn);
+               cbmod->notifyObservers(_idManager);                             
+       }
        //=========================================================================
        
-       GBlackBoxModel* wxVtkSceneManager::findGBox(std::string boxname)
+       
+       //=========================================================================
+       GBoxModel* wxVtkSceneManager::findGBox(std::string boxname)
        {       
-               GBlackBoxModel *boxModel        = NULL;
-               GBlackBoxModel *bbMod;
-               std::vector<int> lstB           = getBlackBoxes();                              
-               int idB;
                int j;
+               int idB;
+               GBoxModel *bMod;
+               GBoxModel *boxModel                     = NULL;
+               std::vector<int> lstB           = getBlackBoxes();                              
                for(j = 0;j<(int)lstB.size();j++)
                {
-                       idB = lstB[j];
-                       bbMod = (GBlackBoxModel*)_controllers[idB]->getModel();
+                       idB             = lstB[j];
+                       bMod    = (GBoxModel*)_controllers[idB]->getModel();
                        if(_controllers[idB]->getModel()->getBBTKName()==boxname)
-                       {                                               
-                               boxModel = bbMod;
+                       {
+                               boxModel = bMod;
                        }
                } // for
+               
+               if((_isComplexBox) && (boxModel==NULL))
+               {
+                       std::vector<int> lstInputs = getComplexInputPorts();
+                       for(j = 0;j<(int)lstInputs.size();j++)
+                       {
+                               idB             = lstInputs[j];
+                               bMod    = (GBoxModel*)_controllers[idB]->getModel();
+                               if(_controllers[idB]->getModel()->getBBTKName()==boxname)
+                               {
+                                       boxModel = bMod;
+                               }  
+                       } // for
+                       
+                       std::vector<int> lstOutputs = getComplexOutputPorts();
+                       for(j = 0;j<(int)lstOutputs.size();j++)
+                       {
+                               int idB = lstOutputs[j];
+                               bMod = (GBoxModel*)_controllers[idB]->getModel();
+                               if(_controllers[idB]->getModel()->getBBTKName()==boxname)
+                               {                                               
+                                       boxModel = bMod;
+                               } 
+                       } // for
+                       
+               } // complex box
+
                return boxModel;
        }
        
        //=========================================================================
 
 
-       void wxVtkSceneManager::configGConnetion(bool _isComplexBox, 
-                                                                                        std::string nameStartBox, std::string  nameStartPort, std::string  
+       void wxVtkSceneManager::configGConnetion(std::string nameStartBox, std::string  nameStartPort, std::string  
                                                                                         nameEndBox, std::string  nameEndPort)
        {
-               GPortModel *startP              = findGBox(nameStartBox)->getOutputPort(nameStartPort);
-               GPortModel *endP                = findGBox(nameEndBox)->getInputPort(nameEndPort);
+               printf("EED wxVtkSceneManager::configGConnetion 1 %s %s    %s %s\n", nameStartBox.c_str(), nameStartPort.c_str(), nameEndBox.c_str(), nameEndPort.c_str() );
+               
+               GBoxModel *boxModel;
+               GPortModel *startP      = NULL;
+               GPortModel *endP        = NULL;
+               
+               boxModel= findGBox(nameStartBox);
+               if (boxModel!=NULL)
+               {
+                       startP          = boxModel->getOutputPort(nameStartPort);
+               }
+
+               boxModel= findGBox(nameEndBox);
+               if (boxModel!=NULL)
+               {
+                       endP            = boxModel->getInputPort(nameEndPort);
+               }
+
+               
+               printf("EED wxVtkSceneManager::configGConnetion 2 %p %p \n", startP, endP );
 
 /*ups5 EED Borrame
                std::vector<int> lstB   = getBlackBoxes();                              
@@ -1827,8 +2028,7 @@ namespace bbtk
                                endP = bbMod->getInputPort(nameEndPort);
                        }
                } // for
-*/             
-               int j;
                if(_isComplexBox)
                {
                        if(startP==NULL)
@@ -1836,8 +2036,8 @@ namespace bbtk
                                std::vector<int> lstInputs = getComplexInputPorts();
                                for(j = 0;j<(int)lstInputs.size();j++)
                                {
-                                       int idB = lstInputs[j];
-                                       GBoxModel *cbMod = (GBoxModel*)_controllers[idB]->getModel();
+                                       int idB                         = lstInputs[j];
+                                       GBoxModel *cbMod        = (GBoxModel*)_controllers[idB]->getModel();
                                        if(_controllers[idB]->getModel()->getBBTKName()==nameStartBox)
                                        {                                               
                                                startP = cbMod->getOutputPort(nameStartPort);
@@ -1859,13 +2059,14 @@ namespace bbtk
                                } // for
                        } // if endP
                } // complex box
+ */            
                
-               int idCon = createGConnector(startP);
-               _worldState = NOTHING_HAPPENS;
+               int idCon                                       = createGConnector(startP);
+               _worldState                                     = NOTHING_HAPPENS;
                GConnectorController *tempp = (GConnectorController*)_controllers[idCon]; 
                
-               GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
-               vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
+               GConnectorModel *conMod         = (GConnectorModel*)tempp->getModel();
+               vtkGConnectorView *conView      = (vtkGConnectorView*)tempp->getView();
                tempp->endContourCreation();
                conMod->setEndPort(endP);                                       
                conView->updateStartEndPoints();                
@@ -2025,8 +2226,7 @@ namespace bbtk
                                {                                       
                                        int ID = cont->getId();
                                        mapSelected[ID]=cont;
-                               }
-                               
+                               }                               
                        }
                }
                return mapSelected;
@@ -2074,7 +2274,7 @@ namespace bbtk
                        
                }
                
-               for(int i = 0 ;i<connections.size();i++)
+               for(int i = 0 ;i<(int)connections.size();i++)
                {
                        int objId = connections[i];
                        GObjectController *cont = objectsMap[objId];