+ //ups2
+ int idCon = createGConnector(startP);
+
+ _worldState = NOTHING_HAPPENS;
+ GConnectorController *tempp = (GConnectorController*) _controllers[idCon];
+
+ GConnectorModel *conMod = (GConnectorModel*) tempp->getModel();
+ vtkGConnectorView *conView = (vtkGConnectorView*) tempp->getView();
+ tempp->endContourCreation();
+ conMod->setEndPort(endP);
+ conView->updateStartEndPoints();
+ return idCon;
+}
+
+//=========================================================================
+
+bool wxVtkSceneManager::boxExist(std::string boxname) {
+ bool ok = false;
+ std::map<int, GObjectController*>::iterator it;
+ for (it = _controllers.begin(); it != _controllers.end(); ++it) {
+ GObjectController *cont = it->second;
+ if (cont->getModel()->getBBTKName() == boxname) {
+ ok = true;
+ }
+ }
+ return ok;
+}
+
+//=========================================================================
+
+std::vector<int> wxVtkSceneManager::getBlackBoxes() {
+ std::vector<int> vect;
+ std::map<int, GObjectController*>::iterator it;
+ for (it = _controllers.begin(); it != _controllers.end(); ++it) {
+ GObjectController *cont = it->second;
+ if (cont->getGObjectType() == GBLACKBOX) {
+ vect.push_back(cont->getId());
+ }
+ }
+ return vect;
+}
+
+//=========================================================================
+
+std::vector<int> wxVtkSceneManager::getComplexInputPorts() {
+ std::vector<int> vect;
+ std::map<int, GObjectController*>::iterator it;
+ for (it = _controllers.begin(); it != _controllers.end(); ++it) {
+ GObjectController *cont = it->second;
+ if (cont->getGObjectType() == GCOMPLEXINPUTPORT) {
+ vect.push_back(cont->getId());
+ }
+ }
+ return vect;
+}
+
+//=========================================================================
+
+std::vector<int> wxVtkSceneManager::getComplexOutputPorts() {
+ std::vector<int> vect;
+ std::map<int, GObjectController*>::iterator it;
+ for (it = _controllers.begin(); it != _controllers.end(); ++it) {
+ GObjectController *cont = it->second;
+ if (cont->getGObjectType() == GCOMPLEXOUTPUTPORT) {
+ vect.push_back(cont->getId());
+ }
+ }
+ return vect;
+}
+
+//=========================================================================
+
+std::vector<int> wxVtkSceneManager::getConnections() {
+ std::vector<int> vect;
+ std::map<int, GObjectController*>::iterator it;
+ for (it = _controllers.begin(); it != _controllers.end(); ++it) {
+ GObjectController *cont = it->second;
+ if (cont->getGObjectType() == GCONNECTOR) {
+ vect.push_back(cont->getId());
+ }
+ }
+ return vect;
+}
+
+//=========================================================================
+
+bool wxVtkSceneManager::isComplexBox() {
+ return _isComplexBox;
+}
+
+//=========================================================================
+
+void wxVtkSceneManager::setComplexBox(bool val) {
+ _isComplexBox = val;
+}
+
+//=========================================================================
+
+int wxVtkSceneManager::addObjectController(GObjectController* objController) {
+ //Register the controller of the new object
+ registerController((InteractorStyleMaracas*) objController);
+ //Add the object to the objects list
+ int newId = _contLastId;//_controllers.size();
+ objController->setId(newId);
+ _controllers[newId] = objController;
+ //std::cout << "DFCH: int wxVtkSceneManager::addObjectController(GObjectController* objController) ---- _contLastId = " << _contLastId << std::endl;
+ _contLastId++;
+ 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);
+
+ }
+ }
+
+
+//=========================================================================
+
+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;
+ }
+ }