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_ActiveControlMgr.h"
25 #include "XGUI_ActiveControlSelector.h"
26 #include "XGUI_MenuMgr.h"
27 #include "XGUI_ColorDialog.h"
28 #include "XGUI_DeflectionDialog.h"
29 #include "XGUI_TransparencyWidget.h"
30 #include "XGUI_ContextMenuMgr.h"
31 #include "XGUI_Displayer.h"
32 #include "XGUI_ErrorDialog.h"
33 #include "XGUI_ErrorMgr.h"
34 #include "XGUI_FacesPanel.h"
35 #include "XGUI_FacesPanelSelector.h"
36 #include "XGUI_ModuleConnector.h"
37 #include "XGUI_ObjectsBrowser.h"
38 #include "XGUI_OperationMgr.h"
39 #include "XGUI_PropertyPanel.h"
40 #include "XGUI_PropertyPanelSelector.h"
41 #include "XGUI_PropertyDialog.h"
42 #include "XGUI_SalomeConnector.h"
43 #include "XGUI_Selection.h"
44 #include "XGUI_SelectionMgr.h"
45 #include "XGUI_Tools.h"
46 #include "XGUI_ViewerProxy.h"
47 #include "XGUI_WorkshopListener.h"
48 #include <XGUI_CustomPrs.h>
49 #include <XGUI_HistoryMenu.h>
50 #include <XGUI_QtEvents.h>
51 #include <XGUI_DataModel.h>
54 #include <AppElements_Button.h>
55 #include <AppElements_Command.h>
56 #include <AppElements_MainMenu.h>
57 #include <AppElements_MainWindow.h>
58 #include <AppElements_MenuGroupPanel.h>
59 #include <AppElements_Viewer.h>
60 #include <AppElements_Workbench.h>
63 #include <Config_XMLReader.h>
65 #include <ModelAPI_AttributeDocRef.h>
66 #include <ModelAPI_AttributeIntArray.h>
67 #include <ModelAPI_AttributeDouble.h>
68 #include <ModelAPI_Data.h>
69 #include <ModelAPI_Events.h>
70 #include <ModelAPI_Feature.h>
71 #include <ModelAPI_Object.h>
72 #include <ModelAPI_ResultBody.h>
73 #include <ModelAPI_ResultCompSolid.h>
74 #include <ModelAPI_ResultConstruction.h>
75 #include <ModelAPI_ResultGroup.h>
76 #include <ModelAPI_ResultParameter.h>
77 #include <ModelAPI_ResultField.h>
78 #include <ModelAPI_Session.h>
79 #include <ModelAPI_Validator.h>
80 #include <ModelAPI_Tools.h>
82 //#include <PartSetPlugin_Part.h>
84 #include <Events_Loop.h>
85 #include <Events_InfoMessage.h>
86 #include <Events_LongOp.h>
88 #include <ModuleBase_IModule.h>
89 #include <ModuleBase_IViewer.h>
90 #include <ModuleBase_Operation.h>
91 #include <ModuleBase_OperationDescription.h>
92 #include <ModuleBase_PageBase.h>
93 #include <ModuleBase_Preferences.h>
94 #include <ModuleBase_SelectionValidator.h>
95 #include <ModuleBase_Tools.h>
96 #include <ModuleBase_WidgetFactory.h>
97 #include <ModuleBase_OperationFeature.h>
98 #include <ModuleBase_OperationAction.h>
99 #include <ModuleBase_PagedContainer.h>
100 #include <ModuleBase_WidgetValidated.h>
101 #include <ModuleBase_ModelWidget.h>
102 #include <ModuleBase_ResultPrs.h>
104 #include <Config_Common.h>
105 #include <Config_FeatureMessage.h>
106 #include <Config_ModuleReader.h>
107 #include <Config_PointerMessage.h>
108 #include <Config_PropManager.h>
109 #include <Config_DataModelReader.h>
110 #include <Config_Translator.h>
111 #include <Config_WidgetAPI.h>
112 #include <Config_Keywords.h>
114 #include <SUIT_ResourceMgr.h>
116 #include <AIS_Trihedron.hxx>
117 #ifdef BEFORE_TRIHEDRON_PATCH
118 #include <AIS_Point.hxx>
119 #include <AIS_Axis.hxx>
122 #include <QApplication>
123 #include <QFileDialog>
124 #include <QMessageBox>
125 #include <QMdiSubWindow>
126 #include <QMainWindow>
127 #include <QPushButton>
128 #include <QDockWidget>
133 #include <QToolButton>
135 #include <QDesktopWidget>
140 #include <CDF_Session.hxx>
141 #include <CDF_Application.hxx>
142 #include <inspector/TInspector_Communicator.hxx>
143 #include <inspector/VInspector_CallBack.hxx>
144 static TInspector_Communicator* MyTCommunicator;
145 static Handle(VInspector_CallBack) MyVCallBack;
160 //#define DEBUG_FACES_PANEL
161 //#define DEBUG_WITH_MESSAGE_REPORT
163 QString XGUI_Workshop::MOVE_TO_END_COMMAND = QObject::tr("Move to the end");
165 //#define DEBUG_DELETE
166 //#define DEBUG_FEATURE_NAME
167 //#define DEBUG_CLEAN_HISTORY
169 //******************************************************
170 XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
172 myCurrentDir(QString()),
174 mySalomeConnector(theConnector),
179 //myViewerSelMode(TopAbs_FACE)
181 mySelector = new XGUI_SelectionMgr(this);
182 myModuleConnector = new XGUI_ModuleConnector(this);
183 myOperationMgr = new XGUI_OperationMgr(this, 0);
184 ModuleBase_IWorkshop* aWorkshop = moduleConnector();
185 // Has to be defined first in order to get errors and messages from other components
186 myEventsListener = new XGUI_WorkshopListener(aWorkshop);
188 SUIT_ResourceMgr* aResMgr = ModuleBase_Preferences::resourceMgr();
190 myMainWindow = new AppElements_MainWindow();
192 bool aCloc = aResMgr->booleanValue("language", "locale", true);
194 QLocale::setDefault( QLocale::c() );
196 QLocale::setDefault( QLocale::system() );
198 QString aPath = Config_XMLReader::pluginConfigFile().c_str();
203 aLangs << "*_en.ts"; // load by default eng translations
204 QString aCurrLang = aResMgr->stringValue("language", "language", "en");
205 if(aCurrLang != "en") {
206 aLangs << "*_" + aCurrLang + ".ts"; // then replace with translated files
209 foreach(QString aLang, aLangs) {
210 QStringList aFilters;
212 QStringList aTsFiles = aDir.entryList(aFilters, QDir::Files);
213 foreach(QString aFileName, aTsFiles) {
214 Config_Translator::load(aFileName.toStdString());
218 myDataModelXMLReader = new Config_DataModelReader();
219 //myDataModelXMLReader->readAll();
221 myDisplayer = new XGUI_Displayer(this);
223 connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(updateCommandStatus()));
225 myActionsMgr = new XGUI_ActionsMgr(this);
226 myActiveControlMgr = new XGUI_ActiveControlMgr(myModuleConnector);
227 myMenuMgr = new XGUI_MenuMgr(this);
228 myErrorDlg = new XGUI_ErrorDialog(QApplication::desktop());
229 myContextMenuMgr = new XGUI_ContextMenuMgr(this);
230 connect(myContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), this,
231 SLOT(onContextMenuCommand(const QString&, bool)));
233 myViewerProxy = new XGUI_ViewerProxy(this);
234 //connect(myViewerProxy, SIGNAL(selectionChanged()),
235 // myActionsMgr, SLOT(updateOnViewSelection()));
237 myOperationMgr->setWorkshop(aWorkshop);
239 myErrorMgr = new XGUI_ErrorMgr(this, aWorkshop);
241 connect(myOperationMgr, SIGNAL(operationResumed(ModuleBase_Operation*)),
242 SLOT(onOperationResumed(ModuleBase_Operation*)));
243 connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
244 SLOT(onOperationStopped(ModuleBase_Operation*)));
245 connect(myOperationMgr, SIGNAL(operationCommitted(ModuleBase_Operation*)),
246 SLOT(onOperationCommitted(ModuleBase_Operation*)));
247 connect(myOperationMgr, SIGNAL(operationAborted(ModuleBase_Operation*)),
248 SLOT(onOperationAborted(ModuleBase_Operation*)));
251 connect(myMainWindow, SIGNAL(exitKeySequence()), SLOT(onExit()));
252 onTrihedronVisibilityChanged(true);
255 connect(myEventsListener, SIGNAL(errorOccurred(std::shared_ptr<Events_InfoMessage>)),
256 myErrorDlg, SLOT(addError(std::shared_ptr<Events_InfoMessage>)));
258 //Config_PropManager::registerProp("Visualization", "object_default_color", "Object color",
259 // Config_Prop::Color, "225,225,225");
261 Config_PropManager::registerProp("Visualization", "result_body_color", "Result color",
262 Config_Prop::Color, ModelAPI_ResultBody::DEFAULT_COLOR());
263 Config_PropManager::registerProp("Visualization", "result_group_color", "Group color",
264 Config_Prop::Color, ModelAPI_ResultGroup::DEFAULT_COLOR());
265 Config_PropManager::registerProp("Visualization", "result_construction_color",
266 "Construction color",
268 ModelAPI_ResultConstruction::DEFAULT_COLOR());
269 Config_PropManager::registerProp("Visualization", "result_part_color", "Part color",
270 Config_Prop::Color, ModelAPI_ResultPart::DEFAULT_COLOR());
271 Config_PropManager::registerProp("Visualization", "result_field_color", "Field color",
272 Config_Prop::Color, ModelAPI_ResultField::DEFAULT_COLOR());
274 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "face-selection", true))
275 myViewerSelMode.append(TopAbs_FACE);
276 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "edge-selection", true))
277 myViewerSelMode.append(TopAbs_EDGE);
278 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "vertex-selection", true))
279 myViewerSelMode.append(TopAbs_VERTEX);
280 //IMP: an attempt to use result selection with other selection modes
281 myViewerSelMode.append(ModuleBase_ResultPrs::Sel_Result);//TopAbs_VERTEX);
282 myViewerSelMode.append(TopAbs_COMPSOLID);
285 //******************************************************
286 XGUI_Workshop::~XGUI_Workshop(void)
289 #ifdef MISSED_TRANSLATION
290 // Save Missed translations
291 Config_Translator::saveMissedTranslations();
296 delete myDataModelXMLReader;
299 //******************************************************
300 void XGUI_Workshop::startApplication()
302 //Initialize event listening
303 myEventsListener->initializeEventListening();
305 myDataModelXMLReader->readAll();
308 Config_PropManager::registerProp("Plugins", "default_path", "Default Path",
309 Config_Prop::Directory, "");
311 std::string aDir = Config_XMLReader::resourcesConfigFile();
312 Config_PropManager::registerProp("Plugins", "import_initial_path", "Import initial directory",
313 Config_Prop::Directory, aDir);
316 Config_PropManager::registerProp("Plugins", "create_part_by_start", "Create Part by Start",
317 Config_Prop::Boolean, "false");
319 registerValidators();
321 // Calling of loadCustomProps before activating module is required
322 // by Config_PropManger to restore user-defined path to plugins
323 ModuleBase_Preferences::loadCustomProps();
327 myMainWindow->show();
328 updateCommandStatus();
333 myViewerProxy->connectViewProxy();
334 connect(myViewerProxy, SIGNAL(trihedronVisibilityChanged(bool)),
335 SLOT(onTrihedronVisibilityChanged(bool)));
337 emit applicationStarted();
340 bool aNewPart = Config_PropManager::boolean("Plugins", "create_part_by_start");
342 module()->launchOperation("Part", false); // PartSetPlugin_Part::ID()
347 //******************************************************
348 void XGUI_Workshop::activateModule()
350 myModule->activateSelectionFilters();
352 connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
353 myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
354 connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
355 myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
357 updateCommandStatus();
359 // TODO: get default selection mode
361 // activate visualized objects in the viewer
362 activateObjectsSelection(displayer()->displayedObjects());
363 myOperationMgr->activate();
366 //******************************************************
367 void XGUI_Workshop::deactivateModule()
369 myModule->deactivateSelectionFilters();
371 // remove internal displayer filter
372 displayer()->deactivateSelectionFilters();
374 disconnect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
375 myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
376 disconnect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
377 myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
379 XGUI_Displayer* aDisplayer = displayer();
380 QObjectPtrList aDisplayed = aDisplayer->displayedObjects();
381 aDisplayer->deactivateObjects(aDisplayed, true);
382 Handle(AIS_InteractiveContext) aContext = viewer()->AISContext();
383 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(aDisplayer->getTrihedron());
384 /// deactivate trihedron in selection modes
385 TColStd_ListOfInteger aTColModes;
386 aContext->ActivatedModes(aTrihedron, aTColModes);
387 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
388 for (; itr.More(); itr.Next() ) {
389 Standard_Integer aMode = itr.Value();
390 aContext->Deactivate(aTrihedron, aMode);
392 #ifdef BEFORE_TRIHEDRON_PATCH
393 /// Trihedron problem: objects stayed in the viewer, should be removed manually
394 /// otherwise in SALOME happens crash by HideAll in the viewer
395 aContext->Remove(aTrihedron->Position(), true);
396 aContext->Remove(aTrihedron->Axis(), true);
397 aContext->Remove(aTrihedron->XAxis(), true);
398 aContext->Remove(aTrihedron->YAxis(), true);
401 myOperationMgr->deactivate();
404 //******************************************************
405 void XGUI_Workshop::initMenu()
407 myContextMenuMgr->createActions();
410 // Create only Undo, Redo commands
411 QAction* aAction = salomeConnector()->addDesktopCommand("UNDO_CMD", tr("Undo"),
412 tr("Undo last command"),
413 QIcon(":pictures/undo.png"),
414 QKeySequence::Undo, false,
416 QString aToolBarTitle = tr( "INF_DESK_TOOLBAR_STANDARD" );
417 salomeConnector()->addActionInToolbar( aAction,aToolBarTitle );
419 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onUndo()));
420 addHistoryMenu(aAction, SIGNAL(updateUndoHistory(const QList<ActionInfo>&)), SLOT(onUndo(int)));
422 aAction = salomeConnector()->addDesktopCommand("REDO_CMD", tr("Redo"), tr("Redo last command"),
423 QIcon(":pictures/redo.png"), QKeySequence::Redo,
424 false, "MEN_DESK_EDIT");
425 salomeConnector()->addActionInToolbar( aAction, aToolBarTitle );
427 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo()));
428 addHistoryMenu(aAction, SIGNAL(updateRedoHistory(const QList<ActionInfo>&)), SLOT(onRedo(int)));
430 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
432 aAction = salomeConnector()->addDesktopCommand("SAVEAS_CMD", tr("Export native..."),
433 tr("Export the current document into a native file"),
434 QIcon(), QKeySequence(),
435 false, "MEN_DESK_FILE");
436 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onSaveAs()));
438 aAction = salomeConnector()->addDesktopCommand("OPEN_CMD", tr("Import native..."),
439 tr("Import native file"),
440 QIcon(), QKeySequence(),
441 false, "MEN_DESK_FILE");
442 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onOpen()));
443 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_FILE");
446 // File commands group
447 AppElements_MenuGroupPanel* aGroup = myMainWindow->menuObject()->generalPage();
449 AppElements_Command* aCommand;
451 aCommand = aGroup->addFeature("SAVE_CMD", tr("Save"), tr("Save the document"),
452 QIcon(":pictures/save.png"), QKeySequence::Save);
453 aCommand->connectTo(this, SLOT(onSave()));
454 //aCommand->disable();
456 aCommand = aGroup->addFeature("SAVEAS_CMD", tr("Save as..."), tr("Save the document into a file"),
457 QIcon(":pictures/save.png"), QKeySequence());
458 aCommand->connectTo(this, SLOT(onSaveAs()));
460 QString aUndoId = "UNDO_CMD";
461 aCommand = aGroup->addFeature(aUndoId, tr("Undo"), tr("Undo last command"),
462 QIcon(":pictures/undo.png"), QKeySequence::Undo);
463 aCommand->connectTo(this, SLOT(onUndo()));
464 AppElements_Button* aUndoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aUndoId));
465 addHistoryMenu(aUndoButton,
466 SIGNAL(updateUndoHistory(const QList<ActionInfo>&)),
469 QString aRedoId = "REDO_CMD";
470 aCommand = aGroup->addFeature(aRedoId, tr("Redo"), tr("Redo last command"),
471 QIcon(":pictures/redo.png"), QKeySequence::Redo);
472 aCommand->connectTo(this, SLOT(onRedo()));
473 AppElements_Button* aRedoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aRedoId));
474 addHistoryMenu(aRedoButton,
475 SIGNAL(updateRedoHistory(const QList<ActionInfo>&)),
478 aCommand = aGroup->addFeature("OPEN_CMD", tr("Open..."), tr("Open a new document"),
479 QIcon(":pictures/open.png"), QKeySequence::Open);
480 aCommand->connectTo(this, SLOT(onOpen()));
482 aCommand = aGroup->addFeature("PREF_CMD", tr("Preferences"), tr("Edit preferences"),
483 QIcon(":pictures/preferences.png"), QKeySequence::Preferences);
484 aCommand->connectTo(this, SLOT(onPreferences()));
486 aCommand = aGroup->addFeature("EXIT_CMD", tr("Exit"), tr("Exit application"),
487 QIcon(":pictures/close.png"), QKeySequence::Close);
488 aCommand->connectTo(this, SLOT(onExit()));
493 //******************************************************
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 //******************************************************
580 void XGUI_Workshop::fillPropertyPanel(ModuleBase_Operation* theOperation)
582 ModuleBase_OperationFeature* aFOperation =
583 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
587 showPanel(myPropertyPanel);
588 myPropertyPanel->cleanContent();
590 QList<ModuleBase_ModelWidget*> aWidgets;
591 if (!module()->createWidgets(theOperation, aWidgets)) {
592 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
593 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), myModuleConnector);
594 aFactory.createWidget(myPropertyPanel->contentWidget());
595 aWidgets = aFactory.getModelWidgets();
598 // check compatibility of feature and widgets
599 FeaturePtr aFeature = aFOperation->feature();
600 std::string aFeatureKind = aFeature->getKind();
601 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
602 if (!aWidget->attributeID().empty() && !aFeature->attribute(aWidget->attributeID()).get()) {
603 std::string anErrorMsg = "The feature '%1' has no attribute '%2' used by widget '%3'.";
604 Events_InfoMessage("XGUI_Workshop", anErrorMsg)
605 .arg(aFeatureKind).arg(aWidget->attributeID())
606 .arg(aWidget->metaObject()->className()).send();
607 myPropertyPanel->cleanContent();
611 // for performance purpose, flush should be done after all controls are filled
612 bool isUpdateFlushed = false;
613 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
614 bool isStoreValue = !aFOperation->isEditOperation() &&
615 !aWidget->getDefaultValue().empty() &&
616 !aWidget->isComputedDefault();
617 aWidget->setFeature(aFeature, isStoreValue, isUpdateFlushed);
619 aWidget->restoreValue();
620 aWidget->enableFocusProcessing();
622 // update visible state of Preview button
623 std::shared_ptr<Config_FeatureMessage> aFeatureInfo;
625 aFeatureInfo = mySalomeConnector->featureInfo(aFeatureKind.c_str());
627 AppElements_MainMenu* aMenuBar = mainWindow()->menuObject();
628 AppElements_Command* aCommand = aMenuBar->feature(aFeatureKind.c_str());
630 aFeatureInfo = aCommand->featureMessage();
632 bool anIsAutoPreview = true;
633 if (aFeatureInfo.get())
634 anIsAutoPreview = aFeatureInfo->isAutoPreview();
636 std::string aXmlCfg, aDescription;
637 module()->getXMLRepresentation(aFeatureKind, aXmlCfg, aDescription);
638 ModuleBase_WidgetFactory aFactory(aXmlCfg, moduleConnector());
639 anIsAutoPreview = aFactory.widgetAPI()->getBooleanAttribute(FEATURE_AUTO_PREVIEW, true);
642 if (!anIsAutoPreview) {
643 myPropertyPanel->findButton(PROP_PANEL_PREVIEW)->setVisible(true);
644 // send signal about preview should not be computed automatically, click on preview
645 // button should initiate it
646 std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
647 new Events_Message(Events_Loop::eventByName(EVENT_PREVIEW_BLOCKED)));
648 Events_Loop::loop()->send(aMsg);
650 // if update happens after preview is blocked, it does nothing when blocked
651 // it improves performance for valid objects on feature start
652 ModuleBase_Tools::flushUpdated(aFeature);
654 myPropertyPanel->setModelWidgets(aWidgets);
655 aFOperation->setPropertyPanel(myPropertyPanel);
657 myModule->propertyPanelDefined(theOperation);
659 #ifndef DEBUG_FEATURE_NAME
660 myPropertyPanel->setWindowTitle(theOperation->getDescription()->description());
662 std::string aFeatureName = aFeature->name();
663 myPropertyPanel->setWindowTitle(QString("%1: %2")
664 .arg(theOperation->getDescription()->description())
665 .arg(aFeatureName.c_str()));
668 myErrorMgr->setPropertyPanel(myPropertyPanel);
671 //******************************************************
672 void XGUI_Workshop::connectToPropertyPanel(const bool isToConnect)
674 XGUI_PropertyPanel* aPropertyPanel = propertyPanel();
675 if (aPropertyPanel) {
676 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
677 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
678 myModule->connectToPropertyPanel(aWidget, isToConnect);
680 connect(aWidget, SIGNAL(valueStateChanged(int)), this, SLOT(onWidgetStateChanged(int)));
681 connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
682 connect(aWidget, SIGNAL(objectUpdated()), this, SLOT(onWidgetObjectUpdated()));
685 disconnect(aWidget, SIGNAL(valueStateChanged(int)), this, SLOT(onWidgetStateChanged(int)));
686 disconnect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
687 disconnect(aWidget, SIGNAL(objectUpdated()), this, SLOT(onWidgetObjectUpdated()));
693 //******************************************************
694 void XGUI_Workshop::onOperationResumed(ModuleBase_Operation* theOperation)
696 setGrantedFeatures(theOperation);
698 if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
699 fillPropertyPanel(theOperation);
700 connectToPropertyPanel(true);
702 updateCommandStatus();
704 myModule->operationResumed(theOperation);
708 //******************************************************
709 void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
711 updateCommandStatus();
713 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
718 ModuleBase_ISelection* aSel = mySelector->selection();
719 QObjectPtrList aObj = aSel->selectedPresentations();
720 //!< No need for property panel
721 hidePanel(myPropertyPanel);
722 myPropertyPanel->cleanContent();
724 connectToPropertyPanel(false);
725 myModule->operationStopped(aFOperation);
727 // the deactivated objects of the current operation should be activated back.
728 // They were deactivated on operation start or an object redisplay
729 QObjectPtrList anObjects;
730 FeaturePtr aFeature = aFOperation->feature();
731 if (aFeature.get()) { // feature may be not created (plugin load fail)
732 if (myDisplayer->isVisible(aFeature) && !myDisplayer->isActive(aFeature))
733 anObjects.append(aFeature);
734 std::list<ResultPtr> aResults;
735 ModelAPI_Tools::allResults(aFeature, aResults);
736 std::list<ResultPtr>::const_iterator aIt;
737 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
738 ResultPtr anObject = *aIt;
739 if (myDisplayer->isVisible(anObject) && !myDisplayer->isActive(anObject)) {
740 anObjects.append(anObject);
744 activateObjectsSelection(anObjects);
747 //******************************************************
748 void XGUI_Workshop::onOperationCommitted(ModuleBase_Operation* theOperation)
750 myModule->operationCommitted(theOperation);
753 //******************************************************
754 void XGUI_Workshop::onOperationAborted(ModuleBase_Operation* theOperation)
756 myModule->operationAborted(theOperation);
759 //******************************************************
760 void XGUI_Workshop::setGrantedFeatures(ModuleBase_Operation* theOperation)
762 ModuleBase_OperationFeature* aFOperation =
763 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
767 QStringList aGrantedIds;
768 if (isSalomeMode()) {
769 const std::shared_ptr<Config_FeatureMessage>& anInfo =
770 mySalomeConnector->featureInfo(theOperation->id());
772 aGrantedIds = QString::fromStdString(anInfo->nestedFeatures())
773 .split(" ", QString::SkipEmptyParts);
776 aGrantedIds = myActionsMgr->nestedCommands(theOperation->id());
778 ModuleBase_IModule* aModule = module();
780 aModule->grantedOperationIds(theOperation, aGrantedIds);
782 aFOperation->setGrantedOperationIds(aGrantedIds);
785 //******************************************************
786 void XGUI_Workshop::saveDocument(const QString& theName, std::list<std::string>& theFileNames)
788 QApplication::restoreOverrideCursor();
789 SessionPtr aMgr = ModelAPI_Session::get();
791 std::list<DocumentPtr> aDocList = aMgr->allOpenedDocuments();
792 std::list<DocumentPtr>::const_iterator aIt;
793 for (aIt = aDocList.cbegin(); aIt != aDocList.cend(); aIt++) {
794 std::list<bool> aState = myObjectBrowser->getStateForDoc(*aIt);
795 (*aIt)->storeNodesState(aState);
798 aMgr->save(theName.toLatin1().constData(), theFileNames);
800 QApplication::restoreOverrideCursor();
803 //******************************************************
804 bool XGUI_Workshop::abortAllOperations()
806 return myOperationMgr->abortAllOperations();
809 //******************************************************
810 void XGUI_Workshop::operationStarted(ModuleBase_Operation* theOperation)
812 setGrantedFeatures(theOperation);
813 if (!theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
814 updateCommandStatus();
817 myModule->operationStarted(theOperation);
821 //******************************************************
822 void XGUI_Workshop::onOpen()
824 if(!abortAllOperations())
826 //save current file before close if modified
827 SessionPtr aSession = ModelAPI_Session::get();
828 if (aSession->isModified()) {
829 //TODO(sbh): re-launch the app?
830 int anAnswer = QMessageBox::question(
831 desktop(), tr("Save current file"),
832 tr("The document is modified, save before opening another?"),
833 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
834 if (anAnswer == QMessageBox::Save) {
836 } else if (anAnswer == QMessageBox::Cancel) {
842 //show file dialog, check if readable and open
843 QString aDirectory = QFileDialog::getExistingDirectory(desktop(), tr("Select directory"));
844 openDirectory(aDirectory);
847 //******************************************************
848 void XGUI_Workshop::openDirectory(const QString& theDirectory)
850 myCurrentDir = theDirectory;
851 if (myCurrentDir.isEmpty())
854 QFileInfo aFileInfo(myCurrentDir);
855 if (!aFileInfo.exists() || !aFileInfo.isReadable()) {
856 QMessageBox::critical(desktop(), tr("Warning"), tr("Unable to open the file."));
861 QApplication::setOverrideCursor(Qt::WaitCursor);
862 module()->closeDocument();
863 SessionPtr aSession = ModelAPI_Session::get();
864 aSession->closeAll();
865 aSession->load(myCurrentDir.toLatin1().constData());
866 myObjectBrowser->rebuildDataTree();
868 // Open first level of data tree
869 DocumentPtr aRootDoc = aSession->moduleDocument();
870 std::list<bool> aStates;
871 aRootDoc->restoreNodesState(aStates);
872 myObjectBrowser->setStateForDoc(aRootDoc, aStates);
874 updateCommandStatus();
876 myMainWindow->setCurrentDir(myCurrentDir, true);
880 bool aNewPart = Config_PropManager::boolean("Plugins", "create_part_by_start");
883 DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
884 int aSize = aRootDoc->size(ModelAPI_ResultPart::group());
886 ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), 0);
887 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
894 QApplication::restoreOverrideCursor();
897 //******************************************************
898 void XGUI_Workshop::onNew()
900 QApplication::setOverrideCursor(Qt::WaitCursor);
901 if (objectBrowser() == 0) {
903 mySelector->connectViewers();
905 myViewerProxy->connectToViewer();
908 myMainWindow->showPythonConsole();
909 QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
910 aWnd->showMaximized();
911 updateCommandStatus();
913 myContextMenuMgr->connectViewer();
914 QApplication::restoreOverrideCursor();
918 //******************************************************
919 void XGUI_Workshop::onExit()
921 SessionPtr aMgr = ModelAPI_Session::get();
922 if (aMgr->isModified()) {
923 int anAnswer = QMessageBox::question(
924 myMainWindow, tr("Save current file"), tr("The document is modified, save before exit?"),
925 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
926 if (anAnswer == QMessageBox::Save) {
927 bool saved = onSave();
931 } else if (anAnswer == QMessageBox::Cancel) {
938 //******************************************************
939 void XGUI_Workshop::onPreferences()
941 ModuleBase_Prefs aModif;
942 ModuleBase_Preferences::editPreferences(aModif);
943 if (aModif.size() > 0) {
945 foreach (ModuleBase_Pref aPref, aModif)
947 aSection = aPref.first;
948 if (aSection == ModuleBase_Preferences::VIEWER_SECTION) {
949 myMainWindow->viewer()->updateFromResources();
950 } else if (aSection == ModuleBase_Preferences::MENU_SECTION) {
951 myMainWindow->menuObject()->updateFromResources();
954 displayer()->redisplayObjects();
959 //******************************************************
960 void XGUI_Workshop::onTrihedronVisibilityChanged(bool theState)
962 XGUI_Displayer* aDisplayer = displayer();
964 aDisplayer->displayTrihedron(theState);
967 //******************************************************
968 bool XGUI_Workshop::onSave()
970 if(!myOperationMgr->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
972 if (myCurrentDir.isEmpty()) {
975 std::list<std::string> aFiles;
976 saveDocument(myCurrentDir, aFiles);
977 updateCommandStatus();
979 myMainWindow->setModifiedState(false);
984 //******************************************************
985 bool XGUI_Workshop::onSaveAs()
987 if(!myOperationMgr->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
989 QFileDialog dialog(desktop());
990 dialog.setWindowTitle(tr("Select directory to save files..."));
991 dialog.setFileMode(QFileDialog::Directory);
992 dialog.setFilter(QDir::AllDirs);
993 dialog.setOptions(QFileDialog::HideNameFilterDetails | QFileDialog::ShowDirsOnly);
994 dialog.setViewMode(QFileDialog::Detail);
996 if (!dialog.exec()) {
1000 QString aTempDir = dialog.selectedFiles().first();
1001 QDir aDir(aTempDir);
1002 if (aDir.exists() && !aDir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries).isEmpty()) {
1003 int answer = QMessageBox::question(
1005 // Title of the dialog which asks user if he wants to save study
1006 // in existing non-empty folder
1008 tr("The directory already contains some files, save anyway?"),
1009 QMessageBox::Save | QMessageBox::Cancel);
1010 if (answer == QMessageBox::Cancel) {
1014 myCurrentDir = aTempDir;
1016 myMainWindow->setCurrentDir(myCurrentDir, false);
1017 myMainWindow->setModifiedState(false);
1022 //******************************************************
1023 void XGUI_Workshop::onUndo(int theTimes)
1025 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1026 if (anActiveWidget && anActiveWidget->processAction(ActionUndo))
1029 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
1030 SessionPtr aMgr = ModelAPI_Session::get();
1031 std::list<std::string> aUndoList = aMgr->undoList();
1032 if (aMgr->isOperation()) {
1033 /// this is important for nested operations
1034 /// when sketch operation is active, this condition is false and
1035 /// the sketch operation is not aborted
1036 operationMgr()->onAbortOperation();
1038 std::list<std::string>::const_iterator aIt = aUndoList.cbegin();
1039 for (int i = 0; (i < theTimes) && (aIt != aUndoList.cend()); ++i, ++aIt) {
1041 if (QString((*aIt).c_str()) == MOVE_TO_END_COMMAND)
1042 myObjectBrowser->rebuildDataTree();
1045 operationMgr()->updateApplyOfOperations();
1046 updateCommandStatus();
1049 //******************************************************
1050 void XGUI_Workshop::onRedo(int theTimes)
1052 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1053 if (anActiveWidget && anActiveWidget->processAction(ActionRedo))
1056 // the viewer update should be blocked in order to avoid the features blinking. For the created
1057 // feature a results are created, the flush of the created signal caused the viewer redisplay for
1058 // each created result. After a redisplay signal is flushed. So, the viewer update is blocked
1059 // until redo of all possible objects happens
1060 bool isUpdateEnabled = myDisplayer->enableUpdateViewer(false);
1062 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
1063 SessionPtr aMgr = ModelAPI_Session::get();
1064 std::list<std::string> aRedoList = aMgr->redoList();
1065 if (aMgr->isOperation()) {
1066 /// this is important for nested operations
1067 /// when sketch operation is active, this condition is false and
1068 /// the sketch operation is not aborted
1069 operationMgr()->onAbortOperation();
1071 std::list<std::string>::const_iterator aIt = aRedoList.cbegin();
1072 for (int i = 0; (i < theTimes) && (aIt != aRedoList.cend()); ++i, ++aIt) {
1074 if (QString((*aIt).c_str()) == MOVE_TO_END_COMMAND)
1075 myObjectBrowser->rebuildDataTree();
1077 operationMgr()->updateApplyOfOperations();
1078 updateCommandStatus();
1080 // unblock the viewer update functionality and make update on purpose
1081 myDisplayer->enableUpdateViewer(isUpdateEnabled);
1082 myDisplayer->updateViewer();
1085 //******************************************************
1086 void XGUI_Workshop::onWidgetStateChanged(int thePreviousState)
1088 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1089 //ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
1090 //if (anOperation) {
1091 // ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1093 // anActiveWidget = aPanel->activeWidget();
1096 operationMgr()->onValidateOperation();
1098 myModule->widgetStateChanged(thePreviousState);
1101 //******************************************************
1102 void XGUI_Workshop::onValuesChanged()
1104 ModuleBase_ModelWidget* aSenderWidget = (ModuleBase_ModelWidget*)(sender());
1105 if (!aSenderWidget || aSenderWidget->canAcceptFocus())
1108 ModuleBase_ModelWidget* anActiveWidget = 0;
1109 ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
1111 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1113 anActiveWidget = aPanel->activeWidget();
1115 if (anActiveWidget) {
1116 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1118 if (aWidgetValidated)
1119 aWidgetValidated->clearValidatedCash();
1123 //******************************************************
1124 void XGUI_Workshop::onWidgetObjectUpdated()
1126 operationMgr()->onValidateOperation();
1129 //******************************************************
1130 ModuleBase_IModule* XGUI_Workshop::loadModule(const QString& theModule)
1132 QString libName = QString::fromStdString(library(theModule.toStdString()));
1133 if (libName.isEmpty()) {
1134 qWarning(qPrintable(tr("Information about module \"%1\" doesn't exist.").arg(theModule)));
1139 CREATE_FUNC crtInst = 0;
1142 HINSTANCE modLib = ::LoadLibrary((LPTSTR) qPrintable(libName));
1146 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
1147 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
1148 QString aMsg((char*) &lpMsgBuf);
1149 err = QString("Failed to load %1. %2").arg(libName).arg(aMsg);
1150 ::LocalFree(lpMsgBuf);
1152 crtInst = (CREATE_FUNC) ::GetProcAddress(modLib, CREATE_MODULE);
1156 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
1157 | FORMAT_MESSAGE_IGNORE_INSERTS,
1158 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
1159 QString aMsg((char*) &lpMsgBuf);
1160 err = QString("Failed to find %1 function. %2").arg( CREATE_MODULE).arg(aMsg);
1161 ::LocalFree(lpMsgBuf);
1165 void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY | RTLD_GLOBAL );
1167 err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
1169 crtInst = (CREATE_FUNC)dlsym( modLib, CREATE_MODULE );
1171 err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() );
1176 ModuleBase_IModule* aModule = crtInst ? crtInst(myModuleConnector) : 0;
1178 if (!err.isEmpty()) {
1180 Events_InfoMessage("XGUI_Workshop", err.toStdString()).send();
1182 qWarning(qPrintable(err));
1188 //******************************************************
1189 bool XGUI_Workshop::createModule()
1191 Config_ModuleReader aModuleReader;
1192 QString moduleName = QString::fromStdString(aModuleReader.getModuleName());
1193 myModule = loadModule(moduleName);
1197 //connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
1198 // myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
1199 //connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
1200 // myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
1202 myModule->createFeatures();
1204 salomeConnector()->createFeatureActions();
1206 //myActionsMgr->update();
1210 //******************************************************
1211 void XGUI_Workshop::updateCommandStatus()
1213 QList<QAction*> aCommands;
1215 aCommands = salomeConnector()->commandList();
1217 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
1218 foreach (AppElements_Command* aCmd, aMenuBar->features())
1219 aCommands.append(aCmd);
1221 SessionPtr aMgr = ModelAPI_Session::get();
1222 if (aMgr->hasModuleDocument()) {
1223 foreach(QAction* aCmd, aCommands) {
1224 QString aId = aCmd->data().toString();
1225 if (aId == "UNDO_CMD") {
1226 bool isActionEnabled = false;
1227 // if ultimate is true -> using result of operation only, or using OR combination
1228 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1229 if (anActiveWidget && anActiveWidget->canProcessAction(ActionUndo, isActionEnabled))
1230 aCmd->setEnabled(isActionEnabled);
1232 aCmd->setEnabled(myModule->canUndo());
1234 else if (aId == "REDO_CMD") {
1235 bool isActionEnabled = false;
1236 // if ultimate is true -> using result of operation only, or using OR combination
1237 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1238 if (anActiveWidget && anActiveWidget->canProcessAction(ActionRedo, isActionEnabled))
1239 aCmd->setEnabled(isActionEnabled);
1241 aCmd->setEnabled(myModule->canRedo());
1244 // Enable all commands
1245 aCmd->setEnabled(true);
1249 foreach(QAction* aCmd, aCommands) {
1250 QString aId = aCmd->data().toString();
1251 if (aId == "NEW_CMD")
1252 aCmd->setEnabled(true);
1253 else if (aId == "EXIT_CMD")
1254 aCmd->setEnabled(true);
1256 aCmd->setEnabled(false);
1259 myActionsMgr->updateCommandsStatus();
1260 emit commandStatusUpdated();
1263 //******************************************************
1264 void XGUI_Workshop::updateHistory()
1266 std::list<std::string> aUndoList = ModelAPI_Session::get()->undoList();
1267 QList<ActionInfo> aUndoRes = processHistoryList(aUndoList);
1268 emit updateUndoHistory(aUndoRes);
1270 std::list<std::string> aRedoList = ModelAPI_Session::get()->redoList();
1271 QList<ActionInfo> aRedoRes = processHistoryList(aRedoList);
1272 emit updateRedoHistory(aRedoRes);
1275 //******************************************************
1276 QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
1278 QDockWidget* aObjDock = new QDockWidget(theParent);
1279 aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea |
1280 Qt::RightDockWidgetArea |
1281 Qt::BottomDockWidgetArea);
1282 aObjDock->setWindowTitle(tr("Object browser"));
1283 aObjDock->setStyleSheet(
1284 "::title { position: relative; padding-left: 5px; text-align: left center }");
1285 myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock, this);
1286 myObjectBrowser->setXMLReader(myDataModelXMLReader);
1287 myModule->customizeObjectBrowser(myObjectBrowser);
1288 aObjDock->setWidget(myObjectBrowser);
1290 myContextMenuMgr->connectObjectBrowser();
1294 //******************************************************
1296 * Creates dock widgets, places them in corresponding area
1297 * and tabifies if necessary.
1299 void XGUI_Workshop::createDockWidgets()
1301 QMainWindow* aDesktop = desktop();
1302 QDockWidget* aObjDock = createObjectBrowser(aDesktop);
1303 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
1304 myPropertyPanel = new XGUI_PropertyPanel(aDesktop, myOperationMgr);
1305 myActiveControlMgr->addSelector(new XGUI_PropertyPanelSelector(myPropertyPanel));
1307 myPropertyPanel->setupActions(myActionsMgr);
1308 myPropertyPanel->setAllowedAreas(Qt::LeftDockWidgetArea |
1309 Qt::RightDockWidgetArea |
1310 Qt::BottomDockWidgetArea);
1311 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel);
1312 hidePanel(myPropertyPanel); ///<! Invisible by default
1314 myFacesPanel = new XGUI_FacesPanel(aDesktop, myModuleConnector);
1315 myActiveControlMgr->addSelector(new XGUI_FacesPanelSelector(myFacesPanel));
1316 myFacesPanel->setAllowedAreas(Qt::LeftDockWidgetArea |
1317 Qt::RightDockWidgetArea |
1318 Qt::BottomDockWidgetArea);
1319 connect(myFacesPanel, SIGNAL(closed()), myFacesPanel, SLOT(onClosed()));
1321 aDesktop->addDockWidget(
1323 Qt::RightDockWidgetArea,
1325 Qt::LeftDockWidgetArea,
1328 hidePanel(myFacesPanel); ///<! Invisible by default
1330 #ifdef DEBUG_FACES_PANEL
1331 aDesktop->addDockWidget(Qt::RightDockWidgetArea, myFacesPanel);
1332 showPanel(myFacesPanel);
1335 hideObjectBrowser();
1337 #ifdef DEBUG_FACES_PANEL
1340 aDesktop->tabifyDockWidget(myFacesPanel, aObjDock);
1344 aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
1345 myPropertyPanel->installEventFilter(myOperationMgr);
1347 QAction* aOkAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept);
1348 connect(aOkAct, SIGNAL(triggered()), this, SLOT(onAcceptActionClicked()));
1350 QAction* aCancelAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Abort);
1351 connect(aCancelAct, SIGNAL(triggered()), myOperationMgr, SLOT(onAbortOperation()));
1353 QAction* aPreviewAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Preview);
1354 connect(aPreviewAct, SIGNAL(triggered()), this, SLOT(onPreviewActionClicked()));
1356 connect(myPropertyPanel, SIGNAL(keyReleased(QObject*, QKeyEvent*)),
1357 myOperationMgr, SLOT(onKeyReleased(QObject*, QKeyEvent*)));
1358 connect(myPropertyPanel, SIGNAL(enterClicked(QObject*)),
1359 myOperationMgr, SLOT(onProcessEnter(QObject*)));
1362 //******************************************************
1363 void XGUI_Workshop::showPanel(QDockWidget* theDockWidget)
1365 if (theDockWidget == myPropertyPanel) {
1366 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1367 ///<! Restore ability to close panel from the window's menu
1368 aViewAct->setEnabled(true);
1370 theDockWidget->show();
1371 theDockWidget->raise();
1373 // The next code is necessary to made the property panel the active window
1374 // in order to operation manager could process key events of the panel.
1375 // otherwise they are ignored. It happens only if the same(activateWindow) is
1376 // not happened by property panel activation(e.g. resume operation of Sketch)
1377 ModuleBase_Tools::setFocus(theDockWidget, "XGUI_Workshop::showPanel()");
1380 //******************************************************
1381 void XGUI_Workshop::hidePanel(QDockWidget* theDockWidget)
1383 if (theDockWidget && theDockWidget == myPropertyPanel) {
1384 QAction* aViewAct = theDockWidget->toggleViewAction();
1385 ///<! Do not allow to show empty property panel
1386 aViewAct->setEnabled(false);
1388 theDockWidget->hide();
1390 // the property panel is active window of the desktop, when it is
1391 // hidden, it is undefined which window becomes active. By this reason
1392 // it is defined to perform the desktop as the active window.
1393 // in SALOME mode, workstack made the PyConsole the active window,
1394 // set the focus on it. As a result, shortcuts of the application, like
1395 // are processed by this console. For example Undo actions.
1396 // It is possible that this code is to be moved to SHAPER package
1397 QMainWindow* aDesktop = desktop();
1398 ModuleBase_Tools::setFocus(aDesktop, "XGUI_Workshop::hidePanel()");
1401 //******************************************************
1402 void XGUI_Workshop::showObjectBrowser()
1404 if (!isSalomeMode())
1405 myObjectBrowser->parentWidget()->show();
1408 //******************************************************
1409 void XGUI_Workshop::hideObjectBrowser()
1411 if (!isSalomeMode())
1412 myObjectBrowser->parentWidget()->hide();
1415 //******************************************************
1416 void XGUI_Workshop::salomeViewerSelectionChanged()
1418 emit salomeViewerSelection();
1421 //**************************************************************
1422 ModuleBase_IViewer* XGUI_Workshop::salomeViewer() const
1424 return mySalomeConnector->viewer();
1427 //**************************************************************
1428 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
1430 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1431 if (theId == "DELETE_CMD")
1433 else if (theId == "CLEAN_HISTORY_CMD")
1435 else if (theId == "MOVE_CMD")
1437 else if (theId == "COLOR_CMD")
1438 changeColor(aObjects);
1439 else if (theId == "DEFLECTION_CMD")
1440 changeDeflection(aObjects);
1441 #ifdef USE_TRANSPARENCY
1442 else if (theId == "TRANSPARENCY_CMD")
1443 changeTransparency(aObjects);
1445 else if (theId == "SHOW_CMD") {
1446 showObjects(aObjects, true);
1447 mySelector->updateSelectionBy(ModuleBase_ISelection::Browser);
1448 updateCommandStatus();
1450 else if (theId == "HIDE_CMD") {
1451 showObjects(aObjects, false);
1452 updateCommandStatus();
1454 else if (theId == "SHOW_ONLY_CMD") {
1455 showOnlyObjects(aObjects);
1456 mySelector->updateSelectionBy(ModuleBase_ISelection::Browser);
1457 updateCommandStatus();
1459 else if (theId == "SHADING_CMD")
1460 setDisplayMode(aObjects, XGUI_Displayer::Shading);
1461 else if (theId == "WIREFRAME_CMD")
1462 setDisplayMode(aObjects, XGUI_Displayer::Wireframe);
1463 else if (theId == "HIDEALL_CMD") {
1464 QObjectPtrList aList = myDisplayer->displayedObjects();
1465 foreach (ObjectPtr aObj, aList) {
1466 if (module()->canEraseObject(aObj))
1467 aObj->setDisplayed(false);
1469 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1471 //issue #2159 Hide all incomplete behavior
1472 viewer()->eraseAll();
1474 updateCommandStatus();
1476 // Necessary for update icons in ObjectBrowser on Linux
1477 QModelIndexList aIndexes = mySelector->selection()->selectedIndexes();
1478 foreach (QModelIndex aIdx, aIndexes) {
1479 if (aIdx.column() == 0) {
1480 myObjectBrowser->treeView()->update(aIdx);
1484 } else if (theId == "SELECT_VERTEX_CMD") {
1485 setViewerSelectionMode(TopAbs_VERTEX);
1486 } else if (theId == "SELECT_EDGE_CMD") {
1487 setViewerSelectionMode(TopAbs_EDGE);
1488 } else if (theId == "SELECT_FACE_CMD") {
1489 setViewerSelectionMode(TopAbs_FACE);
1490 } else if (theId == "INSERT_FOLDER_CMD") {
1491 insertFeatureFolder();
1492 } else if (theId == "ADD_TO_FOLDER_BEFORE_CMD") {
1493 insertToFolder(true);
1494 } else if (theId == "ADD_TO_FOLDER_AFTER_CMD") {
1495 insertToFolder(false);
1496 } else if (theId == "ADD_OUT_FOLDER_BEFORE_CMD") {
1497 moveOutFolder(true);
1498 } else if (theId == "ADD_OUT_FOLDER_AFTER_CMD") {
1499 moveOutFolder(false);
1500 } else if (theId == "SELECT_RESULT_CMD") {
1501 //setViewerSelectionMode(-1);
1502 //IMP: an attempt to use result selection with other selection modes
1503 setViewerSelectionMode(ModuleBase_ResultPrs::Sel_Result);
1504 setViewerSelectionMode(TopAbs_COMPSOLID);
1505 } else if (theId == "SHOW_RESULTS_CMD") {
1506 highlightResults(aObjects);
1507 } else if (theId == "SHOW_FEATURE_CMD") {
1508 highlightFeature(aObjects);
1511 else if (theId == "TINSPECTOR_VIEW") {
1512 Handle(CDF_Application) anApplication = CDF_Session::CurrentSession()->CurrentApplication();
1513 if (!anApplication.IsNull())
1515 if (!MyTCommunicator)
1517 MyTCommunicator = new TInspector_Communicator();
1519 NCollection_List<Handle(Standard_Transient)> aParameters;
1520 aParameters.Append(anApplication);
1521 Handle(AIS_InteractiveContext) aContext = viewer()->AISContext();
1522 if (!aContext.IsNull())
1523 aParameters.Append(aContext);
1525 #ifdef DEBUG_WITH_MESSAGE_REPORT
1526 Handle(Message_Report) aContextReport = aContext->GetReport();
1527 aContextReport->SetActive (Standard_True);
1528 aContextReport->SetLimit (1000);
1529 if (!aContextReport.IsNull())
1530 aParameters.Append(aContextReport);
1532 MyVCallBack = new VInspector_CallBack();
1533 myDisplayer->setCallBack(MyVCallBack);
1535 AppElements_Viewer* aViewer = mainWindow()->viewer();
1537 aViewer->setCallBack(MyVCallBack);
1539 aParameters.Append(MyVCallBack);
1541 MyTCommunicator->RegisterPlugin("TKDFBrowser");
1542 MyTCommunicator->RegisterPlugin("TKShapeView");
1543 MyTCommunicator->RegisterPlugin("TKVInspector");
1544 #ifdef DEBUG_WITH_MESSAGE_REPORT
1545 MyTCommunicator->RegisterPlugin("TKMessageView");
1547 MyTCommunicator->RegisterPlugin("SMBrowser"); // custom plugin to view ModelAPI
1548 //MyTCommunicator->RegisterPlugin("TKSMBrowser"); // custom plugin to view ModelAPI
1550 MyTCommunicator->Init(aParameters);
1551 MyTCommunicator->Activate("TKSMBrowser"); // to have button in TInspector
1552 #ifndef DEBUG_WITH_MESSAGE_REPORT
1553 MyTCommunicator->Activate("TKVInspector"); // to have filled callback by model
1555 MyTCommunicator->Activate("TKDFBrowser");
1557 #ifdef DEBUG_WITH_MESSAGE_REPORT
1558 MyTCommunicator->Activate("TKMessageView"); // temporary
1559 MyTCommunicator->Activate("TKVInspector"); // to have filled callback by model
1562 MyTCommunicator->SetVisible(true);
1568 //**************************************************************
1569 void XGUI_Workshop::setViewerSelectionMode(int theMode)
1571 XGUI_ActiveControlSelector* anActiveSelector = activeControlMgr()->activeSelector();
1572 if (anActiveSelector && anActiveSelector->getType() == XGUI_FacesPanelSelector::Type())
1573 facesPanel()->setActivePanel(false);
1576 myViewerSelMode.clear();
1578 if (myViewerSelMode.contains(theMode))
1579 myViewerSelMode.removeAll(theMode);
1581 myViewerSelMode.append(theMode);
1583 activateObjectsSelection(myDisplayer->displayedObjects());
1586 //**************************************************************
1587 void XGUI_Workshop::activateObjectsSelection(const QObjectPtrList& theList)
1590 module()->activeSelectionModes(aModes);
1591 if (aModes.isEmpty() && (myViewerSelMode.length() > 0))
1592 aModes.append(myViewerSelMode);
1593 myDisplayer->activateObjects(aModes, theList);
1596 //**************************************************************
1597 bool XGUI_Workshop::prepareForDisplay(const std::set<ObjectPtr>& theObjects) const
1599 // generate container of objects taking into account sub elments of compsolid
1600 std::set<ObjectPtr> anAllProcessedObjects;
1601 for (std::set<ObjectPtr>::const_iterator anObjectsIt = theObjects.begin();
1602 anObjectsIt != theObjects.end(); anObjectsIt++) {
1603 ObjectPtr anObject = *anObjectsIt;
1604 ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(anObject);
1605 if (aCompRes.get()) {
1606 if (aCompRes->numberOfSubs(true) == 0)
1607 anAllProcessedObjects.insert(anObject);
1609 for (int i = 0; i < aCompRes->numberOfSubs(true); i++) {
1610 ResultPtr aSubRes = aCompRes->subResult(i, true);
1611 anAllProcessedObjects.insert(aCompRes->subResult(i, true));
1616 anAllProcessedObjects.insert(anObject);
1619 // find hidden objects in faces panel
1620 std::set<ObjectPtr> aHiddenObjects;
1621 QStringList aHiddenObjectNames;
1622 for (std::set<ObjectPtr>::const_iterator anObjectsIt = theObjects.begin();
1623 anObjectsIt != theObjects.end(); anObjectsIt++) {
1624 if (!facesPanel()->isObjectHiddenByPanel(*anObjectsIt))
1626 aHiddenObjects.insert(*anObjectsIt);
1627 aHiddenObjectNames.append((*anObjectsIt)->data()->name().c_str());
1629 if (aHiddenObjects.empty())
1632 int anAnswer = QMessageBox::question(
1633 desktop(), tr("Show object"),
1634 tr("'%1'\n are hidden by %2:\nRemove objects from the panel to be displayed?")
1635 .arg(aHiddenObjectNames.join(',').arg(facesPanel()->windowTitle()),
1636 QMessageBox::Yes | QMessageBox::No, QMessageBox::No));
1638 bool aToBeDisplayed = anAnswer == QMessageBox::Yes;
1640 facesPanel()->restoreObjects(aHiddenObjects);
1642 return aToBeDisplayed;
1645 //**************************************************************
1646 void XGUI_Workshop::deleteObjects()
1648 ModuleBase_IModule* aModule = module();
1649 // allow the module to delete objects, do nothing if it has succeed
1650 if (aModule->deleteObjects()) {
1651 updateCommandStatus();
1655 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1656 if (!abortAllOperations())
1659 bool hasResult = false;
1660 bool hasFeature = false;
1661 bool hasParameter = false;
1662 bool hasCompositeOwner = false;
1663 bool hasResultInHistory = false;
1664 bool hasFolder = false;
1665 ModuleBase_Tools::checkObjects(anObjects, hasResult, hasFeature, hasParameter, hasCompositeOwner,
1666 hasResultInHistory, hasFolder);
1667 if (!(hasFeature || hasParameter || hasFolder))
1671 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1672 std::set<FeaturePtr> aFeatures;
1673 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1674 ModelAPI_Tools::findAllReferences(aFeatures, aReferences);
1676 std::set<FolderPtr> aFolders;
1677 ModuleBase_Tools::convertToFolders(anObjects, aFolders);
1680 QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text() + " %1";
1681 aDescription = aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
1682 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, module());
1684 operationMgr()->startOperation(anOpAction);
1686 std::set<FeaturePtr> aFeatureRefsToDelete;
1687 if (ModuleBase_Tools::askToDelete(aFeatures, aReferences, desktop(), aFeatureRefsToDelete)) {
1688 // WORKAROUND, should be done before each object remove, if it presents in XGUI_DataModel tree
1689 // It is necessary to clear selection in order to avoid selection changed event during
1690 // deletion and negative consequences connected with processing of already deleted items
1691 mySelector->clearSelection();
1693 if (!aFeatureRefsToDelete.empty())
1694 aFeatures.insert(aFeatureRefsToDelete.begin(), aFeatureRefsToDelete.end());
1695 aDone = ModelAPI_Tools::removeFeatures(aFeatures, false);
1697 if (aFolders.size() > 0) {
1698 std::set<FolderPtr>::const_iterator anIt = aFolders.begin(),
1699 aLast = aFolders.end();
1700 for (; anIt != aLast; anIt++) {
1701 FolderPtr aFolder = *anIt;
1702 if (aFolder.get()) {
1703 DocumentPtr aDoc = aFolder->document();
1704 aDoc->removeFolder(aFolder);
1710 operationMgr()->commitOperation();
1712 operationMgr()->abortOperation(operationMgr()->currentOperation());
1715 //**************************************************************
1716 void addRefsToFeature(const FeaturePtr& theFeature,
1717 const std::map<FeaturePtr, std::set<FeaturePtr> >& theMainList,
1718 std::set<FeaturePtr>& theReferences)
1720 //if (theReferences.find(theFeature) != theReferences.end())
1722 if (theMainList.find(theFeature) == theMainList.end())
1723 return; // this feature is not in the selection list, so exists without references to it
1724 std::set<FeaturePtr> aMainReferences = theMainList.at(theFeature);
1726 std::set<FeaturePtr>::const_iterator anIt = aMainReferences.begin(),
1727 aLast = aMainReferences.end();
1728 for (; anIt != aLast; anIt++) {
1729 FeaturePtr aRefFeature = *anIt;
1730 if (theReferences.find(aRefFeature) == theReferences.end())
1731 theReferences.insert(aRefFeature);
1732 addRefsToFeature(aRefFeature, theMainList, theReferences);
1736 //**************************************************************
1737 void XGUI_Workshop::cleanHistory()
1739 if (!abortAllOperations())
1742 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1743 std::set<FeaturePtr> aFeatures;
1744 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1746 #ifdef DEBUG_CLEAN_HISTORY
1748 std::set<FeaturePtr>::const_iterator aFIt;
1749 for (aFIt = aFeatures.begin(); aFIt != aFeatures.end(); ++aFIt) {
1750 FeaturePtr aFeature = ModelAPI_Feature::feature(*aFIt);
1751 anInfo.append(aFeature->name().c_str());
1753 QString anInfoStr = anInfo.join(";\t");
1754 qDebug(QString("cleanHistory for: [%1] - %2").
1755 arg(aFeatures.size()).arg(anInfoStr).toStdString().c_str());
1758 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1759 ModelAPI_Tools::findAllReferences(aFeatures, aReferences, true, false);
1760 // find for each object whether all reference values are in the map as key, that means that there
1761 // is no other reference in the model to this object, so it might be removed by cleaning history
1762 // sk_1(ext_1, vertex_1) + (sk_3, bool_1) - cann't be deleted, dependency to bool_1
1763 // ext_1(bool_1, sk_3) - cann't be deleted, dependency to bool_1
1765 // sk_2(ext_2) + (bool_1) - cann't be deleted, dependency to bool_1
1766 // ext_2(bool_1) - cann't be deleted, dependency to bool_1
1768 // Information: bool_1 is not selected
1769 std::set<FeaturePtr> anUnusedObjects;
1770 std::map<FeaturePtr, std::set<FeaturePtr> >::const_iterator aMainIt = aReferences.begin(),
1771 aMainLast = aReferences.end();
1772 for (; aMainIt != aMainLast; aMainIt++) {
1773 FeaturePtr aMainListFeature = aMainIt->first;
1774 std::set<FeaturePtr> aMainRefList = aMainIt->second;
1775 std::set<FeaturePtr>::const_iterator aRefIt = aMainRefList.begin(),
1776 aRefLast = aMainRefList.end();
1777 bool aFeatureOutOfTheList = false;
1778 for (; aRefIt != aRefLast && !aFeatureOutOfTheList; aRefIt++) {
1779 FeaturePtr aRefFeature = *aRefIt;
1780 aFeatureOutOfTheList = aReferences.find(aRefFeature) == aReferences.end();
1782 if (!aFeatureOutOfTheList)
1783 anUnusedObjects.insert(aMainListFeature);
1786 #ifdef DEBUG_CLEAN_HISTORY
1788 for (aFIt = anUnusedObjects.begin(); aFIt != anUnusedObjects.end(); ++aFIt) {
1789 FeaturePtr aFeature = *aFIt;
1790 anInfo.append(aFeature->name().c_str());
1792 qDebug(QString("unused objects: [%1] - %2").
1793 arg(anInfo.size()).arg(anInfo.join(";\t")).toStdString().c_str());
1796 // warn about the references remove, break the delete operation if the user chose it
1797 if (!anUnusedObjects.empty()) {
1799 foreach (const FeaturePtr& aFeature, anUnusedObjects) {
1800 aNames.append(aFeature->name().c_str());
1803 QString anUnusedNames = aNames.join(", ");
1805 QString anActionId = "CLEAN_HISTORY_CMD";
1806 QString aDescription = contextMenuMgr()->action(anActionId)->text();
1808 QMessageBox aMessageBox(desktop());
1809 aMessageBox.setWindowTitle(aDescription);
1810 aMessageBox.setIcon(QMessageBox::Warning);
1811 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
1812 aMessageBox.setDefaultButton(QMessageBox::No);
1814 const char* aKeyStr = "Unused features are the following: "
1815 "%1.\nThese features will be deleted.\nWould you like to continue?";
1816 QString aText = QString(tr(aKeyStr).arg(anUnusedNames));
1817 aMessageBox.setText(aText);
1818 if (aMessageBox.exec() == QMessageBox::No)
1821 // 1. start operation
1822 aDescription += "by deleting of " +
1823 aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
1824 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, module());
1825 operationMgr()->startOperation(anOpAction);
1827 // WORKAROUND, should be done before each object remove, if it presents in XGUI_DataModel tree
1828 // It is necessary to clear selection in order to avoid selection changed event during
1829 // deletion and negative consequences connected with processing of already deleted items
1830 mySelector->clearSelection();
1832 std::set<FeaturePtr> anIgnoredFeatures;
1833 if (ModelAPI_Tools::removeFeatures(anUnusedObjects, true)) {
1834 operationMgr()->commitOperation();
1837 operationMgr()->abortOperation(operationMgr()->currentOperation());
1841 QString anActionId = "CLEAN_HISTORY_CMD";
1842 QString aDescription = contextMenuMgr()->action(anActionId)->text();
1844 QMessageBox aMessageBox(desktop());
1845 aMessageBox.setWindowTitle(aDescription);
1846 aMessageBox.setIcon(QMessageBox::Warning);
1847 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
1848 aMessageBox.setDefaultButton(QMessageBox::No);
1851 aMessageBox.setStandardButtons(QMessageBox::Ok);
1852 aMessageBox.setDefaultButton(QMessageBox::Ok);
1854 aText = QString(tr("All features are relevant, there is nothing to be deleted"));
1855 aMessageBox.setText(aText);
1857 if (aMessageBox.exec() == QMessageBox::No)
1862 //**************************************************************
1863 void XGUI_Workshop::moveObjects()
1865 if (!abortAllOperations())
1868 SessionPtr aMgr = ModelAPI_Session::get();
1870 QString anActionId = "MOVE_CMD";
1871 QString aDescription = contextMenuMgr()->action(anActionId)->text();
1872 aMgr->startOperation(aDescription.toStdString());
1874 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1875 // It is necessary to clear selection in order to avoid selection changed event during
1876 // moving and negative consequences connected with processing of already moved items
1877 mySelector->clearSelection();
1878 // check whether the object can be moved. There should not be parts which are not loaded
1879 std::set<FeaturePtr> aFeatures;
1880 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1881 if (!XGUI_Tools::canRemoveOrRename(desktop(), aFeatures))
1884 DocumentPtr anActiveDocument = aMgr->activeDocument();
1885 FeaturePtr aCurrentFeature = anActiveDocument->currentFeature(true);
1886 std::set<FeaturePtr>::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
1887 for (; anIt != aLast; anIt++) {
1888 FeaturePtr aFeature = *anIt;
1889 if (!aFeature.get() || !myModule->canApplyAction(aFeature, anActionId))
1892 anActiveDocument->moveFeature(aFeature, aCurrentFeature);
1893 aCurrentFeature = anActiveDocument->currentFeature(true);
1895 aMgr->finishOperation();
1898 //**************************************************************
1899 bool XGUI_Workshop::deleteFeatures(const QObjectPtrList& theObjects)
1901 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1902 std::set<FeaturePtr> aFeatures;
1903 ModuleBase_Tools::convertToFeatures(theObjects, aFeatures);
1905 return ModelAPI_Tools::removeFeaturesAndReferences(aFeatures);
1908 //******************************************************
1909 bool hasResults(QObjectPtrList theObjects, const std::set<std::string>& theTypes)
1911 bool isFoundResultType = false;
1912 foreach(ObjectPtr anObj, theObjects)
1914 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
1915 if (aResult.get() == NULL)
1918 isFoundResultType = theTypes.find(aResult->groupName()) != theTypes.end();
1919 if (isFoundResultType)
1922 return isFoundResultType;
1925 //**************************************************************
1926 // Returns the list of all features for theDocument and all features of
1927 // all nested parts.
1928 std::list<FeaturePtr> allFeatures(const DocumentPtr& theDocument)
1930 std::list<FeaturePtr> aResultList;
1931 std::list<FeaturePtr> anAllFeatures = theDocument->allFeatures();
1932 foreach (const FeaturePtr& aFeature, anAllFeatures) {
1933 // The order of appending features of the part and the part itself is important
1935 // Append features from a part feature
1936 std::list<ResultPtr> aResults;
1937 ModelAPI_Tools::allResults(aFeature, aResults);
1938 foreach (const ResultPtr& aResult, aResults) {
1939 ResultPartPtr aResultPart =
1940 std::dynamic_pointer_cast<ModelAPI_ResultPart>(aResult);
1941 if (aResultPart.get() && aResultPart->partDoc().get()) {
1943 std::list<FeaturePtr> anAllFeatures = allFeatures(aResultPart->partDoc());
1944 aResultList.insert(aResultList.end(), anAllFeatures.begin(), anAllFeatures.end());
1948 aResultList.push_back(aFeature);
1953 //**************************************************************
1954 // Returns the list of features placed between theObject and the current feature
1955 // in the same document. Excludes theObject, includes the current feature.
1956 std::list<FeaturePtr> toCurrentFeatures(const ObjectPtr& theObject)
1958 std::list<FeaturePtr> aResult;
1959 DocumentPtr aDocument = theObject->document();
1960 std::list<FeaturePtr> anAllFeatures = allFeatures(aDocument);
1961 // find the object iterator
1962 std::list<FeaturePtr>::iterator aObjectIt =
1963 std::find(anAllFeatures.begin(), anAllFeatures.end(), theObject);
1964 if (aObjectIt == anAllFeatures.end())
1966 // find the current feature iterator
1967 std::list<FeaturePtr>::iterator aCurrentIt =
1968 std::find(anAllFeatures.begin(), anAllFeatures.end(), aDocument->currentFeature(true));
1969 if (aCurrentIt == anAllFeatures.end())
1971 // check the right order
1972 if (std::distance(aObjectIt, anAllFeatures.end()) <=
1973 std::distance(aCurrentIt, anAllFeatures.end()))
1975 // exclude the object
1976 std::advance(aObjectIt, 1);
1977 // include the current feature
1978 std::advance(aCurrentIt, 1);
1979 return std::list<FeaturePtr>(aObjectIt, aCurrentIt);
1982 //******************************************************
1983 bool XGUI_Workshop::canMoveFeature()
1985 QString anActionId = "MOVE_CMD";
1987 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1988 QObjectPtrList aValidatedObjects;
1989 foreach (ObjectPtr aObject, aObjects) {
1990 if (!myModule->canApplyAction(aObject, anActionId))
1992 // To be moved feature should be in active document
1993 if (aObject->document() != ModelAPI_Session::get()->activeDocument())
1995 aValidatedObjects.append(aObject);
1997 if (aValidatedObjects.size() != aObjects.size())
1998 aObjects = aValidatedObjects;
2000 bool aCanMove = !aObjects.empty();
2002 QObjectPtrList::const_iterator anIt = aObjects.begin(), aLast = aObjects.end();
2003 for (; anIt != aLast && aCanMove; anIt++) {
2004 ObjectPtr aObject = *anIt;
2005 // 1. Get features placed between selected and current in the document
2006 std::list<FeaturePtr> aFeaturesBetween = toCurrentFeatures(aObject);
2007 // if aFeaturesBetween is empty it means wrong order or aObject is the current feature
2008 if (aFeaturesBetween.empty())
2011 std::set<FeaturePtr> aPlacedFeatures(aFeaturesBetween.begin(), aFeaturesBetween.end());
2012 // 2. Get all reference features to the selected object in the document
2013 std::set<FeaturePtr> aRefFeatures;
2014 ModuleBase_Tools::refsToFeatureInFeatureDocument(aObject, aRefFeatures);
2016 if (aRefFeatures.empty())
2019 // 3. Find any placed features in all reference features
2020 std::set<FeaturePtr> aIntersectionFeatures;
2021 std::set_intersection(aRefFeatures.begin(), aRefFeatures.end(),
2022 aPlacedFeatures.begin(), aPlacedFeatures.end(),
2023 std::inserter(aIntersectionFeatures, aIntersectionFeatures.begin()));
2024 // 4. Return false if any reference feature is placed before current feature
2025 if (!aIntersectionFeatures.empty())
2033 //**************************************************************
2034 bool XGUI_Workshop::canBeShaded(const ObjectPtr& theObject) const
2036 bool aCanBeShaded = myDisplayer->canBeShaded(theObject);
2037 if (!aCanBeShaded) {
2038 ResultCompSolidPtr aCompsolidResult =
2039 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
2040 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
2041 for(int i = 0; i < aCompsolidResult->numberOfSubs() && !aCanBeShaded; i++)
2042 aCanBeShaded = myDisplayer->canBeShaded(aCompsolidResult->subResult(i));
2045 return aCanBeShaded;
2048 //**************************************************************
2049 bool XGUI_Workshop::canChangeProperty(const QString& theActionName) const
2051 if (theActionName == "COLOR_CMD" ||
2052 theActionName == "DEFLECTION_CMD"
2053 #ifdef USE_TRANSPARENCY
2054 || theActionName == "TRANSPARENCY_CMD"
2057 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
2059 std::set<std::string> aTypes;
2060 aTypes.insert(ModelAPI_ResultGroup::group());
2061 aTypes.insert(ModelAPI_ResultConstruction::group());
2062 aTypes.insert(ModelAPI_ResultBody::group());
2063 aTypes.insert(ModelAPI_ResultPart::group());
2065 return hasResults(aObjects, aTypes);
2070 //******************************************************
2071 void setColor(ResultPtr theResult, const std::vector<int>& theColor)
2073 if (!theResult.get())
2076 AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
2077 if (aColorAttr.get() != NULL) {
2078 if (!aColorAttr->size()) {
2079 aColorAttr->setSize(3);
2081 aColorAttr->setValue(0, theColor[0]);
2082 aColorAttr->setValue(1, theColor[1]);
2083 aColorAttr->setValue(2, theColor[2]);
2087 //**************************************************************
2088 void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
2091 AttributeIntArrayPtr aColorAttr;
2092 // 1. find the current color of the object. This is a color of AIS presentation
2093 // The objects are iterated until a first valid color is found
2094 std::vector<int> aColor;
2095 foreach(ObjectPtr anObject, theObjects) {
2096 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
2097 if (aResult.get()) {
2098 XGUI_CustomPrs::getResultColor(aResult, aColor);
2101 // TODO: remove the obtaining a color from the AIS object
2102 // this does not happen never because:
2103 // 1. The color can be changed only on results
2104 // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
2105 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
2106 if (anAISObj.get()) {
2108 anAISObj->getColor(aColor[0], aColor[1], aColor[2]);
2111 if (!aColor.empty())
2114 if (aColor.size() != 3)
2117 if (!abortAllOperations())
2119 // 2. show the dialog to change the value
2120 XGUI_ColorDialog* aDlg = new XGUI_ColorDialog(desktop());
2121 aDlg->setColor(aColor);
2122 aDlg->move(QCursor::pos());
2123 bool isDone = aDlg->exec() == QDialog::Accepted;
2127 bool isRandomColor = aDlg->isRandomColor();
2129 // 3. abort the previous operation and start a new one
2130 SessionPtr aMgr = ModelAPI_Session::get();
2131 QString aDescription = contextMenuMgr()->action("COLOR_CMD")->text();
2132 aMgr->startOperation(aDescription.toStdString());
2134 // 4. set the value to all results
2135 std::vector<int> aColorResult = aDlg->getColor();
2136 foreach(ObjectPtr anObj, theObjects) {
2137 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
2138 if (aResult.get() != NULL) {
2139 ResultCompSolidPtr aCompsolidResult =
2140 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
2141 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
2142 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
2143 setColor(aCompsolidResult->subResult(i), !isRandomColor ? aColorResult :
2144 aDlg->getRandomColor());
2147 setColor(aResult, !isRandomColor ? aColorResult : aDlg->getRandomColor());
2150 aMgr->finishOperation();
2151 updateCommandStatus();
2154 //**************************************************************
2155 void setDeflection(ResultPtr theResult, const double theDeflection)
2157 if (!theResult.get())
2160 AttributeDoublePtr aDeflectionAttr = theResult->data()->real(ModelAPI_Result::DEFLECTION_ID());
2161 if (aDeflectionAttr.get() != NULL)
2162 aDeflectionAttr->setValue(theDeflection);
2165 //**************************************************************
2166 void setTransparency(ResultPtr theResult, double theTransparency)
2168 if (!theResult.get())
2171 AttributeDoublePtr anAttribute = theResult->data()->real(ModelAPI_Result::TRANSPARENCY_ID());
2172 if (anAttribute.get() != NULL)
2173 anAttribute->setValue(theTransparency);
2176 //**************************************************************
2177 void setTransparency(double theTransparency, const QObjectPtrList& theObjects)
2179 foreach(ObjectPtr anObj, theObjects) {
2180 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
2181 if (aResult.get() != NULL) {
2182 ResultCompSolidPtr aCompsolidResult =
2183 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
2184 if (aCompsolidResult.get() != NULL) { // change property for all sub-solids
2185 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
2186 setTransparency(aCompsolidResult->subResult(i), theTransparency);
2189 setTransparency(aResult, theTransparency);
2194 //**************************************************************
2195 void XGUI_Workshop::changeDeflection(const QObjectPtrList& theObjects)
2197 AttributeDoublePtr aDoubleAttr;
2198 // 1. find the current property of the object. This is a property of AIS presentation
2199 // The objects are iterated until a first valid property is found
2200 double aDeflection = -1;
2201 foreach(ObjectPtr anObject, theObjects) {
2202 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
2203 if (aResult.get()) {
2204 aDeflection = XGUI_CustomPrs::getResultDeflection(aResult);
2207 // TODO: remove the obtaining a property from the AIS object
2208 // this does not happen never because:
2209 // 1. The property can be changed only on results
2210 // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
2211 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
2212 if (anAISObj.get()) {
2213 aDeflection = anAISObj->getDeflection();
2216 if (aDeflection > 0)
2219 if (aDeflection < 0)
2222 if (!abortAllOperations())
2224 // 2. show the dialog to change the value
2225 XGUI_DeflectionDialog* aDlg = new XGUI_DeflectionDialog(desktop());
2226 aDlg->setDeflection(aDeflection);
2227 aDlg->move(QCursor::pos());
2228 bool isDone = aDlg->exec() == QDialog::Accepted;
2232 // 3. abort the previous operation and start a new one
2233 SessionPtr aMgr = ModelAPI_Session::get();
2234 QString aDescription = contextMenuMgr()->action("DEFLECTION_CMD")->text();
2235 aMgr->startOperation(aDescription.toStdString());
2237 // 4. set the value to all results
2238 aDeflection = aDlg->getDeflection();
2239 foreach(ObjectPtr anObj, theObjects) {
2240 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
2241 if (aResult.get() != NULL) {
2242 ResultCompSolidPtr aCompsolidResult =
2243 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
2244 if (aCompsolidResult.get() != NULL) { // change property for all sub-solids
2245 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
2246 setDeflection(aCompsolidResult->subResult(i), aDeflection);
2249 setDeflection(aResult, aDeflection);
2252 aMgr->finishOperation();
2253 updateCommandStatus();
2256 //**************************************************************
2257 void XGUI_Workshop::changeTransparency(const QObjectPtrList& theObjects)
2259 AttributeDoublePtr aDoubleAttr;
2260 // 1. find the current property of the object. This is a property of AIS presentation
2261 // The objects are iterated until a first valid property is found
2262 double aCurrentValue = -1;
2263 foreach(ObjectPtr anObject, theObjects) {
2264 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
2265 if (aResult.get()) {
2266 aCurrentValue = XGUI_CustomPrs::getResultTransparency(aResult);
2269 // TODO: remove the obtaining a property from the AIS object
2270 // this does not happen never because:
2271 // 1. The property can be changed only on results
2272 // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
2273 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
2274 if (anAISObj.get()) {
2275 aCurrentValue = anAISObj->getDeflection();
2278 if (aCurrentValue > 0)
2281 if (aCurrentValue < 0)
2284 if (!abortAllOperations())
2287 // 2. show the dialog to change the value
2288 XGUI_PropertyDialog* aDlg = new XGUI_PropertyDialog(desktop());
2289 aDlg->setWindowTitle("Transparency");
2290 XGUI_TransparencyWidget* aTransparencyWidget = new XGUI_TransparencyWidget(aDlg);
2291 connect(aTransparencyWidget, SIGNAL(transparencyValueChanged()),
2292 this, SLOT(onTransparencyValueChanged()));
2293 connect(aTransparencyWidget, SIGNAL(previewStateChanged()),
2294 this, SLOT(onPreviewStateChanged()));
2295 aDlg->setContent(aTransparencyWidget);
2296 aTransparencyWidget->setValue(aCurrentValue);
2298 // 3. abort the previous operation and start a new one
2299 SessionPtr aMgr = ModelAPI_Session::get();
2300 QString aDescription = contextMenuMgr()->action("TRANSPARENCY_CMD")->text();
2301 aMgr->startOperation(aDescription.toStdString());
2303 aDlg->move(QCursor::pos());
2304 bool isDone = aDlg->exec() == QDialog::Accepted;
2308 // 4. set the value to all results
2309 aCurrentValue = aTransparencyWidget->getValue();
2310 setTransparency(aCurrentValue, theObjects);
2312 aMgr->finishOperation();
2313 updateCommandStatus();
2316 //**************************************************************
2317 void XGUI_Workshop::onTransparencyValueChanged()
2319 XGUI_TransparencyWidget* aTransparencyWidget = (XGUI_TransparencyWidget*)sender();
2320 if (!aTransparencyWidget || !aTransparencyWidget->isPreviewNeeded())
2323 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
2324 setTransparency(aTransparencyWidget->getValue(), anObjects);
2325 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2328 //**************************************************************
2329 void XGUI_Workshop::onPreviewStateChanged()
2331 XGUI_TransparencyWidget* aTransparencyWidget = (XGUI_TransparencyWidget*)sender();
2332 if (!aTransparencyWidget || !aTransparencyWidget->isPreviewNeeded())
2335 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
2336 setTransparency(aTransparencyWidget->getValue(), anObjects);
2337 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2340 //**************************************************************
2341 #define SET_DISPLAY_GROUP(aGroupName, aDisplay) \
2342 for (int i = 0; i < aDoc->size(aGroupName); i++) { \
2343 aDoc->object(aGroupName, i)->setDisplayed(aDisplay); \
2346 //******************************************************
2347 void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible)
2350 std::set<ObjectPtr> anObjects;
2351 foreach (ObjectPtr aObj, theList) {
2352 anObjects.insert(aObj);
2354 if (!prepareForDisplay(anObjects))
2358 foreach (ObjectPtr aObj, theList) {
2359 aObj->setDisplayed(isVisible);
2361 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2363 // Necessary for update icons in ObjectBrowser on Linux
2364 QModelIndexList aIndexes = mySelector->selection()->selectedIndexes();
2365 foreach (QModelIndex aIdx, aIndexes) {
2366 if (aIdx.column() == 0) {
2367 myObjectBrowser->treeView()->update(aIdx);
2373 //**************************************************************
2374 void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList)
2376 // Hide all displayed objects
2377 QObjectPtrList aList = myDisplayer->displayedObjects();
2378 foreach (ObjectPtr aObj, aList) {
2379 if (module()->canEraseObject(aObj))
2380 aObj->setDisplayed(false);
2382 //Do not use eraseAll if you didn't send Redisplay event:
2383 //all objects are erased from viewer, but considered as displayed in displayer
2384 // Problem in bug 2218
2385 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2387 //issue #2159 Hide all incomplete behavior
2388 viewer()->eraseAll();
2391 std::set<ObjectPtr> anObjects;
2392 foreach (ObjectPtr aObj, theList) {
2393 anObjects.insert(aObj);
2396 if (!prepareForDisplay(anObjects))
2399 // Show only objects from the list
2400 foreach (ObjectPtr aObj, theList) {
2401 aObj->setDisplayed(true);
2403 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2405 // Necessary for update icons in ObjectBrowser on Linux
2406 QModelIndexList aIndexes = mySelector->selection()->selectedIndexes();
2407 foreach (QModelIndex aIdx, aIndexes) {
2408 if (aIdx.column() == 0) {
2409 myObjectBrowser->treeView()->update(aIdx);
2415 //**************************************************************
2416 void XGUI_Workshop::registerValidators() const
2418 SessionPtr aMgr = ModelAPI_Session::get();
2419 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
2422 //**************************************************************
2423 void XGUI_Workshop::displayDocumentResults(DocumentPtr theDoc)
2427 displayGroupResults(theDoc, ModelAPI_ResultConstruction::group());
2428 displayGroupResults(theDoc, ModelAPI_ResultBody::group());
2431 //**************************************************************
2432 void XGUI_Workshop::displayGroupResults(DocumentPtr theDoc, std::string theGroup)
2434 for (int i = 0; i < theDoc->size(theGroup); i++)
2435 theDoc->object(theGroup, i)->setDisplayed(true);
2436 //displayObject(theDoc->object(theGroup, i));
2437 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2440 //**************************************************************
2441 void XGUI_Workshop::setDisplayMode(const QObjectPtrList& theList, int theMode)
2443 foreach(ObjectPtr aObj, theList) {
2444 myDisplayer->setDisplayMode(aObj, (XGUI_Displayer::DisplayMode)theMode, false);
2446 ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aObj);
2447 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
2448 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
2449 myDisplayer->setDisplayMode(aCompsolidResult->subResult(i),
2450 (XGUI_Displayer::DisplayMode)theMode, false);
2454 if (theList.size() > 0)
2455 myDisplayer->updateViewer();
2458 //**************************************************************
2459 void XGUI_Workshop::closeDocument()
2461 ModuleBase_Operation* anOperation = operationMgr()->currentOperation();
2462 while (anOperation) {
2463 anOperation->abort();
2464 anOperation = operationMgr()->currentOperation();
2466 //myDisplayer->closeLocalContexts();
2467 myDisplayer->eraseAll();
2468 objectBrowser()->clearContent();
2470 module()->closeDocument();
2471 // we need to clear viewer (with created filters) to do not have problems in 2nd SALOME study
2472 module()->clearViewer();
2475 // data model need not process the document's signals about objects modifications as
2476 // the document is closed
2477 //bool isBlocked = objectBrowser()->dataModel()->blockEventsProcessing(true);
2479 SessionPtr aMgr = ModelAPI_Session::get();
2482 //objectBrowser()->dataModel()->blockEventsProcessing(isBlocked);
2485 //******************************************************
2486 void XGUI_Workshop::addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot)
2488 XGUI_HistoryMenu* aMenu = NULL;
2489 if (isSalomeMode()) {
2490 QAction* anAction = qobject_cast<QAction*>(theObject);
2493 aMenu = new XGUI_HistoryMenu(anAction);
2495 QToolButton* aButton = qobject_cast<QToolButton*>(theObject);
2496 aMenu = new XGUI_HistoryMenu(aButton);
2498 connect(this, theSignal, aMenu, SLOT(setHistory(const QList<ActionInfo>&)));
2499 connect(aMenu, SIGNAL(actionSelected(int)), this, theSlot);
2502 //******************************************************
2503 QList<ActionInfo> XGUI_Workshop::processHistoryList(const std::list<std::string>& theList) const
2505 QList<ActionInfo> aResult;
2506 std::list<std::string>::const_iterator it = theList.cbegin();
2507 for (; it != theList.cend(); it++) {
2508 QString anId = QString::fromStdString(*it);
2509 bool isEditing = anId.endsWith(ModuleBase_OperationFeature::EditSuffix());
2511 anId.chop(ModuleBase_OperationFeature::EditSuffix().size());
2514 QAction* aContextMenuAct = myContextMenuMgr->actionByName(anId);
2515 if (aContextMenuAct) {
2516 anInfo.initFrom(aContextMenuAct);
2518 anInfo = myActionsMgr->actionInfoById(anId);
2521 anInfo.text = anInfo.text.prepend("Modify ");
2528 //******************************************************
2529 void XGUI_Workshop::setStatusBarMessage(const QString& theMessage)
2532 salomeConnector()->putInfo(theMessage, -1);
2534 myMainWindow->putInfo(theMessage, -1);
2538 //******************************************************
2539 void XGUI_Workshop::synchronizeViewer()
2541 SessionPtr aMgr = ModelAPI_Session::get();
2542 QList<DocumentPtr> aDocs;
2543 aDocs.append(aMgr->activeDocument());
2544 aDocs.append(aMgr->moduleDocument());
2546 foreach(DocumentPtr aDoc, aDocs) {
2547 synchronizeGroupInViewer(aDoc, ModelAPI_ResultConstruction::group(), false);
2548 synchronizeGroupInViewer(aDoc, ModelAPI_ResultBody::group(), false);
2549 synchronizeGroupInViewer(aDoc, ModelAPI_ResultPart::group(), false);
2550 synchronizeGroupInViewer(aDoc, ModelAPI_ResultGroup::group(), false);
2554 //******************************************************
2555 void XGUI_Workshop::synchronizeGroupInViewer(const DocumentPtr& theDoc,
2556 const std::string& theGroup,
2557 bool theUpdateViewer)
2560 int aSize = theDoc->size(theGroup);
2561 for (int i = 0; i < aSize; i++) {
2562 aObj = theDoc->object(theGroup, i);
2563 if (aObj->isDisplayed()) {
2564 // Hide the presentation with an empty shape. But isDisplayed state of the object should not
2565 // be changed to the object becomes visible when the shape becomes not empty
2566 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
2567 if (aRes.get() && (!aRes->shape().get() || aRes->shape()->isNull()))
2569 myDisplayer->display(aObj, false);
2572 if (theUpdateViewer)
2573 myDisplayer->updateViewer();
2576 //******************************************************
2577 void XGUI_Workshop::highlightResults(const QObjectPtrList& theObjects)
2579 FeaturePtr aFeature;
2580 QObjectPtrList aSelList = theObjects;
2581 bool aHasHidden = false;
2582 foreach(ObjectPtr aObj, theObjects) {
2583 aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
2584 if (aFeature.get()) {
2585 std::list<ResultPtr> aResults;
2586 ModelAPI_Tools::allResults(aFeature, aResults);
2587 std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aIt;
2588 for(aIt = aResults.cbegin(); aIt != aResults.cend(); aIt++) {
2589 aHasHidden |= (*aIt)->isConcealed();
2590 aSelList.append(*aIt);
2594 if (aSelList.count() > theObjects.count()) {
2595 // if something was found
2596 bool aBlocked = objectBrowser()->blockSignals(true);
2597 objectBrowser()->setObjectsSelected(aSelList);
2598 objectBrowser()->blockSignals(aBlocked);
2601 QMessageBox::information(desktop(), tr("Find results"),
2602 tr("Results not found"), QMessageBox::Ok);
2605 //******************************************************
2606 void XGUI_Workshop::highlightFeature(const QObjectPtrList& theObjects)
2609 QObjectPtrList aSelList = theObjects;
2610 FeaturePtr aFeature;
2611 foreach(ObjectPtr aObj, theObjects) {
2612 aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
2613 if (aResult.get()) {
2614 aFeature = ModelAPI_Feature::feature(aResult);
2615 if (aFeature.get()) {
2616 aSelList.append(aFeature);
2620 if (aSelList.count() > theObjects.count()) {
2621 // if something was found
2622 bool aBlocked = objectBrowser()->blockSignals(true);
2623 objectBrowser()->setObjectsSelected(aSelList);
2624 objectBrowser()->blockSignals(aBlocked);
2628 void XGUI_Workshop::insertFeatureFolder()
2630 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
2631 if (aObjects.isEmpty())
2633 ObjectPtr aObj = aObjects.first();
2634 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
2635 if (aFeature.get() == NULL)
2637 SessionPtr aMgr = ModelAPI_Session::get();
2638 DocumentPtr aDoc = aMgr->activeDocument();
2640 aMgr->startOperation();
2641 aDoc->addFolder(aFeature);
2642 aMgr->finishOperation();
2646 void XGUI_Workshop::insertToFolder(bool isBefore)
2648 std::list<FeaturePtr> aFeatures = mySelector->getSelectedFeatures();
2649 if (aFeatures.empty())
2652 SessionPtr aMgr = ModelAPI_Session::get();
2653 DocumentPtr aDoc = aMgr->activeDocument();
2655 FolderPtr aFolder = isBefore? aDoc->findFolderAbove(aFeatures):
2656 aDoc->findFolderBelow(aFeatures);
2660 aMgr->startOperation();
2661 aDoc->moveToFolder(aFeatures, aFolder);
2662 aMgr->finishOperation();
2665 void XGUI_Workshop::moveOutFolder(bool isBefore)
2667 std::list<FeaturePtr> aFeatures = mySelector->getSelectedFeatures();
2668 if (aFeatures.empty())
2671 SessionPtr aMgr = ModelAPI_Session::get();
2672 DocumentPtr aDoc = aMgr->activeDocument();
2674 aMgr->startOperation();
2675 aDoc->removeFromFolder(aFeatures, isBefore);
2676 aMgr->finishOperation();