+ int wxVtkSceneManager::addObjectController(GObjectController* objController)
+ {
+ //Register the controller of the new object
+ registerController((InteractorStyleMaracas*) objController);
+
+ //Add the object to the objects list
+ int newId = _controllers.size();
+ objController->setId(newId);
+ _controllers[newId] = objController;
+ return newId;
+ }
+
+ //=========================================================================
+
+ int wxVtkSceneManager::getNumSelectedObjects()
+ {
+ return _selectedObjects.size();
+ }
+
+ //=========================================================================
+
+ std::map<int,GObjectController*> wxVtkSceneManager::getSelectedObjects()
+ {
+ std::map<int,GObjectController*> mapSelected;
+
+ std::map<int, GObjectController*>::iterator it;
+ for(it = _controllers.begin(); it != _controllers.end(); ++it)
+ {
+ GObjectController *cont = it->second;
+ if(cont->getGObjectType()==GBLACKBOX && cont->getView()->getState()==SELECTED)
+ {
+ mapSelected[cont->getId()]=cont;
+ }
+ }
+
+ std::map<int, GObjectController*>::iterator it2;
+ for(it2 = _controllers.begin(); it2 != _controllers.end(); ++it2)
+ {
+ GObjectController *cont = it2->second;
+ if(cont->getGObjectType()==GCONNECTOR)
+ {
+ GConnectorModel* cmod = (GConnectorModel*)cont->getModel();
+ GBoxModel* endPortParentBox = cmod->getEndPort()->getParentBox();
+ GBoxModel* startPortParentBox = cmod->getStartPort()->getParentBox();
+
+ std::map<int, GObjectController*>::iterator iterOBJ1 = mapSelected.find(startPortParentBox->getObjectId());
+ std::map<int, GObjectController*>::iterator iterOBJ2 = mapSelected.find(endPortParentBox->getObjectId());
+
+ if(iterOBJ1 != mapSelected.end() && iterOBJ2 != mapSelected.end())
+ {
+ int ID = cont->getId();
+ mapSelected[ID]=cont;
+ }
+
+ }
+ }
+ return mapSelected;
+ }
+
+ //=========================================================================
+
+ void wxVtkSceneManager::addObjects(std::map<int,GObjectController*> objectsMap)
+ {
+
+ std::map<int,int> oldIdNewIdBoxes;
+ std::vector<int> connections;
+
+ 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->notifyObservers(_idManager);
+ }
+ else if(type==GCONNECTOR)
+ {
+ int idCon = cont->getId();
+ connections.push_back(idCon);
+ }
+
+ }
+
+ for(int i = 0 ;i<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();
+ }
+
+ std::map<int, int>::iterator itIds;
+ for(itIds = oldIdNewIdBoxes.begin(); itIds != oldIdNewIdBoxes.end(); ++itIds)
+ {
+ int idOld = itIds->first;
+ int idNew = itIds->second;
+
+ GBlackBoxModel* oldBox = (GBlackBoxModel*)objectsMap[idOld]->getModel();
+ GBlackBoxModel* newBox = (GBlackBoxModel*)_controllers[idNew]->getModel();
+
+ std::vector<int> oldInputConnections = oldBox->getConnectedInputs();
+ std::vector<int> oldOutputConnections = oldBox->getConnectedOutputs();
+ std::vector<int> newInputConnections = newBox->getConnectedInputs();
+ std::vector<int> newOutputConnections = newBox->getConnectedOutputs();
+
+ for(int k = 0; k<oldInputConnections.size();k++)
+ {
+ bool exist=false;
+ int toCreate=-1;
+ for(int l = 0; l<newInputConnections.size() && !exist;l++)
+ {
+ if(oldInputConnections[k]==newInputConnections[l])
+ {
+ exist=true;
+ }
+ }
+
+ if(exist==false)
+ {
+ //Create complex input
+ int posInBox = oldInputConnections[k];
+ GPortModel* inputPort = oldBox->getInputPort(posInBox);
+ std::string inputPortName = inputPort->getBBTKName();
+ int idInputPort = createGComplexBoxInputPort(inputPortName);
+ GObjectController *cont = _controllers[idInputPort];
+ GBoxModel *cbmod = (GBoxModel*)cont->getModel();
+ double xIn,yIn,zIn;
+ inputPort->getInicPoint(xIn,yIn,zIn);
+ yIn+=20;
+ cbmod->setInicPoint(xIn,yIn,zIn);
+ cbmod->notifyObservers(_idManager);
+
+ GPortModel* inputPortEnd = newBox->getInputPort(posInBox);
+
+ // Creates connection
+ int idCon = createGConnector(cbmod->getOutputPort(0));
+ GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
+ GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
+ vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
+ tempp->endContourCreation();
+ conMod->setEndPort(inputPortEnd);
+ conView->updateStartEndPoints();
+
+ }
+
+ }
+
+
+ for(int k = 0; k<oldOutputConnections.size();k++)
+ {
+ bool exist=false;
+ int toCreate=-1;
+ for(int l = 0; l<newOutputConnections.size() && !exist;l++)
+ {
+ if(oldOutputConnections[k]==newOutputConnections[l])
+ {
+ exist=true;
+ }
+ }
+
+ if(exist==false)
+ {
+ //Create complex output
+ int posInBox = oldOutputConnections[k];
+ GPortModel* outputPort = oldBox->getOutputPort(posInBox);
+ std::string outputPortName = outputPort->getBBTKName();
+ int idOutputPort = createGComplexBoxOutputPort(outputPortName);
+ GObjectController *cont = _controllers[idOutputPort];
+ GBoxModel *cbmod = (GBoxModel*)cont->getModel();
+ double xIn,yIn,zIn;
+ outputPort->getInicPoint(xIn,yIn,zIn);
+ yIn-=20;
+ cbmod->setInicPoint(xIn,yIn,zIn);
+ cbmod->notifyObservers(_idManager);
+
+ GPortModel* outputPortEnd = newBox->getOutputPort(posInBox);
+
+ // Creates connection
+ int idCon = createGConnector(outputPortEnd);
+ GConnectorController *tempp = (GConnectorController*)_controllers[idCon];
+ GConnectorModel *conMod = (GConnectorModel*)tempp->getModel();
+ vtkGConnectorView *conView = (vtkGConnectorView*)tempp->getView();
+ tempp->endContourCreation();
+ conMod->setEndPort(cbmod->getInputPort(0));
+ conView->updateStartEndPoints();
+
+ }
+
+ }
+
+ }
+
+
+ }
+
+ //=========================================================================
+