1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "XGUI_Workshop.h"
23 #include "XGUI_ActionsMgr.h"
24 #include "XGUI_MenuMgr.h"
25 #include "XGUI_ColorDialog.h"
26 #include "XGUI_DeflectionDialog.h"
27 #include "XGUI_TransparencyWidget.h"
28 #include "XGUI_ContextMenuMgr.h"
29 #include "XGUI_Displayer.h"
30 #include "XGUI_ErrorDialog.h"
31 #include "XGUI_ErrorMgr.h"
32 #include "XGUI_ModuleConnector.h"
33 #include "XGUI_ObjectsBrowser.h"
34 #include "XGUI_OperationMgr.h"
35 #include "XGUI_PropertyPanel.h"
36 #include "XGUI_PropertyDialog.h"
37 #include "XGUI_SalomeConnector.h"
38 #include "XGUI_Selection.h"
39 #include "XGUI_SelectionMgr.h"
40 #include "XGUI_Tools.h"
41 #include "XGUI_ViewerProxy.h"
42 #include "XGUI_WorkshopListener.h"
43 #include <XGUI_CustomPrs.h>
44 #include <XGUI_HistoryMenu.h>
45 #include <XGUI_QtEvents.h>
46 #include <XGUI_DataModel.h>
49 #include <AppElements_Button.h>
50 #include <AppElements_Command.h>
51 #include <AppElements_MainMenu.h>
52 #include <AppElements_MainWindow.h>
53 #include <AppElements_MenuGroupPanel.h>
54 #include <AppElements_Viewer.h>
55 #include <AppElements_Workbench.h>
58 #include <Config_XMLReader.h>
60 #include <ModelAPI_AttributeDocRef.h>
61 #include <ModelAPI_AttributeIntArray.h>
62 #include <ModelAPI_AttributeDouble.h>
63 #include <ModelAPI_Data.h>
64 #include <ModelAPI_Events.h>
65 #include <ModelAPI_Feature.h>
66 #include <ModelAPI_Object.h>
67 #include <ModelAPI_ResultBody.h>
68 #include <ModelAPI_ResultConstruction.h>
69 #include <ModelAPI_ResultGroup.h>
70 #include <ModelAPI_ResultParameter.h>
71 #include <ModelAPI_ResultField.h>
72 #include <ModelAPI_Session.h>
73 #include <ModelAPI_Validator.h>
74 #include <ModelAPI_ResultCompSolid.h>
75 #include <ModelAPI_Tools.h>
77 //#include <PartSetPlugin_Part.h>
79 #include <Events_Loop.h>
80 #include <Events_InfoMessage.h>
81 #include <Events_LongOp.h>
83 #include <ModuleBase_IModule.h>
84 #include <ModuleBase_IViewer.h>
85 #include <ModuleBase_Operation.h>
86 #include <ModuleBase_OperationDescription.h>
87 #include <ModuleBase_PageBase.h>
88 #include <ModuleBase_Preferences.h>
89 #include <ModuleBase_SelectionValidator.h>
90 #include <ModuleBase_Tools.h>
91 #include <ModuleBase_WidgetFactory.h>
92 #include <ModuleBase_OperationFeature.h>
93 #include <ModuleBase_OperationAction.h>
94 #include <ModuleBase_PagedContainer.h>
95 #include <ModuleBase_WidgetValidated.h>
96 #include <ModuleBase_ModelWidget.h>
97 #include <ModuleBase_ResultPrs.h>
99 #include <Config_Common.h>
100 #include <Config_FeatureMessage.h>
101 #include <Config_ModuleReader.h>
102 #include <Config_PointerMessage.h>
103 #include <Config_PropManager.h>
104 #include <Config_DataModelReader.h>
105 #include <Config_Translator.h>
106 #include <Config_WidgetAPI.h>
107 #include <Config_Keywords.h>
109 #include <SUIT_ResourceMgr.h>
111 #include <AIS_Trihedron.hxx>
112 #ifdef BEFORE_TRIHEDRON_PATCH
113 #include <AIS_Point.hxx>
114 #include <AIS_Axis.hxx>
117 #include <QApplication>
118 #include <QFileDialog>
119 #include <QMessageBox>
120 #include <QMdiSubWindow>
121 #include <QMainWindow>
122 #include <QPushButton>
123 #include <QDockWidget>
128 #include <QToolButton>
130 #include <QDesktopWidget>
135 #include <CDF_Session.hxx>
136 #include <CDF_Application.hxx>
137 #include <inspector/TInspector_Communicator.hxx>
138 #include <inspector/VInspector_CallBack.hxx>
139 static TInspector_Communicator* MyTCommunicator;
140 static Handle(VInspector_CallBack) MyVCallBack;
155 QString XGUI_Workshop::MOVE_TO_END_COMMAND = QObject::tr("Move to the end");
157 //#define DEBUG_DELETE
158 //#define DEBUG_FEATURE_NAME
159 //#define DEBUG_CLEAN_HISTORY
161 XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
163 myCurrentDir(QString()),
165 mySalomeConnector(theConnector),
169 //myViewerSelMode(TopAbs_FACE)
171 mySelector = new XGUI_SelectionMgr(this);
172 myModuleConnector = new XGUI_ModuleConnector(this);
173 myOperationMgr = new XGUI_OperationMgr(this, 0);
174 ModuleBase_IWorkshop* aWorkshop = moduleConnector();
175 // Has to be defined first in order to get errors and messages from other components
176 myEventsListener = new XGUI_WorkshopListener(aWorkshop);
178 SUIT_ResourceMgr* aResMgr = ModuleBase_Preferences::resourceMgr();
180 myMainWindow = new AppElements_MainWindow();
182 bool aCloc = aResMgr->booleanValue("language", "locale", true);
184 QLocale::setDefault( QLocale::c() );
186 QLocale::setDefault( QLocale::system() );
188 QString aPath = Config_XMLReader::pluginConfigFile().c_str();
193 aLangs << "*_en.ts"; // load by default eng translations
194 QString aCurrLang = aResMgr->stringValue("language", "language", "en");
195 if(aCurrLang != "en") {
196 aLangs << "*_" + aCurrLang + ".ts"; // then replace with translated files
199 foreach(QString aLang, aLangs) {
200 QStringList aFilters;
202 QStringList aTsFiles = aDir.entryList(aFilters, QDir::Files);
203 foreach(QString aFileName, aTsFiles) {
204 Config_Translator::load(aFileName.toStdString());
208 myDataModelXMLReader = new Config_DataModelReader();
209 //myDataModelXMLReader->readAll();
211 myDisplayer = new XGUI_Displayer(this);
213 connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(updateCommandStatus()));
215 myActionsMgr = new XGUI_ActionsMgr(this);
216 myMenuMgr = new XGUI_MenuMgr(this);
217 myErrorDlg = new XGUI_ErrorDialog(QApplication::desktop());
218 myContextMenuMgr = new XGUI_ContextMenuMgr(this);
219 connect(myContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), this,
220 SLOT(onContextMenuCommand(const QString&, bool)));
222 myViewerProxy = new XGUI_ViewerProxy(this);
223 //connect(myViewerProxy, SIGNAL(selectionChanged()),
224 // myActionsMgr, SLOT(updateOnViewSelection()));
226 myOperationMgr->setWorkshop(aWorkshop);
228 myErrorMgr = new XGUI_ErrorMgr(this, aWorkshop);
230 connect(myOperationMgr, SIGNAL(operationResumed(ModuleBase_Operation*)),
231 SLOT(onOperationResumed(ModuleBase_Operation*)));
232 connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
233 SLOT(onOperationStopped(ModuleBase_Operation*)));
234 connect(myOperationMgr, SIGNAL(operationCommitted(ModuleBase_Operation*)),
235 SLOT(onOperationCommitted(ModuleBase_Operation*)));
236 connect(myOperationMgr, SIGNAL(operationAborted(ModuleBase_Operation*)),
237 SLOT(onOperationAborted(ModuleBase_Operation*)));
240 connect(myMainWindow, SIGNAL(exitKeySequence()), SLOT(onExit()));
241 onTrihedronVisibilityChanged(true);
244 connect(myEventsListener, SIGNAL(errorOccurred(std::shared_ptr<Events_InfoMessage>)),
245 myErrorDlg, SLOT(addError(std::shared_ptr<Events_InfoMessage>)));
247 //Config_PropManager::registerProp("Visualization", "object_default_color", "Object color",
248 // Config_Prop::Color, "225,225,225");
250 Config_PropManager::registerProp("Visualization", "result_body_color", "Result color",
251 Config_Prop::Color, ModelAPI_ResultBody::DEFAULT_COLOR());
252 Config_PropManager::registerProp("Visualization", "result_group_color", "Group color",
253 Config_Prop::Color, ModelAPI_ResultGroup::DEFAULT_COLOR());
254 Config_PropManager::registerProp("Visualization", "result_construction_color",
255 "Construction color",
257 ModelAPI_ResultConstruction::DEFAULT_COLOR());
258 Config_PropManager::registerProp("Visualization", "result_part_color", "Part color",
259 Config_Prop::Color, ModelAPI_ResultPart::DEFAULT_COLOR());
260 Config_PropManager::registerProp("Visualization", "result_field_color", "Field color",
261 Config_Prop::Color, ModelAPI_ResultField::DEFAULT_COLOR());
263 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "face-selection", true))
264 myViewerSelMode.append(TopAbs_FACE);
265 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "edge-selection", true))
266 myViewerSelMode.append(TopAbs_EDGE);
267 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "vertex-selection", true))
268 myViewerSelMode.append(TopAbs_VERTEX);
269 //IMP: an attempt to use result selection with other selection modes
270 myViewerSelMode.append(ModuleBase_ResultPrs::Sel_Result);//TopAbs_VERTEX);
271 myViewerSelMode.append(TopAbs_COMPSOLID);
274 //******************************************************
275 XGUI_Workshop::~XGUI_Workshop(void)
278 #ifdef MISSED_TRANSLATION
279 // Save Missed translations
280 Config_Translator::saveMissedTranslations();
285 delete myDataModelXMLReader;
288 //******************************************************
289 void XGUI_Workshop::startApplication()
291 //Initialize event listening
292 myEventsListener->initializeEventListening();
294 myDataModelXMLReader->readAll();
297 Config_PropManager::registerProp("Plugins", "default_path", "Default Path",
298 Config_Prop::Directory, "");
300 std::string aDir = Config_XMLReader::resourcesConfigFile();
301 Config_PropManager::registerProp("Plugins", "import_initial_path", "Import initial directory",
302 Config_Prop::Directory, aDir);
305 Config_PropManager::registerProp("Plugins", "create_part_by_start", "Create Part by Start",
306 Config_Prop::Boolean, "false");
308 registerValidators();
310 // Calling of loadCustomProps before activating module is required
311 // by Config_PropManger to restore user-defined path to plugins
312 ModuleBase_Preferences::loadCustomProps();
316 myMainWindow->show();
317 updateCommandStatus();
322 myViewerProxy->connectViewProxy();
323 connect(myViewerProxy, SIGNAL(trihedronVisibilityChanged(bool)),
324 SLOT(onTrihedronVisibilityChanged(bool)));
326 emit applicationStarted();
329 bool aNewPart = Config_PropManager::boolean("Plugins", "create_part_by_start");
331 module()->launchOperation("Part", false); // PartSetPlugin_Part::ID()
336 void XGUI_Workshop::activateModule()
338 myModule->activateSelectionFilters();
340 connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
341 myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
342 connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
343 myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
345 updateCommandStatus();
347 // TODO: get default selection mode
349 // activate visualized objects in the viewer
350 activateObjectsSelection(displayer()->displayedObjects());
351 myOperationMgr->activate();
354 void XGUI_Workshop::deactivateModule()
356 myModule->deactivateSelectionFilters();
358 // remove internal displayer filter
359 displayer()->deactivateSelectionFilters();
361 disconnect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
362 myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
363 disconnect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
364 myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
366 XGUI_Displayer* aDisplayer = displayer();
367 QObjectPtrList aDisplayed = aDisplayer->displayedObjects();
368 aDisplayer->deactivateObjects(aDisplayed, true);
369 Handle(AIS_InteractiveContext) aContext = viewer()->AISContext();
370 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(aDisplayer->getTrihedron());
371 /// deactivate trihedron in selection modes
372 TColStd_ListOfInteger aTColModes;
373 aContext->ActivatedModes(aTrihedron, aTColModes);
374 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
375 for (; itr.More(); itr.Next() ) {
376 Standard_Integer aMode = itr.Value();
377 aContext->Deactivate(aTrihedron, aMode);
379 #ifdef BEFORE_TRIHEDRON_PATCH
380 /// Trihedron problem: objects stayed in the viewer, should be removed manually
381 /// otherwise in SALOME happens crash by HideAll in the viewer
382 aContext->Remove(aTrihedron->Position(), true);
383 aContext->Remove(aTrihedron->Axis(), true);
384 aContext->Remove(aTrihedron->XAxis(), true);
385 aContext->Remove(aTrihedron->YAxis(), true);
388 myOperationMgr->deactivate();
391 //******************************************************
392 void XGUI_Workshop::initMenu()
394 myContextMenuMgr->createActions();
397 // Create only Undo, Redo commands
398 QAction* aAction = salomeConnector()->addDesktopCommand("UNDO_CMD", tr("Undo"),
399 tr("Undo last command"),
400 QIcon(":pictures/undo.png"),
401 QKeySequence::Undo, false,
403 QString aToolBarTitle = tr( "INF_DESK_TOOLBAR_STANDARD" );
404 salomeConnector()->addActionInToolbar( aAction,aToolBarTitle );
406 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onUndo()));
407 addHistoryMenu(aAction, SIGNAL(updateUndoHistory(const QList<ActionInfo>&)), SLOT(onUndo(int)));
409 aAction = salomeConnector()->addDesktopCommand("REDO_CMD", tr("Redo"), tr("Redo last command"),
410 QIcon(":pictures/redo.png"), QKeySequence::Redo,
411 false, "MEN_DESK_EDIT");
412 salomeConnector()->addActionInToolbar( aAction, aToolBarTitle );
414 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo()));
415 addHistoryMenu(aAction, SIGNAL(updateRedoHistory(const QList<ActionInfo>&)), SLOT(onRedo(int)));
417 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
418 //aAction = salomeConnector()->addDesktopCommand("REBUILD_CMD", tr("Rebuild"),
419 // tr("Rebuild data objects"),
420 // QIcon(":pictures/rebuild.png"), QKeySequence(),
421 // false, "MEN_DESK_EDIT");
422 //salomeConnector()->addActionInToolbar( aAction, aToolBarTitle );
424 //connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRebuild()));
425 //salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
427 aAction = salomeConnector()->addDesktopCommand("SAVEAS_CMD", tr("Export native..."),
428 tr("Export the current document into a native file"),
429 QIcon(), QKeySequence(),
430 false, "MEN_DESK_FILE");
431 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onSaveAs()));
433 aAction = salomeConnector()->addDesktopCommand("OPEN_CMD", tr("Import native..."),
434 tr("Import native file"),
435 QIcon(), QKeySequence(),
436 false, "MEN_DESK_FILE");
437 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onOpen()));
438 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_FILE");
441 // File commands group
442 AppElements_MenuGroupPanel* aGroup = myMainWindow->menuObject()->generalPage();
444 AppElements_Command* aCommand;
446 aCommand = aGroup->addFeature("SAVE_CMD", tr("Save"), tr("Save the document"),
447 QIcon(":pictures/save.png"), QKeySequence::Save);
448 aCommand->connectTo(this, SLOT(onSave()));
449 //aCommand->disable();
451 aCommand = aGroup->addFeature("SAVEAS_CMD", tr("Save as..."), tr("Save the document into a file"),
452 QIcon(":pictures/save.png"), QKeySequence());
453 aCommand->connectTo(this, SLOT(onSaveAs()));
455 QString aUndoId = "UNDO_CMD";
456 aCommand = aGroup->addFeature(aUndoId, tr("Undo"), tr("Undo last command"),
457 QIcon(":pictures/undo.png"), QKeySequence::Undo);
458 aCommand->connectTo(this, SLOT(onUndo()));
459 AppElements_Button* aUndoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aUndoId));
460 addHistoryMenu(aUndoButton,
461 SIGNAL(updateUndoHistory(const QList<ActionInfo>&)),
464 QString aRedoId = "REDO_CMD";
465 aCommand = aGroup->addFeature(aRedoId, tr("Redo"), tr("Redo last command"),
466 QIcon(":pictures/redo.png"), QKeySequence::Redo);
467 aCommand->connectTo(this, SLOT(onRedo()));
468 AppElements_Button* aRedoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aRedoId));
469 addHistoryMenu(aRedoButton,
470 SIGNAL(updateRedoHistory(const QList<ActionInfo>&)),
473 //aCommand = aGroup->addFeature("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
474 // QIcon(":pictures/rebuild.png"), QKeySequence());
475 //aCommand->connectTo(this, SLOT(onRebuild()));
477 //aCommand->disable();
479 aCommand = aGroup->addFeature("OPEN_CMD", tr("Open..."), tr("Open a new document"),
480 QIcon(":pictures/open.png"), QKeySequence::Open);
481 aCommand->connectTo(this, SLOT(onOpen()));
483 aCommand = aGroup->addFeature("PREF_CMD", tr("Preferences"), tr("Edit preferences"),
484 QIcon(":pictures/preferences.png"), QKeySequence::Preferences);
485 aCommand->connectTo(this, SLOT(onPreferences()));
487 aCommand = aGroup->addFeature("EXIT_CMD", tr("Exit"), tr("Exit application"),
488 QIcon(":pictures/close.png"), QKeySequence::Close);
489 aCommand->connectTo(this, SLOT(onExit()));
494 AppElements_Workbench* XGUI_Workshop::addWorkbench(const QString& theName)
496 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
497 return aMenuBar->addWorkbench(theName);
501 //******************************************************
502 QMainWindow* XGUI_Workshop::desktop() const
505 return salomeConnector()->desktop();
511 //******************************************************
512 void XGUI_Workshop::onStartWaiting()
514 if (Events_LongOp::isPerformed()) {
515 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
519 //******************************************************
520 void XGUI_Workshop::onAcceptActionClicked()
522 QAction* anAction = dynamic_cast<QAction*>(sender());
523 XGUI_OperationMgr* anOperationMgr = operationMgr();
524 if (anOperationMgr) {
525 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
526 (anOperationMgr->currentOperation());
528 //if (errorMgr()->canProcessClick(anAction, aFOperation->feature()))
529 myOperationMgr->commitOperation();
534 //******************************************************
535 void XGUI_Workshop::onPreviewActionClicked()
537 ModuleBase_IPropertyPanel* aPanel = propertyPanel();
539 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
540 if (anActiveWidget && anActiveWidget->getValueState() == ModuleBase_ModelWidget::ModifiedInPP) {
541 anActiveWidget->storeValue();
544 std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
545 new Events_Message(Events_Loop::eventByName(EVENT_PREVIEW_REQUESTED)));
546 Events_Loop::loop()->send(aMsg);
549 //******************************************************
550 void XGUI_Workshop::deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer)
552 if (!myModule->canActivateSelection(theObject)) {
553 if (myDisplayer->isActive(theObject)) {
554 QObjectPtrList anObjects;
555 anObjects.append(theObject);
556 myDisplayer->deactivateObjects(anObjects, theUpdateViewer);
561 //******************************************************
562 bool XGUI_Workshop::isFeatureOfNested(const FeaturePtr& theFeature)
564 bool aHasNested = false;
565 std::string aFeatureKind = theFeature->getKind();
567 XGUI_SalomeConnector* aSalomeConnector = salomeConnector();
568 if (aSalomeConnector->isFeatureOfNested(actionsMgr()->action(aFeatureKind.c_str())))
571 AppElements_MainMenu* aMenuBar = mainWindow()->menuObject();
572 AppElements_Command* aCommand = aMenuBar->feature(aFeatureKind.c_str());
573 if (aCommand && aCommand->button()->additionalButtonWidget())
579 void XGUI_Workshop::fillPropertyPanel(ModuleBase_Operation* theOperation)
581 ModuleBase_OperationFeature* aFOperation =
582 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
587 myPropertyPanel->cleanContent();
589 QList<ModuleBase_ModelWidget*> aWidgets;
590 if (!module()->createWidgets(theOperation, aWidgets)) {
591 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
592 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), myModuleConnector);
593 aFactory.createWidget(myPropertyPanel->contentWidget());
594 aWidgets = aFactory.getModelWidgets();
597 // check compatibility of feature and widgets
598 FeaturePtr aFeature = aFOperation->feature();
599 std::string aFeatureKind = aFeature->getKind();
600 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
601 if (!aWidget->attributeID().empty() && !aFeature->attribute(aWidget->attributeID()).get()) {
602 std::string anErrorMsg = "The feature '%1' has no attribute '%2' used by widget '%3'.";
603 Events_InfoMessage("XGUI_Workshop", anErrorMsg)
604 .arg(aFeatureKind).arg(aWidget->attributeID())
605 .arg(aWidget->metaObject()->className()).send();
606 myPropertyPanel->cleanContent();
610 // for performance purpose, flush should be done after all controls are filled
611 bool isUpdateFlushed = false;
612 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
613 bool isStoreValue = !aFOperation->isEditOperation() &&
614 !aWidget->getDefaultValue().empty() &&
615 !aWidget->isComputedDefault();
616 aWidget->setFeature(aFeature, isStoreValue, isUpdateFlushed);
618 aWidget->restoreValue();
619 aWidget->enableFocusProcessing();
621 // update visible state of Preview button
622 std::shared_ptr<Config_FeatureMessage> aFeatureInfo;
624 aFeatureInfo = mySalomeConnector->featureInfo(aFeatureKind.c_str());
626 AppElements_MainMenu* aMenuBar = mainWindow()->menuObject();
627 AppElements_Command* aCommand = aMenuBar->feature(aFeatureKind.c_str());
629 aFeatureInfo = aCommand->featureMessage();
631 bool anIsAutoPreview = true;
632 if (aFeatureInfo.get())
633 anIsAutoPreview = aFeatureInfo->isAutoPreview();
635 std::string aXmlCfg, aDescription;
636 module()->getXMLRepresentation(aFeatureKind, aXmlCfg, aDescription);
637 ModuleBase_WidgetFactory aFactory(aXmlCfg, moduleConnector());
638 anIsAutoPreview = aFactory.widgetAPI()->getBooleanAttribute(FEATURE_AUTO_PREVIEW, true);
641 if (!anIsAutoPreview) {
642 myPropertyPanel->findButton(PROP_PANEL_PREVIEW)->setVisible(true);
643 // send signal about preview should not be computed automatically, click on preview
644 // button should initiate it
645 std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
646 new Events_Message(Events_Loop::eventByName(EVENT_PREVIEW_BLOCKED)));
647 Events_Loop::loop()->send(aMsg);
649 // if update happens after preview is blocked, it does nothing when blocked
650 // it improves performance for valid objects on feature start
651 ModuleBase_Tools::flushUpdated(aFeature);
653 myPropertyPanel->setModelWidgets(aWidgets);
654 aFOperation->setPropertyPanel(myPropertyPanel);
656 myModule->propertyPanelDefined(theOperation);
658 #ifndef DEBUG_FEATURE_NAME
659 myPropertyPanel->setWindowTitle(theOperation->getDescription()->description());
661 std::string aFeatureName = aFeature->name();
662 myPropertyPanel->setWindowTitle(QString("%1: %2")
663 .arg(theOperation->getDescription()->description())
664 .arg(aFeatureName.c_str()));
667 myErrorMgr->setPropertyPanel(myPropertyPanel);
670 void XGUI_Workshop::connectToPropertyPanel(const bool isToConnect)
672 XGUI_PropertyPanel* aPropertyPanel = propertyPanel();
673 if (aPropertyPanel) {
674 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
675 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
676 myModule->connectToPropertyPanel(aWidget, isToConnect);
678 connect(aWidget, SIGNAL(valueStateChanged(int)), this, SLOT(onWidgetStateChanged(int)));
679 connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
680 connect(aWidget, SIGNAL(objectUpdated()), this, SLOT(onWidgetObjectUpdated()));
683 disconnect(aWidget, SIGNAL(valueStateChanged(int)), this, SLOT(onWidgetStateChanged(int)));
684 disconnect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
685 disconnect(aWidget, SIGNAL(objectUpdated()), this, SLOT(onWidgetObjectUpdated()));
691 //******************************************************
692 void XGUI_Workshop::onOperationResumed(ModuleBase_Operation* theOperation)
694 setGrantedFeatures(theOperation);
696 if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
697 fillPropertyPanel(theOperation);
698 connectToPropertyPanel(true);
700 updateCommandStatus();
702 myModule->operationResumed(theOperation);
706 //******************************************************
707 void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
709 updateCommandStatus();
711 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
716 ModuleBase_ISelection* aSel = mySelector->selection();
717 QObjectPtrList aObj = aSel->selectedPresentations();
718 //!< No need for property panel
720 myPropertyPanel->cleanContent();
722 connectToPropertyPanel(false);
723 myModule->operationStopped(aFOperation);
725 // the deactivated objects of the current operation should be activated back.
726 // They were deactivated on operation start or an object redisplay
727 QObjectPtrList anObjects;
728 FeaturePtr aFeature = aFOperation->feature();
729 if (aFeature.get()) { // feature may be not created (plugin load fail)
730 if (myDisplayer->isVisible(aFeature) && !myDisplayer->isActive(aFeature))
731 anObjects.append(aFeature);
732 std::list<ResultPtr> aResults;
733 ModelAPI_Tools::allResults(aFeature, aResults);
734 std::list<ResultPtr>::const_iterator aIt;
735 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
736 ResultPtr anObject = *aIt;
737 if (myDisplayer->isVisible(anObject) && !myDisplayer->isActive(anObject)) {
738 anObjects.append(anObject);
742 activateObjectsSelection(anObjects);
746 void XGUI_Workshop::onOperationCommitted(ModuleBase_Operation* theOperation)
748 myModule->operationCommitted(theOperation);
751 void XGUI_Workshop::onOperationAborted(ModuleBase_Operation* theOperation)
753 myModule->operationAborted(theOperation);
756 void XGUI_Workshop::setGrantedFeatures(ModuleBase_Operation* theOperation)
758 ModuleBase_OperationFeature* aFOperation =
759 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
763 QStringList aGrantedIds;
764 if (isSalomeMode()) {
765 const std::shared_ptr<Config_FeatureMessage>& anInfo =
766 mySalomeConnector->featureInfo(theOperation->id());
768 aGrantedIds = QString::fromStdString(anInfo->nestedFeatures())
769 .split(" ", QString::SkipEmptyParts);
772 aGrantedIds = myActionsMgr->nestedCommands(theOperation->id());
774 ModuleBase_IModule* aModule = module();
776 aModule->grantedOperationIds(theOperation, aGrantedIds);
778 aFOperation->setGrantedOperationIds(aGrantedIds);
781 //******************************************************
782 void XGUI_Workshop::saveDocument(const QString& theName, std::list<std::string>& theFileNames)
784 QApplication::restoreOverrideCursor();
785 SessionPtr aMgr = ModelAPI_Session::get();
787 std::list<DocumentPtr> aDocList = aMgr->allOpenedDocuments();
788 std::list<DocumentPtr>::const_iterator aIt;
789 for (aIt = aDocList.cbegin(); aIt != aDocList.cend(); aIt++) {
790 std::list<bool> aState = myObjectBrowser->getStateForDoc(*aIt);
791 (*aIt)->storeNodesState(aState);
794 aMgr->save(theName.toLatin1().constData(), theFileNames);
796 QApplication::restoreOverrideCursor();
799 //******************************************************
800 bool XGUI_Workshop::abortAllOperations()
802 return myOperationMgr->abortAllOperations();
805 //******************************************************
806 void XGUI_Workshop::operationStarted(ModuleBase_Operation* theOperation)
808 setGrantedFeatures(theOperation);
809 if (!theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
810 updateCommandStatus();
813 myModule->operationStarted(theOperation);
817 //******************************************************
818 void XGUI_Workshop::onOpen()
820 if(!abortAllOperations())
822 //save current file before close if modified
823 SessionPtr aSession = ModelAPI_Session::get();
824 if (aSession->isModified()) {
825 //TODO(sbh): re-launch the app?
826 int anAnswer = QMessageBox::question(
827 desktop(), tr("Save current file"),
828 tr("The document is modified, save before opening another?"),
829 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
830 if (anAnswer == QMessageBox::Save) {
832 } else if (anAnswer == QMessageBox::Cancel) {
838 //show file dialog, check if readable and open
839 QString aDirectory = QFileDialog::getExistingDirectory(desktop(), tr("Select directory"));
840 openDirectory(aDirectory);
843 //******************************************************
844 void XGUI_Workshop::openDirectory(const QString& theDirectory)
846 myCurrentDir = theDirectory;
847 if (myCurrentDir.isEmpty())
850 QFileInfo aFileInfo(myCurrentDir);
851 if (!aFileInfo.exists() || !aFileInfo.isReadable()) {
852 QMessageBox::critical(desktop(), tr("Warning"), tr("Unable to open the file."));
857 QApplication::setOverrideCursor(Qt::WaitCursor);
858 module()->closeDocument();
859 SessionPtr aSession = ModelAPI_Session::get();
860 aSession->closeAll();
861 aSession->load(myCurrentDir.toLatin1().constData());
862 myObjectBrowser->rebuildDataTree();
864 // Open first level of data tree
865 DocumentPtr aRootDoc = aSession->moduleDocument();
866 std::list<bool> aStates;
867 aRootDoc->restoreNodesState(aStates);
868 myObjectBrowser->setStateForDoc(aRootDoc, aStates);
870 updateCommandStatus();
872 myMainWindow->setCurrentDir(myCurrentDir, true);
876 bool aNewPart = Config_PropManager::boolean("Plugins", "create_part_by_start");
879 DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
880 int aSize = aRootDoc->size(ModelAPI_ResultPart::group());
882 ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), 0);
883 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
890 QApplication::restoreOverrideCursor();
893 //******************************************************
894 void XGUI_Workshop::onNew()
896 QApplication::setOverrideCursor(Qt::WaitCursor);
897 if (objectBrowser() == 0) {
899 mySelector->connectViewers();
901 myViewerProxy->connectToViewer();
904 myMainWindow->showPythonConsole();
905 QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
906 aWnd->showMaximized();
907 updateCommandStatus();
909 myContextMenuMgr->connectViewer();
910 QApplication::restoreOverrideCursor();
914 //******************************************************
915 void XGUI_Workshop::onExit()
917 SessionPtr aMgr = ModelAPI_Session::get();
918 if (aMgr->isModified()) {
919 int anAnswer = QMessageBox::question(
920 myMainWindow, tr("Save current file"), tr("The document is modified, save before exit?"),
921 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
922 if (anAnswer == QMessageBox::Save) {
923 bool saved = onSave();
927 } else if (anAnswer == QMessageBox::Cancel) {
934 //******************************************************
935 void XGUI_Workshop::onPreferences()
937 ModuleBase_Prefs aModif;
938 ModuleBase_Preferences::editPreferences(aModif);
939 if (aModif.size() > 0) {
941 foreach (ModuleBase_Pref aPref, aModif)
943 aSection = aPref.first;
944 if (aSection == ModuleBase_Preferences::VIEWER_SECTION) {
945 myMainWindow->viewer()->updateFromResources();
946 } else if (aSection == ModuleBase_Preferences::MENU_SECTION) {
947 myMainWindow->menuObject()->updateFromResources();
950 displayer()->redisplayObjects();
955 //******************************************************
956 void XGUI_Workshop::onTrihedronVisibilityChanged(bool theState)
958 XGUI_Displayer* aDisplayer = displayer();
960 aDisplayer->displayTrihedron(theState);
963 //******************************************************
964 bool XGUI_Workshop::onSave()
966 if(!myOperationMgr->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
968 if (myCurrentDir.isEmpty()) {
971 std::list<std::string> aFiles;
972 saveDocument(myCurrentDir, aFiles);
973 updateCommandStatus();
975 myMainWindow->setModifiedState(false);
980 //******************************************************
981 bool XGUI_Workshop::onSaveAs()
983 if(!myOperationMgr->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
985 QFileDialog dialog(desktop());
986 dialog.setWindowTitle(tr("Select directory to save files..."));
987 dialog.setFileMode(QFileDialog::Directory);
988 dialog.setFilter(QDir::AllDirs);
989 dialog.setOptions(QFileDialog::HideNameFilterDetails | QFileDialog::ShowDirsOnly);
990 dialog.setViewMode(QFileDialog::Detail);
992 if (!dialog.exec()) {
996 QString aTempDir = dialog.selectedFiles().first();
998 if (aDir.exists() && !aDir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries).isEmpty()) {
999 int answer = QMessageBox::question(
1001 // Title of the dialog which asks user if he wants to save study
1002 // in existing non-empty folder
1004 tr("The directory already contains some files, save anyway?"),
1005 QMessageBox::Save | QMessageBox::Cancel);
1006 if (answer == QMessageBox::Cancel) {
1010 myCurrentDir = aTempDir;
1012 myMainWindow->setCurrentDir(myCurrentDir, false);
1013 myMainWindow->setModifiedState(false);
1018 //******************************************************
1019 void XGUI_Workshop::onUndo(int theTimes)
1021 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1022 if (anActiveWidget && anActiveWidget->processAction(ActionUndo))
1025 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
1026 SessionPtr aMgr = ModelAPI_Session::get();
1027 std::list<std::string> aUndoList = aMgr->undoList();
1028 if (aMgr->isOperation()) {
1029 /// this is important for nested operations
1030 /// when sketch operation is active, this condition is false and
1031 /// the sketch operation is not aborted
1032 operationMgr()->onAbortOperation();
1034 std::list<std::string>::const_iterator aIt = aUndoList.cbegin();
1035 for (int i = 0; (i < theTimes) && (aIt != aUndoList.cend()); ++i, ++aIt) {
1037 if (QString((*aIt).c_str()) == MOVE_TO_END_COMMAND)
1038 myObjectBrowser->rebuildDataTree();
1041 operationMgr()->updateApplyOfOperations();
1042 updateCommandStatus();
1045 //******************************************************
1046 void XGUI_Workshop::onRedo(int theTimes)
1048 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1049 if (anActiveWidget && anActiveWidget->processAction(ActionRedo))
1052 // the viewer update should be blocked in order to avoid the features blinking. For the created
1053 // feature a results are created, the flush of the created signal caused the viewer redisplay for
1054 // each created result. After a redisplay signal is flushed. So, the viewer update is blocked
1055 // until redo of all possible objects happens
1056 bool isUpdateEnabled = myDisplayer->enableUpdateViewer(false);
1058 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
1059 SessionPtr aMgr = ModelAPI_Session::get();
1060 std::list<std::string> aRedoList = aMgr->redoList();
1061 if (aMgr->isOperation()) {
1062 /// this is important for nested operations
1063 /// when sketch operation is active, this condition is false and
1064 /// the sketch operation is not aborted
1065 operationMgr()->onAbortOperation();
1067 std::list<std::string>::const_iterator aIt = aRedoList.cbegin();
1068 for (int i = 0; (i < theTimes) && (aIt != aRedoList.cend()); ++i, ++aIt) {
1070 if (QString((*aIt).c_str()) == MOVE_TO_END_COMMAND)
1071 myObjectBrowser->rebuildDataTree();
1073 operationMgr()->updateApplyOfOperations();
1074 updateCommandStatus();
1076 // unblock the viewer update functionality and make update on purpose
1077 myDisplayer->enableUpdateViewer(isUpdateEnabled);
1078 myDisplayer->updateViewer();
1081 //******************************************************
1082 //void XGUI_Workshop::onRebuild()
1084 // SessionPtr aMgr = ModelAPI_Session::get();
1085 // bool aWasOperation = aMgr->isOperation(); // keep this value
1086 // if (!aWasOperation) {
1087 // aMgr->startOperation("Rebuild");
1089 // static const Events_ID aRebuildEvent = Events_Loop::loop()->eventByName("Rebuild");
1090 // Events_Loop::loop()->send(std::shared_ptr<Events_Message>(
1091 // new Events_Message(aRebuildEvent, this)));
1092 // if (!aWasOperation) {
1093 // aMgr->finishOperation();
1095 // updateCommandStatus();
1098 //******************************************************
1099 void XGUI_Workshop::onWidgetStateChanged(int thePreviousState)
1101 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1102 //ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
1103 //if (anOperation) {
1104 // ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1106 // anActiveWidget = aPanel->activeWidget();
1109 operationMgr()->onValidateOperation();
1111 myModule->widgetStateChanged(thePreviousState);
1114 //******************************************************
1115 void XGUI_Workshop::onValuesChanged()
1117 ModuleBase_ModelWidget* aSenderWidget = (ModuleBase_ModelWidget*)(sender());
1118 if (!aSenderWidget || aSenderWidget->canAcceptFocus())
1121 ModuleBase_ModelWidget* anActiveWidget = 0;
1122 ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
1124 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1126 anActiveWidget = aPanel->activeWidget();
1128 if (anActiveWidget) {
1129 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1131 if (aWidgetValidated)
1132 aWidgetValidated->clearValidatedCash();
1136 void XGUI_Workshop::onWidgetObjectUpdated()
1138 operationMgr()->onValidateOperation();
1141 ModuleBase_IModule* XGUI_Workshop::loadModule(const QString& theModule)
1143 QString libName = QString::fromStdString(library(theModule.toStdString()));
1144 if (libName.isEmpty()) {
1145 qWarning(qPrintable(tr("Information about module \"%1\" doesn't exist.").arg(theModule)));
1150 CREATE_FUNC crtInst = 0;
1153 HINSTANCE modLib = ::LoadLibrary((LPTSTR) qPrintable(libName));
1157 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
1158 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
1159 QString aMsg((char*) &lpMsgBuf);
1160 err = QString("Failed to load %1. %2").arg(libName).arg(aMsg);
1161 ::LocalFree(lpMsgBuf);
1163 crtInst = (CREATE_FUNC) ::GetProcAddress(modLib, CREATE_MODULE);
1167 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
1168 | FORMAT_MESSAGE_IGNORE_INSERTS,
1169 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
1170 QString aMsg((char*) &lpMsgBuf);
1171 err = QString("Failed to find %1 function. %2").arg( CREATE_MODULE).arg(aMsg);
1172 ::LocalFree(lpMsgBuf);
1176 void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY | RTLD_GLOBAL );
1178 err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
1180 crtInst = (CREATE_FUNC)dlsym( modLib, CREATE_MODULE );
1182 err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() );
1187 ModuleBase_IModule* aModule = crtInst ? crtInst(myModuleConnector) : 0;
1189 if (!err.isEmpty()) {
1191 Events_InfoMessage("XGUI_Workshop", err.toStdString()).send();
1193 qWarning(qPrintable(err));
1199 //******************************************************
1200 bool XGUI_Workshop::createModule()
1202 Config_ModuleReader aModuleReader;
1203 QString moduleName = QString::fromStdString(aModuleReader.getModuleName());
1204 myModule = loadModule(moduleName);
1208 //connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
1209 // myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
1210 //connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
1211 // myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
1213 myModule->createFeatures();
1215 salomeConnector()->createFeatureActions();
1217 //myActionsMgr->update();
1221 //******************************************************
1222 void XGUI_Workshop::updateCommandStatus()
1224 QList<QAction*> aCommands;
1226 aCommands = salomeConnector()->commandList();
1228 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
1229 foreach (AppElements_Command* aCmd, aMenuBar->features())
1230 aCommands.append(aCmd);
1232 SessionPtr aMgr = ModelAPI_Session::get();
1233 if (aMgr->hasModuleDocument()) {
1234 foreach(QAction* aCmd, aCommands) {
1235 QString aId = aCmd->data().toString();
1236 if (aId == "UNDO_CMD") {
1237 bool isActionEnabled = false;
1238 // if ultimate is true -> using result of operation only, or using OR combination
1239 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1240 if (anActiveWidget && anActiveWidget->canProcessAction(ActionUndo, isActionEnabled))
1241 aCmd->setEnabled(isActionEnabled);
1243 aCmd->setEnabled(myModule->canUndo());
1245 else if (aId == "REDO_CMD") {
1246 bool isActionEnabled = false;
1247 // if ultimate is true -> using result of operation only, or using OR combination
1248 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1249 if (anActiveWidget && anActiveWidget->canProcessAction(ActionRedo, isActionEnabled))
1250 aCmd->setEnabled(isActionEnabled);
1252 aCmd->setEnabled(myModule->canRedo());
1255 // Enable all commands
1256 aCmd->setEnabled(true);
1260 foreach(QAction* aCmd, aCommands) {
1261 QString aId = aCmd->data().toString();
1262 if (aId == "NEW_CMD")
1263 aCmd->setEnabled(true);
1264 else if (aId == "EXIT_CMD")
1265 aCmd->setEnabled(true);
1267 aCmd->setEnabled(false);
1270 myActionsMgr->updateCommandsStatus();
1271 emit commandStatusUpdated();
1274 void XGUI_Workshop::updateHistory()
1276 std::list<std::string> aUndoList = ModelAPI_Session::get()->undoList();
1277 QList<ActionInfo> aUndoRes = processHistoryList(aUndoList);
1278 emit updateUndoHistory(aUndoRes);
1280 std::list<std::string> aRedoList = ModelAPI_Session::get()->redoList();
1281 QList<ActionInfo> aRedoRes = processHistoryList(aRedoList);
1282 emit updateRedoHistory(aRedoRes);
1285 //******************************************************
1286 QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
1288 QDockWidget* aObjDock = new QDockWidget(theParent);
1289 aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea |
1290 Qt::RightDockWidgetArea |
1291 Qt::BottomDockWidgetArea);
1292 aObjDock->setWindowTitle(tr("Object browser"));
1293 aObjDock->setStyleSheet(
1294 "::title { position: relative; padding-left: 5px; text-align: left center }");
1295 myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock, this);
1296 myObjectBrowser->setXMLReader(myDataModelXMLReader);
1297 myModule->customizeObjectBrowser(myObjectBrowser);
1298 aObjDock->setWidget(myObjectBrowser);
1300 myContextMenuMgr->connectObjectBrowser();
1304 //******************************************************
1306 * Creates dock widgets, places them in corresponding area
1307 * and tabifies if necessary.
1309 void XGUI_Workshop::createDockWidgets()
1311 QMainWindow* aDesktop = desktop();
1312 QDockWidget* aObjDock = createObjectBrowser(aDesktop);
1313 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
1314 myPropertyPanel = new XGUI_PropertyPanel(aDesktop, myOperationMgr);
1315 myPropertyPanel->setupActions(myActionsMgr);
1316 myPropertyPanel->setAllowedAreas(Qt::LeftDockWidgetArea |
1317 Qt::RightDockWidgetArea |
1318 Qt::BottomDockWidgetArea);
1319 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel);
1320 hidePropertyPanel(); ///<! Invisible by default
1321 hideObjectBrowser();
1322 aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
1323 myPropertyPanel->installEventFilter(myOperationMgr);
1325 QAction* aOkAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept);
1326 connect(aOkAct, SIGNAL(triggered()), this, SLOT(onAcceptActionClicked()));
1328 QAction* aCancelAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Abort);
1329 connect(aCancelAct, SIGNAL(triggered()), myOperationMgr, SLOT(onAbortOperation()));
1331 QAction* aPreviewAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Preview);
1332 connect(aPreviewAct, SIGNAL(triggered()), this, SLOT(onPreviewActionClicked()));
1334 connect(myPropertyPanel, SIGNAL(keyReleased(QObject*, QKeyEvent*)),
1335 myOperationMgr, SLOT(onKeyReleased(QObject*, QKeyEvent*)));
1336 connect(myPropertyPanel, SIGNAL(enterClicked(QObject*)),
1337 myOperationMgr, SLOT(onProcessEnter(QObject*)));
1340 //******************************************************
1341 void XGUI_Workshop::showPropertyPanel()
1343 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1344 ///<! Restore ability to close panel from the window's menu
1345 aViewAct->setEnabled(true);
1346 myPropertyPanel->show();
1347 myPropertyPanel->raise();
1349 // The next code is necessary to made the property panel the active window
1350 // in order to operation manager could process key events of the panel.
1351 // otherwise they are ignored. It happens only if the same(activateWindow) is
1352 // not happened by property panel activation(e.g. resume operation of Sketch)
1353 ModuleBase_Tools::setFocus(myPropertyPanel, "XGUI_Workshop::showPropertyPanel()");
1356 //******************************************************
1357 void XGUI_Workshop::hidePropertyPanel()
1359 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1360 ///<! Do not allow to show empty property panel
1361 aViewAct->setEnabled(false);
1362 myPropertyPanel->hide();
1364 // the property panel is active window of the desktop, when it is
1365 // hidden, it is undefined which window becomes active. By this reason
1366 // it is defined to perform the desktop as the active window.
1367 // in SALOME mode, workstack made the PyConsole the active window,
1368 // set the focus on it. As a result, shortcuts of the application, like
1369 // are processed by this console. For example Undo actions.
1370 // It is possible that this code is to be moved to SHAPER package
1371 QMainWindow* aDesktop = desktop();
1372 ModuleBase_Tools::setFocus(aDesktop, "XGUI_Workshop::showPropertyPanel()");
1375 //******************************************************
1376 void XGUI_Workshop::showObjectBrowser()
1378 if (!isSalomeMode())
1379 myObjectBrowser->parentWidget()->show();
1382 //******************************************************
1383 void XGUI_Workshop::hideObjectBrowser()
1385 if (!isSalomeMode())
1386 myObjectBrowser->parentWidget()->hide();
1389 //******************************************************
1390 void XGUI_Workshop::salomeViewerSelectionChanged()
1392 emit salomeViewerSelection();
1395 //**************************************************************
1396 ModuleBase_IViewer* XGUI_Workshop::salomeViewer() const
1398 return mySalomeConnector->viewer();
1401 //**************************************************************
1402 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
1404 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1405 if (theId == "DELETE_CMD")
1407 else if (theId == "CLEAN_HISTORY_CMD")
1409 else if (theId == "MOVE_CMD")
1411 else if (theId == "COLOR_CMD")
1412 changeColor(aObjects);
1413 else if (theId == "DEFLECTION_CMD")
1414 changeDeflection(aObjects);
1415 #ifdef USE_TRANSPARENCY
1416 else if (theId == "TRANSPARENCY_CMD")
1417 changeTransparency(aObjects);
1419 else if (theId == "SHOW_CMD") {
1420 showObjects(aObjects, true);
1421 mySelector->updateSelectionBy(ModuleBase_ISelection::Browser);
1422 updateCommandStatus();
1424 else if (theId == "HIDE_CMD") {
1425 showObjects(aObjects, false);
1426 updateCommandStatus();
1428 else if (theId == "SHOW_ONLY_CMD") {
1429 showOnlyObjects(aObjects);
1430 mySelector->updateSelectionBy(ModuleBase_ISelection::Browser);
1431 updateCommandStatus();
1433 else if (theId == "SHADING_CMD")
1434 setDisplayMode(aObjects, XGUI_Displayer::Shading);
1435 else if (theId == "WIREFRAME_CMD")
1436 setDisplayMode(aObjects, XGUI_Displayer::Wireframe);
1437 else if (theId == "HIDEALL_CMD") {
1438 QObjectPtrList aList = myDisplayer->displayedObjects();
1439 foreach (ObjectPtr aObj, aList) {
1440 if (module()->canEraseObject(aObj))
1441 aObj->setDisplayed(false);
1443 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1445 //issue #2159 Hide all incomplete behavior
1446 viewer()->eraseAll();
1448 updateCommandStatus();
1449 } else if (theId == "SELECT_VERTEX_CMD") {
1450 setViewerSelectionMode(TopAbs_VERTEX);
1451 } else if (theId == "SELECT_EDGE_CMD") {
1452 setViewerSelectionMode(TopAbs_EDGE);
1453 } else if (theId == "SELECT_FACE_CMD") {
1454 setViewerSelectionMode(TopAbs_FACE);
1455 } else if (theId == "INSERT_FOLDER_CMD") {
1456 insertFeatureFolder();
1457 } else if (theId == "ADD_TO_FOLDER_BEFORE_CMD") {
1458 insertToFolder(true);
1459 } else if (theId == "ADD_TO_FOLDER_AFTER_CMD") {
1460 insertToFolder(false);
1461 } else if (theId == "ADD_OUT_FOLDER_BEFORE_CMD") {
1462 moveOutFolder(true);
1463 } else if (theId == "ADD_OUT_FOLDER_AFTER_CMD") {
1464 moveOutFolder(false);
1465 } else if (theId == "SELECT_RESULT_CMD") {
1466 //setViewerSelectionMode(-1);
1467 //IMP: an attempt to use result selection with other selection modes
1468 setViewerSelectionMode(ModuleBase_ResultPrs::Sel_Result);
1469 setViewerSelectionMode(TopAbs_COMPSOLID);
1470 } else if (theId == "SHOW_RESULTS_CMD") {
1471 highlightResults(aObjects);
1472 } else if (theId == "SHOW_FEATURE_CMD") {
1473 highlightFeature(aObjects);
1476 else if (theId == "TINSPECTOR_VIEW") {
1477 Handle(CDF_Application) anApplication = CDF_Session::CurrentSession()->CurrentApplication();
1478 if (!anApplication.IsNull())
1480 if (!MyTCommunicator)
1482 MyTCommunicator = new TInspector_Communicator();
1484 NCollection_List<Handle(Standard_Transient)> aParameters;
1485 aParameters.Append(anApplication);
1486 Handle(AIS_InteractiveContext) aContext = viewer()->AISContext();
1487 if (!aContext.IsNull())
1488 aParameters.Append(aContext);
1490 MyVCallBack = new VInspector_CallBack();
1491 myDisplayer->setCallBack(MyVCallBack);
1493 AppElements_Viewer* aViewer = mainWindow()->viewer();
1495 aViewer->setCallBack(MyVCallBack);
1497 aParameters.Append(MyVCallBack);
1499 MyTCommunicator->RegisterPlugin("TKDFBrowser");
1500 MyTCommunicator->RegisterPlugin("TKShapeView");
1501 MyTCommunicator->RegisterPlugin("TKVInspector");
1502 MyTCommunicator->RegisterPlugin("SMBrowser"); // custom plugin to view ModelAPI
1503 //MyTCommunicator->RegisterPlugin("TKSMBrowser"); // custom plugin to view ModelAPI
1505 MyTCommunicator->Init(aParameters);
1506 MyTCommunicator->Activate("TKSMBrowser"); // to have button in TInspector
1507 MyTCommunicator->Activate("TKVInspector"); // to have filled callback by model
1508 MyTCommunicator->Activate("TKDFBrowser");
1510 MyTCommunicator->SetVisible(true);
1516 //**************************************************************
1517 void XGUI_Workshop::setViewerSelectionMode(int theMode)
1520 myViewerSelMode.clear();
1522 if (myViewerSelMode.contains(theMode))
1523 myViewerSelMode.removeAll(theMode);
1525 myViewerSelMode.append(theMode);
1527 activateObjectsSelection(myDisplayer->displayedObjects());
1530 //**************************************************************
1531 void XGUI_Workshop::activateObjectsSelection(const QObjectPtrList& theList)
1534 module()->activeSelectionModes(aModes);
1535 if (aModes.isEmpty() && (myViewerSelMode.length() > 0))
1536 aModes.append(myViewerSelMode);
1537 myDisplayer->activateObjects(aModes, theList);
1540 //**************************************************************
1541 void XGUI_Workshop::deleteObjects()
1543 ModuleBase_IModule* aModule = module();
1544 // allow the module to delete objects, do nothing if it has succeed
1545 if (aModule->deleteObjects()) {
1546 updateCommandStatus();
1550 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1551 if (!abortAllOperations())
1554 bool hasResult = false;
1555 bool hasFeature = false;
1556 bool hasParameter = false;
1557 bool hasCompositeOwner = false;
1558 bool hasResultInHistory = false;
1559 bool hasFolder = false;
1560 ModuleBase_Tools::checkObjects(anObjects, hasResult, hasFeature, hasParameter, hasCompositeOwner,
1561 hasResultInHistory, hasFolder);
1562 if (!(hasFeature || hasParameter || hasFolder))
1566 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1567 std::set<FeaturePtr> aFeatures;
1568 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1569 ModelAPI_Tools::findAllReferences(aFeatures, aReferences);
1571 std::set<FolderPtr> aFolders;
1572 ModuleBase_Tools::convertToFolders(anObjects, aFolders);
1575 QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text() + " %1";
1576 aDescription = aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
1577 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, module());
1579 operationMgr()->startOperation(anOpAction);
1581 std::set<FeaturePtr> aFeatureRefsToDelete;
1582 if (ModuleBase_Tools::askToDelete(aFeatures, aReferences, desktop(), aFeatureRefsToDelete)) {
1583 // WORKAROUND, should be done before each object remove, if it presents in XGUI_DataModel tree
1584 // It is necessary to clear selection in order to avoid selection changed event during
1585 // deletion and negative consequences connected with processing of already deleted items
1586 mySelector->clearSelection();
1588 if (!aFeatureRefsToDelete.empty())
1589 aFeatures.insert(aFeatureRefsToDelete.begin(), aFeatureRefsToDelete.end());
1590 aDone = ModelAPI_Tools::removeFeatures(aFeatures, false);
1592 if (aFolders.size() > 0) {
1593 std::set<FolderPtr>::const_iterator anIt = aFolders.begin(),
1594 aLast = aFolders.end();
1595 for (; anIt != aLast; anIt++) {
1596 FolderPtr aFolder = *anIt;
1597 if (aFolder.get()) {
1598 DocumentPtr aDoc = aFolder->document();
1599 aDoc->removeFolder(aFolder);
1605 operationMgr()->commitOperation();
1607 operationMgr()->abortOperation(operationMgr()->currentOperation());
1610 //**************************************************************
1611 void addRefsToFeature(const FeaturePtr& theFeature,
1612 const std::map<FeaturePtr, std::set<FeaturePtr> >& theMainList,
1613 std::set<FeaturePtr>& theReferences)
1615 //if (theReferences.find(theFeature) != theReferences.end())
1617 if (theMainList.find(theFeature) == theMainList.end())
1618 return; // this feature is not in the selection list, so exists without references to it
1619 std::set<FeaturePtr> aMainReferences = theMainList.at(theFeature);
1621 std::set<FeaturePtr>::const_iterator anIt = aMainReferences.begin(),
1622 aLast = aMainReferences.end();
1623 for (; anIt != aLast; anIt++) {
1624 FeaturePtr aRefFeature = *anIt;
1625 if (theReferences.find(aRefFeature) == theReferences.end())
1626 theReferences.insert(aRefFeature);
1627 addRefsToFeature(aRefFeature, theMainList, theReferences);
1631 //**************************************************************
1632 void XGUI_Workshop::cleanHistory()
1634 if (!abortAllOperations())
1637 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1638 std::set<FeaturePtr> aFeatures;
1639 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1641 #ifdef DEBUG_CLEAN_HISTORY
1643 std::set<FeaturePtr>::const_iterator aFIt;
1644 for (aFIt = aFeatures.begin(); aFIt != aFeatures.end(); ++aFIt) {
1645 FeaturePtr aFeature = ModelAPI_Feature::feature(*aFIt);
1646 anInfo.append(aFeature->name().c_str());
1648 QString anInfoStr = anInfo.join(";\t");
1649 qDebug(QString("cleanHistory for: [%1] - %2").
1650 arg(aFeatures.size()).arg(anInfoStr).toStdString().c_str());
1653 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1654 ModelAPI_Tools::findAllReferences(aFeatures, aReferences, true, false);
1655 // find for each object whether all reference values are in the map as key, that means that there
1656 // is no other reference in the model to this object, so it might be removed by cleaning history
1657 // sk_1(ext_1, vertex_1) + (sk_3, bool_1) - cann't be deleted, dependency to bool_1
1658 // ext_1(bool_1, sk_3) - cann't be deleted, dependency to bool_1
1660 // sk_2(ext_2) + (bool_1) - cann't be deleted, dependency to bool_1
1661 // ext_2(bool_1) - cann't be deleted, dependency to bool_1
1663 // Information: bool_1 is not selected
1664 std::set<FeaturePtr> anUnusedObjects;
1665 std::map<FeaturePtr, std::set<FeaturePtr> >::const_iterator aMainIt = aReferences.begin(),
1666 aMainLast = aReferences.end();
1667 for (; aMainIt != aMainLast; aMainIt++) {
1668 FeaturePtr aMainListFeature = aMainIt->first;
1669 std::set<FeaturePtr> aMainRefList = aMainIt->second;
1670 std::set<FeaturePtr>::const_iterator aRefIt = aMainRefList.begin(),
1671 aRefLast = aMainRefList.end();
1672 bool aFeatureOutOfTheList = false;
1673 for (; aRefIt != aRefLast && !aFeatureOutOfTheList; aRefIt++) {
1674 FeaturePtr aRefFeature = *aRefIt;
1675 aFeatureOutOfTheList = aReferences.find(aRefFeature) == aReferences.end();
1677 if (!aFeatureOutOfTheList)
1678 anUnusedObjects.insert(aMainListFeature);
1681 #ifdef DEBUG_CLEAN_HISTORY
1683 for (aFIt = anUnusedObjects.begin(); aFIt != anUnusedObjects.end(); ++aFIt) {
1684 FeaturePtr aFeature = *aFIt;
1685 anInfo.append(aFeature->name().c_str());
1687 qDebug(QString("unused objects: [%1] - %2").
1688 arg(anInfo.size()).arg(anInfo.join(";\t")).toStdString().c_str());
1691 // warn about the references remove, break the delete operation if the user chose it
1692 if (!anUnusedObjects.empty()) {
1694 foreach (const FeaturePtr& aFeature, anUnusedObjects) {
1695 aNames.append(aFeature->name().c_str());
1698 QString anUnusedNames = aNames.join(", ");
1700 QString anActionId = "CLEAN_HISTORY_CMD";
1701 QString aDescription = contextMenuMgr()->action(anActionId)->text();
1703 QMessageBox aMessageBox(desktop());
1704 aMessageBox.setWindowTitle(aDescription);
1705 aMessageBox.setIcon(QMessageBox::Warning);
1706 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
1707 aMessageBox.setDefaultButton(QMessageBox::No);
1709 const char* aKeyStr = "Unused features are the following: "
1710 "%1.\nThese features will be deleted.\nWould you like to continue?";
1711 QString aText = QString(tr(aKeyStr).arg(anUnusedNames));
1712 aMessageBox.setText(aText);
1713 if (aMessageBox.exec() == QMessageBox::No)
1716 // 1. start operation
1717 aDescription += "by deleting of " +
1718 aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
1719 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, module());
1720 operationMgr()->startOperation(anOpAction);
1722 // WORKAROUND, should be done before each object remove, if it presents in XGUI_DataModel tree
1723 // It is necessary to clear selection in order to avoid selection changed event during
1724 // deletion and negative consequences connected with processing of already deleted items
1725 mySelector->clearSelection();
1727 std::set<FeaturePtr> anIgnoredFeatures;
1728 if (ModelAPI_Tools::removeFeatures(anUnusedObjects, true)) {
1729 operationMgr()->commitOperation();
1732 operationMgr()->abortOperation(operationMgr()->currentOperation());
1736 QString anActionId = "CLEAN_HISTORY_CMD";
1737 QString aDescription = contextMenuMgr()->action(anActionId)->text();
1739 QMessageBox aMessageBox(desktop());
1740 aMessageBox.setWindowTitle(aDescription);
1741 aMessageBox.setIcon(QMessageBox::Warning);
1742 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
1743 aMessageBox.setDefaultButton(QMessageBox::No);
1746 aMessageBox.setStandardButtons(QMessageBox::Ok);
1747 aMessageBox.setDefaultButton(QMessageBox::Ok);
1749 aText = QString(tr("All features are relevant, there is nothing to be deleted"));
1750 aMessageBox.setText(aText);
1752 if (aMessageBox.exec() == QMessageBox::No)
1757 //**************************************************************
1758 void XGUI_Workshop::moveObjects()
1760 if (!abortAllOperations())
1763 SessionPtr aMgr = ModelAPI_Session::get();
1765 QString anActionId = "MOVE_CMD";
1766 QString aDescription = contextMenuMgr()->action(anActionId)->text();
1767 aMgr->startOperation(aDescription.toStdString());
1769 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1770 // It is necessary to clear selection in order to avoid selection changed event during
1771 // moving and negative consequences connected with processing of already moved items
1772 mySelector->clearSelection();
1773 // check whether the object can be moved. There should not be parts which are not loaded
1774 std::set<FeaturePtr> aFeatures;
1775 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1776 if (!XGUI_Tools::canRemoveOrRename(desktop(), aFeatures))
1779 DocumentPtr anActiveDocument = aMgr->activeDocument();
1780 FeaturePtr aCurrentFeature = anActiveDocument->currentFeature(true);
1781 std::set<FeaturePtr>::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
1782 for (; anIt != aLast; anIt++) {
1783 FeaturePtr aFeature = *anIt;
1784 if (!aFeature.get() || !myModule->canApplyAction(aFeature, anActionId))
1787 anActiveDocument->moveFeature(aFeature, aCurrentFeature);
1788 aCurrentFeature = anActiveDocument->currentFeature(true);
1790 aMgr->finishOperation();
1793 //**************************************************************
1794 bool XGUI_Workshop::deleteFeatures(const QObjectPtrList& theObjects)
1796 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1797 std::set<FeaturePtr> aFeatures;
1798 ModuleBase_Tools::convertToFeatures(theObjects, aFeatures);
1800 return ModelAPI_Tools::removeFeaturesAndReferences(aFeatures);
1803 bool hasResults(QObjectPtrList theObjects, const std::set<std::string>& theTypes)
1805 bool isFoundResultType = false;
1806 foreach(ObjectPtr anObj, theObjects)
1808 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
1809 if (aResult.get() == NULL)
1812 isFoundResultType = theTypes.find(aResult->groupName()) != theTypes.end();
1813 if (isFoundResultType)
1816 return isFoundResultType;
1819 //**************************************************************
1820 // Returns the list of all features for theDocument and all features of
1821 // all nested parts.
1822 std::list<FeaturePtr> allFeatures(const DocumentPtr& theDocument)
1824 std::list<FeaturePtr> aResultList;
1825 std::list<FeaturePtr> anAllFeatures = theDocument->allFeatures();
1826 foreach (const FeaturePtr& aFeature, anAllFeatures) {
1827 // The order of appending features of the part and the part itself is important
1829 // Append features from a part feature
1830 std::list<ResultPtr> aResults;
1831 ModelAPI_Tools::allResults(aFeature, aResults);
1832 foreach (const ResultPtr& aResult, aResults) {
1833 ResultPartPtr aResultPart =
1834 std::dynamic_pointer_cast<ModelAPI_ResultPart>(aResult);
1835 if (aResultPart.get() && aResultPart->partDoc().get()) {
1837 std::list<FeaturePtr> anAllFeatures = allFeatures(aResultPart->partDoc());
1838 aResultList.insert(aResultList.end(), anAllFeatures.begin(), anAllFeatures.end());
1842 aResultList.push_back(aFeature);
1847 //**************************************************************
1848 // Returns the list of features placed between theObject and the current feature
1849 // in the same document. Excludes theObject, includes the current feature.
1850 std::list<FeaturePtr> toCurrentFeatures(const ObjectPtr& theObject)
1852 std::list<FeaturePtr> aResult;
1853 DocumentPtr aDocument = theObject->document();
1854 std::list<FeaturePtr> anAllFeatures = allFeatures(aDocument);
1855 // find the object iterator
1856 std::list<FeaturePtr>::iterator aObjectIt =
1857 std::find(anAllFeatures.begin(), anAllFeatures.end(), theObject);
1858 if (aObjectIt == anAllFeatures.end())
1860 // find the current feature iterator
1861 std::list<FeaturePtr>::iterator aCurrentIt =
1862 std::find(anAllFeatures.begin(), anAllFeatures.end(), aDocument->currentFeature(true));
1863 if (aCurrentIt == anAllFeatures.end())
1865 // check the right order
1866 if (std::distance(aObjectIt, anAllFeatures.end()) <=
1867 std::distance(aCurrentIt, anAllFeatures.end()))
1869 // exclude the object
1870 std::advance(aObjectIt, 1);
1871 // include the current feature
1872 std::advance(aCurrentIt, 1);
1873 return std::list<FeaturePtr>(aObjectIt, aCurrentIt);
1876 bool XGUI_Workshop::canMoveFeature()
1878 QString anActionId = "MOVE_CMD";
1880 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1881 QObjectPtrList aValidatedObjects;
1882 foreach (ObjectPtr aObject, aObjects) {
1883 if (!myModule->canApplyAction(aObject, anActionId))
1885 // To be moved feature should be in active document
1886 if (aObject->document() != ModelAPI_Session::get()->activeDocument())
1888 aValidatedObjects.append(aObject);
1890 if (aValidatedObjects.size() != aObjects.size())
1891 aObjects = aValidatedObjects;
1893 bool aCanMove = !aObjects.empty();
1895 QObjectPtrList::const_iterator anIt = aObjects.begin(), aLast = aObjects.end();
1896 for (; anIt != aLast && aCanMove; anIt++) {
1897 ObjectPtr aObject = *anIt;
1898 // 1. Get features placed between selected and current in the document
1899 std::list<FeaturePtr> aFeaturesBetween = toCurrentFeatures(aObject);
1900 // if aFeaturesBetween is empty it means wrong order or aObject is the current feature
1901 if (aFeaturesBetween.empty())
1904 std::set<FeaturePtr> aPlacedFeatures(aFeaturesBetween.begin(), aFeaturesBetween.end());
1905 // 2. Get all reference features to the selected object in the document
1906 std::set<FeaturePtr> aRefFeatures;
1907 ModuleBase_Tools::refsToFeatureInFeatureDocument(aObject, aRefFeatures);
1909 if (aRefFeatures.empty())
1912 // 3. Find any placed features in all reference features
1913 std::set<FeaturePtr> aIntersectionFeatures;
1914 std::set_intersection(aRefFeatures.begin(), aRefFeatures.end(),
1915 aPlacedFeatures.begin(), aPlacedFeatures.end(),
1916 std::inserter(aIntersectionFeatures, aIntersectionFeatures.begin()));
1917 // 4. Return false if any reference feature is placed before current feature
1918 if (!aIntersectionFeatures.empty())
1926 //**************************************************************
1927 bool XGUI_Workshop::canBeShaded(const ObjectPtr& theObject) const
1929 bool aCanBeShaded = myDisplayer->canBeShaded(theObject);
1930 if (!aCanBeShaded) {
1931 ResultCompSolidPtr aCompsolidResult =
1932 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
1933 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
1934 for(int i = 0; i < aCompsolidResult->numberOfSubs() && !aCanBeShaded; i++)
1935 aCanBeShaded = myDisplayer->canBeShaded(aCompsolidResult->subResult(i));
1938 return aCanBeShaded;
1941 //**************************************************************
1942 bool XGUI_Workshop::canChangeProperty(const QString& theActionName) const
1944 if (theActionName == "COLOR_CMD" ||
1945 theActionName == "DEFLECTION_CMD"
1946 #ifdef USE_TRANSPARENCY
1947 || theActionName == "TRANSPARENCY_CMD"
1950 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1952 std::set<std::string> aTypes;
1953 aTypes.insert(ModelAPI_ResultGroup::group());
1954 aTypes.insert(ModelAPI_ResultConstruction::group());
1955 aTypes.insert(ModelAPI_ResultBody::group());
1956 aTypes.insert(ModelAPI_ResultPart::group());
1958 return hasResults(aObjects, aTypes);
1963 void setColor(ResultPtr theResult, const std::vector<int>& theColor)
1965 if (!theResult.get())
1968 AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
1969 if (aColorAttr.get() != NULL) {
1970 if (!aColorAttr->size()) {
1971 aColorAttr->setSize(3);
1973 aColorAttr->setValue(0, theColor[0]);
1974 aColorAttr->setValue(1, theColor[1]);
1975 aColorAttr->setValue(2, theColor[2]);
1979 //**************************************************************
1980 void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
1983 AttributeIntArrayPtr aColorAttr;
1984 // 1. find the current color of the object. This is a color of AIS presentation
1985 // The objects are iterated until a first valid color is found
1986 std::vector<int> aColor;
1987 foreach(ObjectPtr anObject, theObjects) {
1988 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1989 if (aResult.get()) {
1990 XGUI_CustomPrs::getResultColor(aResult, aColor);
1993 // TODO: remove the obtaining a color from the AIS object
1994 // this does not happen never because:
1995 // 1. The color can be changed only on results
1996 // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
1997 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
1998 if (anAISObj.get()) {
2000 anAISObj->getColor(aColor[0], aColor[1], aColor[2]);
2003 if (!aColor.empty())
2006 if (aColor.size() != 3)
2009 if (!abortAllOperations())
2011 // 2. show the dialog to change the value
2012 XGUI_ColorDialog* aDlg = new XGUI_ColorDialog(desktop());
2013 aDlg->setColor(aColor);
2014 aDlg->move(QCursor::pos());
2015 bool isDone = aDlg->exec() == QDialog::Accepted;
2019 bool isRandomColor = aDlg->isRandomColor();
2021 // 3. abort the previous operation and start a new one
2022 SessionPtr aMgr = ModelAPI_Session::get();
2023 QString aDescription = contextMenuMgr()->action("COLOR_CMD")->text();
2024 aMgr->startOperation(aDescription.toStdString());
2026 // 4. set the value to all results
2027 std::vector<int> aColorResult = aDlg->getColor();
2028 foreach(ObjectPtr anObj, theObjects) {
2029 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
2030 if (aResult.get() != NULL) {
2031 ResultCompSolidPtr aCompsolidResult =
2032 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
2033 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
2034 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
2035 setColor(aCompsolidResult->subResult(i), !isRandomColor ? aColorResult :
2036 aDlg->getRandomColor());
2039 setColor(aResult, !isRandomColor ? aColorResult : aDlg->getRandomColor());
2042 aMgr->finishOperation();
2043 updateCommandStatus();
2046 //**************************************************************
2047 void setDeflection(ResultPtr theResult, const double theDeflection)
2049 if (!theResult.get())
2052 AttributeDoublePtr aDeflectionAttr = theResult->data()->real(ModelAPI_Result::DEFLECTION_ID());
2053 if (aDeflectionAttr.get() != NULL)
2054 aDeflectionAttr->setValue(theDeflection);
2057 //**************************************************************
2058 void setTransparency(ResultPtr theResult, double theTransparency)
2060 if (!theResult.get())
2063 AttributeDoublePtr anAttribute = theResult->data()->real(ModelAPI_Result::TRANSPARENCY_ID());
2064 if (anAttribute.get() != NULL)
2065 anAttribute->setValue(theTransparency);
2068 //**************************************************************
2069 void setTransparency(double theTransparency, const QObjectPtrList& theObjects)
2071 foreach(ObjectPtr anObj, theObjects) {
2072 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
2073 if (aResult.get() != NULL) {
2074 ResultCompSolidPtr aCompsolidResult =
2075 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
2076 if (aCompsolidResult.get() != NULL) { // change property for all sub-solids
2077 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
2078 setTransparency(aCompsolidResult->subResult(i), theTransparency);
2081 setTransparency(aResult, theTransparency);
2086 //**************************************************************
2087 void XGUI_Workshop::changeDeflection(const QObjectPtrList& theObjects)
2089 AttributeDoublePtr aDoubleAttr;
2090 // 1. find the current property of the object. This is a property of AIS presentation
2091 // The objects are iterated until a first valid property is found
2092 double aDeflection = -1;
2093 foreach(ObjectPtr anObject, theObjects) {
2094 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
2095 if (aResult.get()) {
2096 aDeflection = XGUI_CustomPrs::getResultDeflection(aResult);
2099 // TODO: remove the obtaining a property from the AIS object
2100 // this does not happen never because:
2101 // 1. The property can be changed only on results
2102 // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
2103 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
2104 if (anAISObj.get()) {
2105 aDeflection = anAISObj->getDeflection();
2108 if (aDeflection > 0)
2111 if (aDeflection < 0)
2114 if (!abortAllOperations())
2116 // 2. show the dialog to change the value
2117 XGUI_DeflectionDialog* aDlg = new XGUI_DeflectionDialog(desktop());
2118 aDlg->setDeflection(aDeflection);
2119 aDlg->move(QCursor::pos());
2120 bool isDone = aDlg->exec() == QDialog::Accepted;
2124 // 3. abort the previous operation and start a new one
2125 SessionPtr aMgr = ModelAPI_Session::get();
2126 QString aDescription = contextMenuMgr()->action("DEFLECTION_CMD")->text();
2127 aMgr->startOperation(aDescription.toStdString());
2129 // 4. set the value to all results
2130 aDeflection = aDlg->getDeflection();
2131 foreach(ObjectPtr anObj, theObjects) {
2132 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
2133 if (aResult.get() != NULL) {
2134 ResultCompSolidPtr aCompsolidResult =
2135 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
2136 if (aCompsolidResult.get() != NULL) { // change property for all sub-solids
2137 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
2138 setDeflection(aCompsolidResult->subResult(i), aDeflection);
2141 setDeflection(aResult, aDeflection);
2144 aMgr->finishOperation();
2145 updateCommandStatus();
2148 //**************************************************************
2149 void XGUI_Workshop::changeTransparency(const QObjectPtrList& theObjects)
2151 AttributeDoublePtr aDoubleAttr;
2152 // 1. find the current property of the object. This is a property of AIS presentation
2153 // The objects are iterated until a first valid property is found
2154 double aCurrentValue = -1;
2155 foreach(ObjectPtr anObject, theObjects) {
2156 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
2157 if (aResult.get()) {
2158 aCurrentValue = XGUI_CustomPrs::getResultTransparency(aResult);
2161 // TODO: remove the obtaining a property from the AIS object
2162 // this does not happen never because:
2163 // 1. The property can be changed only on results
2164 // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
2165 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
2166 if (anAISObj.get()) {
2167 aCurrentValue = anAISObj->getDeflection();
2170 if (aCurrentValue > 0)
2173 if (aCurrentValue < 0)
2176 if (!abortAllOperations())
2179 // 2. show the dialog to change the value
2180 XGUI_PropertyDialog* aDlg = new XGUI_PropertyDialog(desktop());
2181 aDlg->setWindowTitle("Transparency");
2182 XGUI_TransparencyWidget* aTransparencyWidget = new XGUI_TransparencyWidget(aDlg);
2183 connect(aTransparencyWidget, SIGNAL(transparencyValueChanged()),
2184 this, SLOT(onTransparencyValueChanged()));
2185 connect(aTransparencyWidget, SIGNAL(previewStateChanged()),
2186 this, SLOT(onPreviewStateChanged()));
2187 aDlg->setContent(aTransparencyWidget);
2188 aTransparencyWidget->setValue(aCurrentValue);
2190 // 3. abort the previous operation and start a new one
2191 SessionPtr aMgr = ModelAPI_Session::get();
2192 QString aDescription = contextMenuMgr()->action("TRANSPARENCY_CMD")->text();
2193 aMgr->startOperation(aDescription.toStdString());
2195 aDlg->move(QCursor::pos());
2196 bool isDone = aDlg->exec() == QDialog::Accepted;
2200 // 4. set the value to all results
2201 aCurrentValue = aTransparencyWidget->getValue();
2202 setTransparency(aCurrentValue, theObjects);
2204 aMgr->finishOperation();
2205 updateCommandStatus();
2208 //**************************************************************
2209 void XGUI_Workshop::onTransparencyValueChanged()
2211 XGUI_TransparencyWidget* aTransparencyWidget = (XGUI_TransparencyWidget*)sender();
2212 if (!aTransparencyWidget || !aTransparencyWidget->isPreviewNeeded())
2215 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
2216 setTransparency(aTransparencyWidget->getValue(), anObjects);
2217 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2220 //**************************************************************
2221 void XGUI_Workshop::onPreviewStateChanged()
2223 XGUI_TransparencyWidget* aTransparencyWidget = (XGUI_TransparencyWidget*)sender();
2224 if (!aTransparencyWidget || !aTransparencyWidget->isPreviewNeeded())
2227 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
2228 setTransparency(aTransparencyWidget->getValue(), anObjects);
2229 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2232 //**************************************************************
2233 #define SET_DISPLAY_GROUP(aGroupName, aDisplay) \
2234 for (int i = 0; i < aDoc->size(aGroupName); i++) { \
2235 aDoc->object(aGroupName, i)->setDisplayed(aDisplay); \
2237 void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible)
2239 foreach (ObjectPtr aObj, theList) {
2240 aObj->setDisplayed(isVisible);
2242 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2244 // Necessary for update icons in ObjectBrowser on Linux
2245 QModelIndexList aIndexes = mySelector->selection()->selectedIndexes();
2246 foreach (QModelIndex aIdx, aIndexes) {
2247 if (aIdx.column() == 0) {
2248 myObjectBrowser->treeView()->update(aIdx);
2254 //**************************************************************
2255 void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList)
2257 // Hide all displayed objects
2258 QObjectPtrList aList = myDisplayer->displayedObjects();
2259 foreach (ObjectPtr aObj, aList) {
2260 if (module()->canEraseObject(aObj))
2261 aObj->setDisplayed(false);
2263 //Do not use eraseAll if you didn't send Redisplay event:
2264 //all objects are erased from viewer, but considered as displayed in displayer
2265 // Problem in bug 2218
2266 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2268 //issue #2159 Hide all incomplete behavior
2269 viewer()->eraseAll();
2272 // Show only objects from the list
2273 foreach (ObjectPtr aObj, theList) {
2274 aObj->setDisplayed(true);
2276 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2278 // Necessary for update icons in ObjectBrowser on Linux
2279 QModelIndexList aIndexes = mySelector->selection()->selectedIndexes();
2280 foreach (QModelIndex aIdx, aIndexes) {
2281 if (aIdx.column() == 0) {
2282 myObjectBrowser->treeView()->update(aIdx);
2289 //**************************************************************
2290 void XGUI_Workshop::registerValidators() const
2292 SessionPtr aMgr = ModelAPI_Session::get();
2293 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
2296 //**************************************************************
2297 void XGUI_Workshop::displayDocumentResults(DocumentPtr theDoc)
2301 displayGroupResults(theDoc, ModelAPI_ResultConstruction::group());
2302 displayGroupResults(theDoc, ModelAPI_ResultBody::group());
2305 //**************************************************************
2306 void XGUI_Workshop::displayGroupResults(DocumentPtr theDoc, std::string theGroup)
2308 for (int i = 0; i < theDoc->size(theGroup); i++)
2309 theDoc->object(theGroup, i)->setDisplayed(true);
2310 //displayObject(theDoc->object(theGroup, i));
2311 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2314 //**************************************************************
2315 void XGUI_Workshop::setDisplayMode(const QObjectPtrList& theList, int theMode)
2317 foreach(ObjectPtr aObj, theList) {
2318 myDisplayer->setDisplayMode(aObj, (XGUI_Displayer::DisplayMode)theMode, false);
2320 ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aObj);
2321 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
2322 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
2323 myDisplayer->setDisplayMode(aCompsolidResult->subResult(i),
2324 (XGUI_Displayer::DisplayMode)theMode, false);
2328 if (theList.size() > 0)
2329 myDisplayer->updateViewer();
2332 //**************************************************************
2333 void XGUI_Workshop::closeDocument()
2335 ModuleBase_Operation* anOperation = operationMgr()->currentOperation();
2336 while (anOperation) {
2337 anOperation->abort();
2338 anOperation = operationMgr()->currentOperation();
2340 //myDisplayer->closeLocalContexts();
2341 myDisplayer->eraseAll();
2342 objectBrowser()->clearContent();
2344 module()->closeDocument();
2345 // we need to clear viewer (with created filters) to do not have problems in 2nd SALOME study
2346 module()->clearViewer();
2349 // data model need not process the document's signals about objects modifications as
2350 // the document is closed
2351 //bool isBlocked = objectBrowser()->dataModel()->blockEventsProcessing(true);
2353 SessionPtr aMgr = ModelAPI_Session::get();
2356 //objectBrowser()->dataModel()->blockEventsProcessing(isBlocked);
2359 void XGUI_Workshop::addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot)
2361 XGUI_HistoryMenu* aMenu = NULL;
2362 if (isSalomeMode()) {
2363 QAction* anAction = qobject_cast<QAction*>(theObject);
2366 aMenu = new XGUI_HistoryMenu(anAction);
2368 QToolButton* aButton = qobject_cast<QToolButton*>(theObject);
2369 aMenu = new XGUI_HistoryMenu(aButton);
2371 connect(this, theSignal, aMenu, SLOT(setHistory(const QList<ActionInfo>&)));
2372 connect(aMenu, SIGNAL(actionSelected(int)), this, theSlot);
2375 QList<ActionInfo> XGUI_Workshop::processHistoryList(const std::list<std::string>& theList) const
2377 QList<ActionInfo> aResult;
2378 std::list<std::string>::const_iterator it = theList.cbegin();
2379 for (; it != theList.cend(); it++) {
2380 QString anId = QString::fromStdString(*it);
2381 bool isEditing = anId.endsWith(ModuleBase_OperationFeature::EditSuffix());
2383 anId.chop(ModuleBase_OperationFeature::EditSuffix().size());
2386 QAction* aContextMenuAct = myContextMenuMgr->actionByName(anId);
2387 if (aContextMenuAct) {
2388 anInfo.initFrom(aContextMenuAct);
2390 anInfo = myActionsMgr->actionInfoById(anId);
2393 anInfo.text = anInfo.text.prepend("Modify ");
2400 void XGUI_Workshop::setStatusBarMessage(const QString& theMessage)
2403 salomeConnector()->putInfo(theMessage, -1);
2405 myMainWindow->putInfo(theMessage, -1);
2409 void XGUI_Workshop::synchronizeViewer()
2411 SessionPtr aMgr = ModelAPI_Session::get();
2412 QList<DocumentPtr> aDocs;
2413 aDocs.append(aMgr->activeDocument());
2414 aDocs.append(aMgr->moduleDocument());
2416 foreach(DocumentPtr aDoc, aDocs) {
2417 synchronizeGroupInViewer(aDoc, ModelAPI_ResultConstruction::group(), false);
2418 synchronizeGroupInViewer(aDoc, ModelAPI_ResultBody::group(), false);
2419 synchronizeGroupInViewer(aDoc, ModelAPI_ResultPart::group(), false);
2420 synchronizeGroupInViewer(aDoc, ModelAPI_ResultGroup::group(), false);
2424 void XGUI_Workshop::synchronizeGroupInViewer(const DocumentPtr& theDoc,
2425 const std::string& theGroup,
2426 bool theUpdateViewer)
2429 int aSize = theDoc->size(theGroup);
2430 for (int i = 0; i < aSize; i++) {
2431 aObj = theDoc->object(theGroup, i);
2432 if (aObj->isDisplayed()) {
2433 // Hide the presentation with an empty shape. But isDisplayed state of the object should not
2434 // be changed to the object becomes visible when the shape becomes not empty
2435 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
2436 if (aRes.get() && (!aRes->shape().get() || aRes->shape()->isNull()))
2438 myDisplayer->display(aObj, false);
2441 if (theUpdateViewer)
2442 myDisplayer->updateViewer();
2445 void XGUI_Workshop::highlightResults(const QObjectPtrList& theObjects)
2447 FeaturePtr aFeature;
2448 QObjectPtrList aSelList = theObjects;
2449 bool aHasHidden = false;
2450 foreach(ObjectPtr aObj, theObjects) {
2451 aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
2452 if (aFeature.get()) {
2453 std::list<ResultPtr> aResults;
2454 ModelAPI_Tools::allResults(aFeature, aResults);
2455 std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aIt;
2456 for(aIt = aResults.cbegin(); aIt != aResults.cend(); aIt++) {
2457 aHasHidden |= (*aIt)->isConcealed();
2458 aSelList.append(*aIt);
2462 if (aSelList.count() > theObjects.count()) {
2463 // if something was found
2464 bool aBlocked = objectBrowser()->blockSignals(true);
2465 objectBrowser()->setObjectsSelected(aSelList);
2466 objectBrowser()->blockSignals(aBlocked);
2469 QMessageBox::information(desktop(), tr("Find results"),
2470 tr("Results not found"), QMessageBox::Ok);
2473 void XGUI_Workshop::highlightFeature(const QObjectPtrList& theObjects)
2476 QObjectPtrList aSelList = theObjects;
2477 FeaturePtr aFeature;
2478 foreach(ObjectPtr aObj, theObjects) {
2479 aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
2480 if (aResult.get()) {
2481 aFeature = ModelAPI_Feature::feature(aResult);
2482 if (aFeature.get()) {
2483 aSelList.append(aFeature);
2487 if (aSelList.count() > theObjects.count()) {
2488 // if something was found
2489 bool aBlocked = objectBrowser()->blockSignals(true);
2490 objectBrowser()->setObjectsSelected(aSelList);
2491 objectBrowser()->blockSignals(aBlocked);
2495 void XGUI_Workshop::insertFeatureFolder()
2497 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
2498 if (aObjects.isEmpty())
2500 ObjectPtr aObj = aObjects.first();
2501 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
2502 if (aFeature.get() == NULL)
2504 SessionPtr aMgr = ModelAPI_Session::get();
2505 DocumentPtr aDoc = aMgr->activeDocument();
2507 aMgr->startOperation();
2508 aDoc->addFolder(aFeature);
2509 aMgr->finishOperation();
2513 void XGUI_Workshop::insertToFolder(bool isBefore)
2515 std::list<FeaturePtr> aFeatures = mySelector->getSelectedFeatures();
2516 if (aFeatures.empty())
2519 SessionPtr aMgr = ModelAPI_Session::get();
2520 DocumentPtr aDoc = aMgr->activeDocument();
2522 FolderPtr aFolder = isBefore? aDoc->findFolderAbove(aFeatures):
2523 aDoc->findFolderBelow(aFeatures);
2527 aMgr->startOperation();
2528 aDoc->moveToFolder(aFeatures, aFolder);
2529 aMgr->finishOperation();
2532 void XGUI_Workshop::moveOutFolder(bool isBefore)
2534 std::list<FeaturePtr> aFeatures = mySelector->getSelectedFeatures();
2535 if (aFeatures.empty())
2538 SessionPtr aMgr = ModelAPI_Session::get();
2539 DocumentPtr aDoc = aMgr->activeDocument();
2541 aMgr->startOperation();
2542 aDoc->removeFromFolder(aFeatures, isBefore);
2543 aMgr->finishOperation();