+//=========================================================================
+
+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);
+
+ }
+ }
+
+