]> Creatis software - bbtkGEditor.git/blobdiff - lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxVtkSceneManager.cxx
Compilation problems corrections:
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsWxGUIEditorGraphic / wxVtkSceneManager.cxx
index c482711cc67ee0e3547f57ded274ce4408b2443c..ab0ef4e76d5a65f6e69cae0748be3c4bcef30c99 100644 (file)
@@ -685,6 +685,7 @@ void wxVtkSceneManager::update(int idController, int command) {
                        if (finPort->getGObjectType() == GPORT) {
                                GPortModel* modelPort = (GPortModel*) finPort->getModel();
                                modelContour->setEndPort(modelPort);
+                               _parent->saveTempDiagram();
                        }
 
                        manualConnectorContourController
@@ -819,6 +820,7 @@ bool wxVtkSceneManager::OnLeftButtonDown() {
                        CancelConnection();
                        UnSelectBlackBoxes();
                } // isOverPort
+       
 
        } else { //_worldState
 
@@ -845,7 +847,7 @@ bool wxVtkSceneManager::OnLeftButtonDown() {
                        cont->getView()->setState(DRAG);
                        cont->getModel()->notifyObservers(_idManager);
                } // for
-
+               
        } // if _selectedObjects.size
 
 
@@ -900,6 +902,26 @@ bool wxVtkSceneManager::OnRightButtonUp() {
        return true;
 }
 
+ ///JLGR 21-05-2012
+
+bool wxVtkSceneManager::OnMiddleButtonDown() {
+
+
+        this->_vtkInteractorStyleBaseView->StartPan();
+
+        return true;
+    }
+
+bool wxVtkSceneManager::OnMiddleButtonUp() {
+
+
+        this->_vtkInteractorStyleBaseView->EndPan();
+
+
+        return true;
+    }
+
+
 //=========================================================================
 
 GObjectController *wxVtkSceneManager::GetGBlackBoxControlerPointedByMouse() {
@@ -990,7 +1012,8 @@ bool wxVtkSceneManager::OnLeftDClick() {
 
 bool wxVtkSceneManager::OnChar() {
        char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
-
+        int ctrlkey = _vtkInteractorStyleBaseView->GetInteractor()->GetControlKey();
+        
        // KeyCode 127 : Delete Key
        // KeyCode 8 : Backspace Key
        if (keyCode == 8 || keyCode == 127) {
@@ -1006,6 +1029,19 @@ bool wxVtkSceneManager::OnChar() {
                        _selectedObjects.clear();
                }
        }
+        
+        /// Duplicate 
+             if(ctrlkey==5){                
+                if(_selectedObjects.size()){
+                    std::cout<<"objects to copy :";
+                    for(int i=0;i<_selectedObjects.size();i++){
+                       std::cout<<_selectedObjects.at(i)<<" ";
+                    }
+                    DuplicateObjects(getSelectedObjects());   
+                }else{
+                    std::cout<<"No objects to copy\n";
+                }
+            }  
 
        return true;
 }
@@ -1104,6 +1140,7 @@ void wxVtkSceneManager::deleteObject(int id) {
                        _controllers.erase(it);
                }//if
        }// for
+       _parent->saveTempDiagram();
 }
 
 //=========================================================================
@@ -1141,26 +1178,27 @@ std::string wxVtkSceneManager::LineNumber(bool withLineNumber, int &value) {
 //DFCH
 bool wxVtkSceneManager::MakeBoxExecutable() {
        std::map<int, GObjectController*> selected = getSelectedObjects();
-
-       std::map<int, GObjectController*>::iterator it = selected.end();
-       it--;
-       GObjectController* lastSelected = it->second;
-       //GObjectController* lastSelected = selected[selected.size()-1];
-       if( lastSelected )
-       {
-               vtkGObjectView* view = (vtkGObjectView*) lastSelected->getView();
-               GBlackBoxModel *bbmodel = (GBlackBoxModel*) lastSelected->getModel();
-               view->setState(HIGHLIGHTED);
-               if (bbmodel->isExecutable()) {
-                       bbmodel->setExecutable(false);
-               } else {
-                       bbmodel->setExecutable(true);
+       if( selected.empty() )
+               return false;
+       bool ret = false;
+       std::map<int, GObjectController*>::iterator it;
+       for (it = selected.begin(); it != selected.end(); ++it) {
+               GObjectController* lastSelected = it->second;
+               if (lastSelected) {
+                       vtkGObjectView* view = (vtkGObjectView*) lastSelected->getView();
+                       GBlackBoxModel *bbmodel =
+                                       (GBlackBoxModel*) lastSelected->getModel();
+                       view->setState(HIGHLIGHTED);
+                       if (bbmodel->isExecutable()) {
+                               bbmodel->setExecutable(false);
+                       } else {
+                               bbmodel->setExecutable(true);
+                       }
+                       bbmodel->notifyObservers(lastSelected->getId());
+                       ret = true;
                }
-               bbmodel->notifyObservers(lastSelected->getId());
-               return true;
        }
-       else
-               return( false );
+       return ret;
 }
 //DFCH
 
@@ -1640,12 +1678,13 @@ void wxVtkSceneManager::saveDiagram(std::string &content) {
 
 //=========================================================================
 
-void wxVtkSceneManager::loadDiagram(ifstream &inputStream) {
+void wxVtkSceneManager::loadDiagram(stringstream &inputStream) {
 
        std::string version = "<void>";
        std::string line = "";
        char delims[] = ":";
        char *result = NULL;
+
        getline(inputStream, line);
 
        bool start = false;
@@ -2182,6 +2221,104 @@ int wxVtkSceneManager::addObjectController(GObjectController* objController) {
        return newId;
 }
 
+//=========================================================================
+
+void wxVtkSceneManager::DuplicateObjects(std::map<int, GObjectController*> objectsMap) {
+
+        std::map<int, int> oldIdNewIdBoxes;
+        std::vector<int> connections;
+
+        std::vector<int> newBoxesID;
+
+        std::map<int, GObjectController*>::iterator it;
+        for (it = objectsMap.begin(); it != objectsMap.end(); ++it) {
+            GObjectController *cont = it->second;
+            int type = cont->getGObjectType();
+
+            if (type == GBLACKBOX) {
+                // Copy black box
+                double xInic, yInic, zInic;
+                GBlackBoxModel* copyBox = (GBlackBoxModel*) cont->getModel();
+                copyBox->getInicPoint(xInic, yInic, zInic);
+                int idBox = createGBlackBox(0, 0, copyBox->getBBTKPackage(),
+                        copyBox->getBBTKType());
+
+                int idcB = copyBox->getObjectId();
+                oldIdNewIdBoxes[idcB] = idBox;
+                cont = _controllers[idBox];
+                GBlackBoxModel* newbox = (GBlackBoxModel*) cont->getModel();
+                newbox->setInicPoint(xInic, yInic, zInic);
+                int num = newbox->getNumInputPorts();
+                for (int j = 0; j < num; j++) {
+                    newbox->setValueToInputPort(j, copyBox->getValueInputPort(j));
+                }
+                newbox->move(xInic + 20, yInic + 20, zInic);
+                newbox->notifyObservers(_idManager);
+                newBoxesID.push_back(newbox->getObjectId());
+
+            } else if (type == GCONNECTOR) {
+                int idCon = cont->getId();
+                connections.push_back(idCon);
+            }
+
+        }
+
+        for (int i = 0; i < (int) connections.size(); i++) {
+            int objId = connections[i];
+            GObjectController *cont = objectsMap[objId];
+            GConnectorModel* connectModel = (GConnectorModel*) cont->getModel();
+
+            GPortModel* startPort = connectModel->getStartPort();
+            int startPortIndex = startPort->getPosInBox();
+            GPortModel* endPort = connectModel->getEndPort();
+            int endPortIndex = endPort->getPosInBox();
+
+            GBlackBoxModel* startPortParentBox =
+                    (GBlackBoxModel*) startPort->getParentBox();
+            GBlackBoxModel* endPortParentBox =
+                    (GBlackBoxModel*) endPort->getParentBox();
+
+            int idNewStartBox = oldIdNewIdBoxes[startPortParentBox->getObjectId()];
+            int idNewEndBox = oldIdNewIdBoxes[endPortParentBox->getObjectId()];
+
+            GBlackBoxModel* newStartBox =
+                    (GBlackBoxModel*) _controllers[idNewStartBox]->getModel();
+            GBlackBoxModel* newEndBox =
+                    (GBlackBoxModel*) _controllers[idNewEndBox]->getModel();
+
+            GPortModel* newStartPort = newStartBox->getOutputPort(startPortIndex);
+            GPortModel* newEndPort = newEndBox->getInputPort(endPortIndex);
+
+            // Creates connection
+            int idCon = createGConnector(newStartPort);
+            GConnectorController *tempp =
+                    (GConnectorController*) _controllers[idCon];
+            GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
+            vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
+            tempp->endContourCreation();
+            conMod->setEndPort(newEndPort);
+            conView->updateStartEndPoints();
+        }
+
+        /// the new selected boxes are the duplicate ones
+
+        UnSelectBlackBoxes();
+        for (int i = 0; i < newBoxesID.size(); i++) {
+            _selectedObjects.push_back(newBoxesID.at(i));
+        }
+
+        for (int i = 0; i < (int) _selectedObjects.size(); i++) {
+            int id = _selectedObjects[i];
+            GObjectController* cont = _controllers[id];
+
+            cont->getView()->setState(SELECTED);
+            cont->getModel()->notifyObservers(_idManager);
+
+        }
+        refreshScene();
+    }
+
+
 //=========================================================================
 
 int wxVtkSceneManager::getNumSelectedObjects() {