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_SelectionActivate.h"
45 #include "XGUI_SelectionMgr.h"
46 #include "XGUI_Tools.h"
47 #include "XGUI_ViewerProxy.h"
48 #include "XGUI_WorkshopListener.h"
49 #include <XGUI_CustomPrs.h>
50 #include <XGUI_HistoryMenu.h>
51 #include <XGUI_QtEvents.h>
52 #include <XGUI_DataModel.h>
55 #include <AppElements_Button.h>
56 #include <AppElements_Command.h>
57 #include <AppElements_MainMenu.h>
58 #include <AppElements_MainWindow.h>
59 #include <AppElements_MenuGroupPanel.h>
60 #include <AppElements_Viewer.h>
61 #include <AppElements_Workbench.h>
64 #include <Config_XMLReader.h>
66 #include <ModelAPI_AttributeDocRef.h>
67 #include <ModelAPI_AttributeIntArray.h>
68 #include <ModelAPI_AttributeDouble.h>
69 #include <ModelAPI_Data.h>
70 #include <ModelAPI_Events.h>
71 #include <ModelAPI_Feature.h>
72 #include <ModelAPI_Object.h>
73 #include <ModelAPI_ResultBody.h>
74 #include <ModelAPI_ResultCompSolid.h>
75 #include <ModelAPI_ResultConstruction.h>
76 #include <ModelAPI_ResultGroup.h>
77 #include <ModelAPI_ResultParameter.h>
78 #include <ModelAPI_ResultField.h>
79 #include <ModelAPI_Session.h>
80 #include <ModelAPI_Validator.h>
81 #include <ModelAPI_Tools.h>
83 //#include <PartSetPlugin_Part.h>
85 #include <Events_Loop.h>
86 #include <Events_InfoMessage.h>
87 #include <Events_LongOp.h>
89 #include <ModuleBase_IModule.h>
90 #include <ModuleBase_IViewer.h>
91 #include <ModuleBase_Operation.h>
92 #include <ModuleBase_OperationDescription.h>
93 #include <ModuleBase_PageBase.h>
94 #include <ModuleBase_Preferences.h>
95 #include <ModuleBase_SelectionValidator.h>
96 #include <ModuleBase_Tools.h>
97 #include <ModuleBase_WidgetFactory.h>
98 #include <ModuleBase_OperationFeature.h>
99 #include <ModuleBase_OperationAction.h>
100 #include <ModuleBase_PagedContainer.h>
101 #include <ModuleBase_WidgetValidated.h>
102 #include <ModuleBase_ModelWidget.h>
103 #include <ModuleBase_ResultPrs.h>
104 #include <ModuleBase_ActionIntParameter.h>
106 #include <Config_Common.h>
107 #include <Config_FeatureMessage.h>
108 #include <Config_ModuleReader.h>
109 #include <Config_PointerMessage.h>
110 #include <Config_PropManager.h>
111 #include <Config_DataModelReader.h>
112 #include <Config_Translator.h>
113 #include <Config_WidgetAPI.h>
114 #include <Config_Keywords.h>
116 #include <SUIT_ResourceMgr.h>
118 #include <AIS_Trihedron.hxx>
119 #ifdef BEFORE_TRIHEDRON_PATCH
120 #include <AIS_Point.hxx>
121 #include <AIS_Axis.hxx>
124 #include <QApplication>
125 #include <QFileDialog>
126 #include <QMessageBox>
127 #include <QMdiSubWindow>
128 #include <QMainWindow>
129 #include <QPushButton>
130 #include <QDockWidget>
135 #include <QToolButton>
137 #include <QDesktopWidget>
142 #include <CDF_Session.hxx>
143 #include <CDF_Application.hxx>
144 #include <inspector/TInspector_Communicator.hxx>
145 #include <inspector/VInspector_CallBack.hxx>
146 static TInspector_Communicator* MyTCommunicator;
147 static Handle(VInspector_CallBack) MyVCallBack;
162 //#define DEBUG_WITH_MESSAGE_REPORT
164 QString XGUI_Workshop::MOVE_TO_END_COMMAND = QObject::tr("Move to the end");
166 //#define DEBUG_DELETE
167 //#define DEBUG_FEATURE_NAME
168 //#define DEBUG_CLEAN_HISTORY
170 //******************************************************
171 XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
173 myCurrentDir(QString()),
175 mySalomeConnector(theConnector),
180 //myViewerSelMode(TopAbs_FACE)
182 mySelector = new XGUI_SelectionMgr(this);
183 myModuleConnector = new XGUI_ModuleConnector(this);
184 myOperationMgr = new XGUI_OperationMgr(this, 0);
185 ModuleBase_IWorkshop* aWorkshop = moduleConnector();
186 // Has to be defined first in order to get errors and messages from other components
187 myEventsListener = new XGUI_WorkshopListener(aWorkshop);
188 mySelectionActivate = new XGUI_SelectionActivate(aWorkshop);
190 SUIT_ResourceMgr* aResMgr = ModuleBase_Preferences::resourceMgr();
192 myMainWindow = new AppElements_MainWindow();
194 bool aCloc = aResMgr->booleanValue("language", "locale", true);
196 QLocale::setDefault( QLocale::c() );
198 QLocale::setDefault( QLocale::system() );
200 QString aPath = Config_XMLReader::pluginConfigFile().c_str();
205 aLangs << "*_en.ts"; // load by default eng translations
206 QString aCurrLang = aResMgr->stringValue("language", "language", "en");
207 if(aCurrLang != "en") {
208 aLangs << "*_" + aCurrLang + ".ts"; // then replace with translated files
211 foreach(QString aLang, aLangs) {
212 QStringList aFilters;
214 QStringList aTsFiles = aDir.entryList(aFilters, QDir::Files);
215 foreach(QString aFileName, aTsFiles) {
216 Config_Translator::load(aFileName.toStdString());
220 myDataModelXMLReader = new Config_DataModelReader();
221 //myDataModelXMLReader->readAll();
223 myDisplayer = new XGUI_Displayer(this);
225 connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(updateCommandStatus()));
227 myActionsMgr = new XGUI_ActionsMgr(this);
228 myActiveControlMgr = new XGUI_ActiveControlMgr(myModuleConnector);
229 myMenuMgr = new XGUI_MenuMgr(this);
230 myErrorDlg = new XGUI_ErrorDialog(QApplication::desktop());
231 myContextMenuMgr = new XGUI_ContextMenuMgr(this);
232 connect(myContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), this,
233 SLOT(onContextMenuCommand(const QString&, bool)));
235 myViewerProxy = new XGUI_ViewerProxy(this);
236 //connect(myViewerProxy, SIGNAL(selectionChanged()),
237 // myActionsMgr, SLOT(updateOnViewSelection()));
239 myOperationMgr->setWorkshop(aWorkshop);
241 myErrorMgr = new XGUI_ErrorMgr(this, aWorkshop);
243 connect(myOperationMgr, SIGNAL(operationResumed(ModuleBase_Operation*)),
244 SLOT(onOperationResumed(ModuleBase_Operation*)));
245 connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
246 SLOT(onOperationStopped(ModuleBase_Operation*)));
247 connect(myOperationMgr, SIGNAL(operationCommitted(ModuleBase_Operation*)),
248 SLOT(onOperationCommitted(ModuleBase_Operation*)));
249 connect(myOperationMgr, SIGNAL(operationAborted(ModuleBase_Operation*)),
250 SLOT(onOperationAborted(ModuleBase_Operation*)));
253 connect(myMainWindow, SIGNAL(exitKeySequence()), SLOT(onExit()));
254 onTrihedronVisibilityChanged(true);
257 connect(myEventsListener, SIGNAL(errorOccurred(std::shared_ptr<Events_InfoMessage>)),
258 myErrorDlg, SLOT(addError(std::shared_ptr<Events_InfoMessage>)));
260 //Config_PropManager::registerProp("Visualization", "object_default_color", "Object color",
261 // Config_Prop::Color, "225,225,225");
263 Config_PropManager::registerProp("Visualization", "result_body_color", "Result color",
264 Config_Prop::Color, ModelAPI_ResultBody::DEFAULT_COLOR());
265 Config_PropManager::registerProp("Visualization", "result_group_color", "Group color",
266 Config_Prop::Color, ModelAPI_ResultGroup::DEFAULT_COLOR());
267 Config_PropManager::registerProp("Visualization", "result_construction_color",
268 "Construction color",
270 ModelAPI_ResultConstruction::DEFAULT_COLOR());
271 Config_PropManager::registerProp("Visualization", "result_part_color", "Part color",
272 Config_Prop::Color, ModelAPI_ResultPart::DEFAULT_COLOR());
273 Config_PropManager::registerProp("Visualization", "result_field_color", "Field color",
274 Config_Prop::Color, ModelAPI_ResultField::DEFAULT_COLOR());
276 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "face-selection", true))
277 myViewerSelMode.append(TopAbs_FACE);
278 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "edge-selection", true))
279 myViewerSelMode.append(TopAbs_EDGE);
280 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "vertex-selection", true))
281 myViewerSelMode.append(TopAbs_VERTEX);
282 //IMP: an attempt to use result selection with other selection modes
283 myViewerSelMode.append(ModuleBase_ResultPrs::Sel_Result);//TopAbs_VERTEX);
284 myViewerSelMode.append(TopAbs_COMPSOLID);
287 //******************************************************
288 XGUI_Workshop::~XGUI_Workshop(void)
291 #ifdef MISSED_TRANSLATION
292 // Save Missed translations
293 Config_Translator::saveMissedTranslations();
298 delete myDataModelXMLReader;
301 //******************************************************
302 void XGUI_Workshop::startApplication()
304 //Initialize event listening
305 myEventsListener->initializeEventListening();
307 myDataModelXMLReader->readAll();
310 Config_PropManager::registerProp("Plugins", "default_path", "Default Path",
311 Config_Prop::Directory, "");
313 std::string aDir = Config_XMLReader::resourcesConfigFile();
314 Config_PropManager::registerProp("Plugins", "import_initial_path", "Import initial directory",
315 Config_Prop::Directory, aDir);
318 Config_PropManager::registerProp("Plugins", "create_part_by_start", "Create Part by Start",
319 Config_Prop::Boolean, "false");
321 Config_PropManager::registerProp("Plugins", "show_hide_faces", "Show Hide Faces (on the right)",
322 Config_Prop::Boolean, "false");
324 registerValidators();
326 // Calling of loadCustomProps before activating module is required
327 // by Config_PropManger to restore user-defined path to plugins
328 ModuleBase_Preferences::loadCustomProps();
332 myMainWindow->show();
333 updateCommandStatus();
338 myViewerProxy->connectViewProxy();
339 connect(myViewerProxy, SIGNAL(trihedronVisibilityChanged(bool)),
340 SLOT(onTrihedronVisibilityChanged(bool)));
342 emit applicationStarted();
345 bool aNewPart = Config_PropManager::boolean("Plugins", "create_part_by_start");
347 module()->launchOperation("Part", false); // PartSetPlugin_Part::ID()
352 //******************************************************
353 void XGUI_Workshop::activateModule()
355 selectionActivate()->updateSelectionFilters();
357 connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
358 myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
359 connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
360 myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
362 updateCommandStatus();
364 // TODO: get default selection mode
366 // activate visualized objects in the viewer
367 activateObjectsSelection(displayer()->displayedObjects());
368 myOperationMgr->activate();
371 //******************************************************
372 void XGUI_Workshop::deactivateModule()
374 // remove internal displayer filter
375 displayer()->deactivateSelectionFilters(false);
377 disconnect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
378 myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
379 disconnect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
380 myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
382 XGUI_Displayer* aDisplayer = displayer();
383 QObjectPtrList aDisplayed = aDisplayer->displayedObjects();
384 aDisplayer->deactivateObjects(aDisplayed, true);
385 selectionActivate()->deactivateTrihedronInSelectionModes();
387 #ifdef BEFORE_TRIHEDRON_PATCH
388 //Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(aDisplayer->getTrihedron());
389 /// Trihedron problem: objects stayed in the viewer, should be removed manually
390 /// otherwise in SALOME happens crash by HideAll in the viewer
391 aContext->Remove(aTrihedron->Position(), true);
392 aContext->Remove(aTrihedron->Axis(), true);
393 aContext->Remove(aTrihedron->XAxis(), true);
394 aContext->Remove(aTrihedron->YAxis(), true);
397 myOperationMgr->deactivate();
400 //******************************************************
401 void XGUI_Workshop::initMenu()
403 myContextMenuMgr->createActions();
406 // Create only Undo, Redo commands
407 QAction* aAction = salomeConnector()->addDesktopCommand("UNDO_CMD", tr("Undo"),
408 tr("Undo last command"),
409 QIcon(":pictures/undo.png"),
410 QKeySequence::Undo, false,
412 QString aToolBarTitle = tr( "INF_DESK_TOOLBAR_STANDARD" );
413 salomeConnector()->addActionInToolbar( aAction,aToolBarTitle );
415 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onUndo()));
416 addHistoryMenu(aAction, SIGNAL(updateUndoHistory(const QList<ActionInfo>&)), SLOT(onUndo(int)));
418 aAction = salomeConnector()->addDesktopCommand("REDO_CMD", tr("Redo"), tr("Redo last command"),
419 QIcon(":pictures/redo.png"), QKeySequence::Redo,
420 false, "MEN_DESK_EDIT");
421 salomeConnector()->addActionInToolbar( aAction, aToolBarTitle );
423 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo()));
424 addHistoryMenu(aAction, SIGNAL(updateRedoHistory(const QList<ActionInfo>&)), SLOT(onRedo(int)));
426 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
428 aAction = salomeConnector()->addDesktopCommand("SAVEAS_CMD", tr("Export native..."),
429 tr("Export the current document into a native file"),
430 QIcon(), QKeySequence(),
431 false, "MEN_DESK_FILE");
432 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onSaveAs()));
434 aAction = salomeConnector()->addDesktopCommand("OPEN_CMD", tr("Import native..."),
435 tr("Import native file"),
436 QIcon(), QKeySequence(),
437 false, "MEN_DESK_FILE");
438 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onOpen()));
439 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_FILE");
442 // File commands group
443 AppElements_MenuGroupPanel* aGroup = myMainWindow->menuObject()->generalPage();
445 AppElements_Command* aCommand;
447 aCommand = aGroup->addFeature("SAVE_CMD", tr("Save"), tr("Save the document"),
448 QIcon(":pictures/save.png"), QKeySequence::Save);
449 aCommand->connectTo(this, SLOT(onSave()));
450 //aCommand->disable();
452 aCommand = aGroup->addFeature("SAVEAS_CMD", tr("Save as..."), tr("Save the document into a file"),
453 QIcon(":pictures/save.png"), QKeySequence());
454 aCommand->connectTo(this, SLOT(onSaveAs()));
456 QString aUndoId = "UNDO_CMD";
457 aCommand = aGroup->addFeature(aUndoId, tr("Undo"), tr("Undo last command"),
458 QIcon(":pictures/undo.png"), QKeySequence::Undo);
459 aCommand->connectTo(this, SLOT(onUndo()));
460 AppElements_Button* aUndoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aUndoId));
461 addHistoryMenu(aUndoButton,
462 SIGNAL(updateUndoHistory(const QList<ActionInfo>&)),
465 QString aRedoId = "REDO_CMD";
466 aCommand = aGroup->addFeature(aRedoId, tr("Redo"), tr("Redo last command"),
467 QIcon(":pictures/redo.png"), QKeySequence::Redo);
468 aCommand->connectTo(this, SLOT(onRedo()));
469 AppElements_Button* aRedoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aRedoId));
470 addHistoryMenu(aRedoButton,
471 SIGNAL(updateRedoHistory(const QList<ActionInfo>&)),
474 aCommand = aGroup->addFeature("OPEN_CMD", tr("Open..."), tr("Open a new document"),
475 QIcon(":pictures/open.png"), QKeySequence::Open);
476 aCommand->connectTo(this, SLOT(onOpen()));
478 aCommand = aGroup->addFeature("PREF_CMD", tr("Preferences"), tr("Edit preferences"),
479 QIcon(":pictures/preferences.png"), QKeySequence::Preferences);
480 aCommand->connectTo(this, SLOT(onPreferences()));
482 aCommand = aGroup->addFeature("EXIT_CMD", tr("Exit"), tr("Exit application"),
483 QIcon(":pictures/close.png"), QKeySequence::Close);
484 aCommand->connectTo(this, SLOT(onExit()));
489 //******************************************************
490 AppElements_Workbench* XGUI_Workshop::addWorkbench(const QString& theName)
492 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
493 return aMenuBar->addWorkbench(theName);
497 //******************************************************
498 QMainWindow* XGUI_Workshop::desktop() const
501 return salomeConnector()->desktop();
507 //******************************************************
508 void XGUI_Workshop::onStartWaiting()
510 if (Events_LongOp::isPerformed()) {
511 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
515 //******************************************************
516 void XGUI_Workshop::onAcceptActionClicked()
518 QAction* anAction = dynamic_cast<QAction*>(sender());
519 XGUI_OperationMgr* anOperationMgr = operationMgr();
520 if (anOperationMgr) {
521 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
522 (anOperationMgr->currentOperation());
524 //if (errorMgr()->canProcessClick(anAction, aFOperation->feature()))
525 myOperationMgr->commitOperation();
530 //******************************************************
531 void XGUI_Workshop::onPreviewActionClicked()
533 ModuleBase_IPropertyPanel* aPanel = propertyPanel();
535 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
536 if (anActiveWidget && anActiveWidget->getValueState() == ModuleBase_ModelWidget::ModifiedInPP) {
537 anActiveWidget->storeValue();
540 std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
541 new Events_Message(Events_Loop::eventByName(EVENT_PREVIEW_REQUESTED)));
542 Events_Loop::loop()->send(aMsg);
545 //******************************************************
546 void XGUI_Workshop::deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer)
548 if (!myModule->canActivateSelection(theObject)) {
549 if (selectionActivate()->isActive(theObject)) {
550 QObjectPtrList anObjects;
551 anObjects.append(theObject);
552 myDisplayer->deactivateObjects(anObjects, theUpdateViewer);
557 //******************************************************
558 bool XGUI_Workshop::isFeatureOfNested(const FeaturePtr& theFeature)
560 bool aHasNested = false;
561 std::string aFeatureKind = theFeature->getKind();
563 XGUI_SalomeConnector* aSalomeConnector = salomeConnector();
564 if (aSalomeConnector->isFeatureOfNested(actionsMgr()->action(aFeatureKind.c_str())))
567 AppElements_MainMenu* aMenuBar = mainWindow()->menuObject();
568 AppElements_Command* aCommand = aMenuBar->feature(aFeatureKind.c_str());
569 if (aCommand && aCommand->button()->additionalButtonWidget())
575 //******************************************************
576 void XGUI_Workshop::fillPropertyPanel(ModuleBase_Operation* theOperation)
578 ModuleBase_OperationFeature* aFOperation =
579 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
583 showPanel(myPropertyPanel);
584 myPropertyPanel->cleanContent();
586 QList<ModuleBase_ModelWidget*> aWidgets;
587 if (!module()->createWidgets(theOperation, aWidgets)) {
588 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
589 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), myModuleConnector);
590 aFactory.createWidget(myPropertyPanel->contentWidget());
591 aWidgets = aFactory.getModelWidgets();
594 // check compatibility of feature and widgets
595 FeaturePtr aFeature = aFOperation->feature();
596 std::string aFeatureKind = aFeature->getKind();
597 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
598 if (!aWidget->attributeID().empty() && !aFeature->attribute(aWidget->attributeID()).get()) {
599 std::string anErrorMsg = "The feature '%1' has no attribute '%2' used by widget '%3'.";
600 Events_InfoMessage("XGUI_Workshop", anErrorMsg)
601 .arg(aFeatureKind).arg(aWidget->attributeID())
602 .arg(aWidget->metaObject()->className()).send();
603 myPropertyPanel->cleanContent();
607 // for performance purpose, flush should be done after all controls are filled
608 bool isUpdateFlushed = false;
609 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
610 bool isStoreValue = !aFOperation->isEditOperation() &&
611 !aWidget->getDefaultValue().empty() &&
612 !aWidget->isComputedDefault();
613 aWidget->setFeature(aFeature, isStoreValue, isUpdateFlushed);
615 aWidget->restoreValue();
616 aWidget->enableFocusProcessing();
618 // update visible state of Preview button
619 std::shared_ptr<Config_FeatureMessage> aFeatureInfo;
621 aFeatureInfo = mySalomeConnector->featureInfo(aFeatureKind.c_str());
623 AppElements_MainMenu* aMenuBar = mainWindow()->menuObject();
624 AppElements_Command* aCommand = aMenuBar->feature(aFeatureKind.c_str());
626 aFeatureInfo = aCommand->featureMessage();
628 bool anIsAutoPreview = true;
629 if (aFeatureInfo.get())
630 anIsAutoPreview = aFeatureInfo->isAutoPreview();
632 std::string aXmlCfg, aDescription;
633 module()->getXMLRepresentation(aFeatureKind, aXmlCfg, aDescription);
634 ModuleBase_WidgetFactory aFactory(aXmlCfg, moduleConnector());
635 anIsAutoPreview = aFactory.widgetAPI()->getBooleanAttribute(FEATURE_AUTO_PREVIEW, true);
638 if (!anIsAutoPreview) {
639 myPropertyPanel->findButton(PROP_PANEL_PREVIEW)->setVisible(true);
640 // send signal about preview should not be computed automatically, click on preview
641 // button should initiate it
642 std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
643 new Events_Message(Events_Loop::eventByName(EVENT_PREVIEW_BLOCKED)));
644 Events_Loop::loop()->send(aMsg);
646 // if update happens after preview is blocked, it does nothing when blocked
647 // it improves performance for valid objects on feature start
648 ModuleBase_Tools::flushUpdated(aFeature);
650 myPropertyPanel->setModelWidgets(aWidgets);
651 aFOperation->setPropertyPanel(myPropertyPanel);
653 myModule->propertyPanelDefined(theOperation);
655 #ifndef DEBUG_FEATURE_NAME
656 myPropertyPanel->setWindowTitle(theOperation->getDescription()->description());
658 std::string aFeatureName = aFeature->name();
659 myPropertyPanel->setWindowTitle(QString("%1: %2")
660 .arg(theOperation->getDescription()->description())
661 .arg(aFeatureName.c_str()));
664 myErrorMgr->setPropertyPanel(myPropertyPanel);
667 //******************************************************
668 void XGUI_Workshop::connectToPropertyPanel(const bool isToConnect)
670 XGUI_PropertyPanel* aPropertyPanel = propertyPanel();
671 if (aPropertyPanel) {
672 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
673 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
674 myModule->connectToPropertyPanel(aWidget, isToConnect);
676 connect(aWidget, SIGNAL(valueStateChanged(int)), this, SLOT(onWidgetStateChanged(int)));
677 connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
678 connect(aWidget, SIGNAL(objectUpdated()), this, SLOT(onWidgetObjectUpdated()));
681 disconnect(aWidget, SIGNAL(valueStateChanged(int)), this, SLOT(onWidgetStateChanged(int)));
682 disconnect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
683 disconnect(aWidget, SIGNAL(objectUpdated()), this, SLOT(onWidgetObjectUpdated()));
689 //******************************************************
690 void XGUI_Workshop::onOperationResumed(ModuleBase_Operation* theOperation)
692 setGrantedFeatures(theOperation);
694 if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
695 fillPropertyPanel(theOperation);
696 connectToPropertyPanel(true);
698 updateCommandStatus();
700 myModule->operationResumed(theOperation);
703 //******************************************************
704 void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
706 updateCommandStatus();
708 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
713 ModuleBase_ISelection* aSel = mySelector->selection();
714 QObjectPtrList aObj = aSel->selectedPresentations();
715 //!< No need for property panel
716 hidePanel(myPropertyPanel);
717 myPropertyPanel->cleanContent();
719 connectToPropertyPanel(false);
720 myModule->operationStopped(aFOperation);
722 // the deactivated objects of the current operation should be activated back.
723 // They were deactivated on operation start or an object redisplay
724 QObjectPtrList anObjects;
725 FeaturePtr aFeature = aFOperation->feature();
726 if (aFeature.get()) { // feature may be not created (plugin load fail)
727 if (myDisplayer->isVisible(aFeature) && !selectionActivate()->isActive(aFeature))
728 anObjects.append(aFeature);
729 std::list<ResultPtr> aResults;
730 ModelAPI_Tools::allResults(aFeature, aResults);
731 std::list<ResultPtr>::const_iterator aIt;
732 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
733 ResultPtr anObject = *aIt;
734 if (myDisplayer->isVisible(anObject) && !selectionActivate()->isActive(anObject)) {
735 anObjects.append(anObject);
739 activateObjectsSelection(anObjects);
742 //******************************************************
743 void XGUI_Workshop::onOperationCommitted(ModuleBase_Operation* theOperation)
745 myModule->operationCommitted(theOperation);
748 //******************************************************
749 void XGUI_Workshop::onOperationAborted(ModuleBase_Operation* theOperation)
751 myModule->operationAborted(theOperation);
754 //******************************************************
755 void XGUI_Workshop::setGrantedFeatures(ModuleBase_Operation* theOperation)
757 ModuleBase_OperationFeature* aFOperation =
758 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
762 QStringList aGrantedIds;
763 if (isSalomeMode()) {
764 const std::shared_ptr<Config_FeatureMessage>& anInfo =
765 mySalomeConnector->featureInfo(theOperation->id());
767 aGrantedIds = QString::fromStdString(anInfo->nestedFeatures())
768 .split(" ", QString::SkipEmptyParts);
771 aGrantedIds = myActionsMgr->nestedCommands(theOperation->id());
773 ModuleBase_IModule* aModule = module();
775 aModule->grantedOperationIds(theOperation, aGrantedIds);
777 aFOperation->setGrantedOperationIds(aGrantedIds);
780 //******************************************************
781 void XGUI_Workshop::saveDocument(const QString& theName, std::list<std::string>& theFileNames)
783 QApplication::restoreOverrideCursor();
784 SessionPtr aMgr = ModelAPI_Session::get();
786 std::list<DocumentPtr> aDocList = aMgr->allOpenedDocuments();
787 std::list<DocumentPtr>::const_iterator aIt;
788 for (aIt = aDocList.cbegin(); aIt != aDocList.cend(); aIt++) {
789 std::list<bool> aState = myObjectBrowser->getStateForDoc(*aIt);
790 (*aIt)->storeNodesState(aState);
793 aMgr->save(theName.toLatin1().constData(), theFileNames);
795 QApplication::restoreOverrideCursor();
798 //******************************************************
799 bool XGUI_Workshop::abortAllOperations()
801 return myOperationMgr->abortAllOperations();
804 //******************************************************
805 void XGUI_Workshop::operationStarted(ModuleBase_Operation* theOperation)
807 setGrantedFeatures(theOperation);
808 if (!theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
809 updateCommandStatus();
812 myModule->operationStarted(theOperation);
816 //******************************************************
817 void XGUI_Workshop::onOpen()
819 if(!abortAllOperations())
821 //save current file before close if modified
822 SessionPtr aSession = ModelAPI_Session::get();
823 if (aSession->isModified()) {
824 //TODO(sbh): re-launch the app?
825 int anAnswer = QMessageBox::question(
826 desktop(), tr("Save current file"),
827 tr("The document is modified, save before opening another?"),
828 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
829 if (anAnswer == QMessageBox::Save) {
831 } else if (anAnswer == QMessageBox::Cancel) {
837 //show file dialog, check if readable and open
838 QString aDirectory = QFileDialog::getExistingDirectory(desktop(), tr("Select directory"));
839 openDirectory(aDirectory);
842 //******************************************************
843 void XGUI_Workshop::openDirectory(const QString& theDirectory)
845 myCurrentDir = theDirectory;
846 if (myCurrentDir.isEmpty())
849 QFileInfo aFileInfo(myCurrentDir);
850 if (!aFileInfo.exists() || !aFileInfo.isReadable()) {
851 QMessageBox::critical(desktop(), tr("Warning"), tr("Unable to open the file."));
856 QApplication::setOverrideCursor(Qt::WaitCursor);
857 module()->closeDocument();
858 SessionPtr aSession = ModelAPI_Session::get();
859 aSession->closeAll();
860 aSession->load(myCurrentDir.toLatin1().constData());
861 myObjectBrowser->rebuildDataTree();
863 // Open first level of data tree
864 DocumentPtr aRootDoc = aSession->moduleDocument();
865 std::list<bool> aStates;
866 aRootDoc->restoreNodesState(aStates);
867 myObjectBrowser->setStateForDoc(aRootDoc, aStates);
869 updateCommandStatus();
871 myMainWindow->setCurrentDir(myCurrentDir, true);
875 bool aNewPart = Config_PropManager::boolean("Plugins", "create_part_by_start");
878 DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
879 int aSize = aRootDoc->size(ModelAPI_ResultPart::group());
881 ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), 0);
882 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
889 QApplication::restoreOverrideCursor();
892 //******************************************************
893 void XGUI_Workshop::onNew()
895 QApplication::setOverrideCursor(Qt::WaitCursor);
896 if (objectBrowser() == 0) {
898 mySelector->connectViewers();
900 myViewerProxy->connectToViewer();
903 myMainWindow->showPythonConsole();
904 QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
905 aWnd->showMaximized();
906 updateCommandStatus();
908 myContextMenuMgr->connectViewer();
909 QApplication::restoreOverrideCursor();
913 //******************************************************
914 void XGUI_Workshop::onExit()
916 SessionPtr aMgr = ModelAPI_Session::get();
917 if (aMgr->isModified()) {
918 int anAnswer = QMessageBox::question(
919 myMainWindow, tr("Save current file"), tr("The document is modified, save before exit?"),
920 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
921 if (anAnswer == QMessageBox::Save) {
922 bool saved = onSave();
926 } else if (anAnswer == QMessageBox::Cancel) {
933 //******************************************************
934 void XGUI_Workshop::onPreferences()
936 ModuleBase_Prefs aModif;
937 ModuleBase_Preferences::editPreferences(aModif);
938 if (aModif.size() > 0) {
940 foreach (ModuleBase_Pref aPref, aModif)
942 aSection = aPref.first;
943 if (aSection == ModuleBase_Preferences::VIEWER_SECTION) {
944 myMainWindow->viewer()->updateFromResources();
945 } else if (aSection == ModuleBase_Preferences::MENU_SECTION) {
946 myMainWindow->menuObject()->updateFromResources();
949 displayer()->redisplayObjects();
954 //******************************************************
955 void XGUI_Workshop::onTrihedronVisibilityChanged(bool theState)
957 XGUI_Displayer* aDisplayer = displayer();
959 aDisplayer->displayTrihedron(theState);
962 //******************************************************
963 bool XGUI_Workshop::onSave()
965 if(!myOperationMgr->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
967 if (myCurrentDir.isEmpty()) {
970 std::list<std::string> aFiles;
971 saveDocument(myCurrentDir, aFiles);
972 updateCommandStatus();
974 myMainWindow->setModifiedState(false);
979 //******************************************************
980 bool XGUI_Workshop::onSaveAs()
982 if(!myOperationMgr->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
984 QFileDialog dialog(desktop());
985 dialog.setWindowTitle(tr("Select directory to save files..."));
986 dialog.setFileMode(QFileDialog::Directory);
987 dialog.setFilter(QDir::AllDirs);
988 dialog.setOptions(QFileDialog::HideNameFilterDetails | QFileDialog::ShowDirsOnly);
989 dialog.setViewMode(QFileDialog::Detail);
991 if (!dialog.exec()) {
995 QString aTempDir = dialog.selectedFiles().first();
997 if (aDir.exists() && !aDir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries).isEmpty()) {
998 int answer = QMessageBox::question(
1000 // Title of the dialog which asks user if he wants to save study
1001 // in existing non-empty folder
1003 tr("The directory already contains some files, save anyway?"),
1004 QMessageBox::Save | QMessageBox::Cancel);
1005 if (answer == QMessageBox::Cancel) {
1009 myCurrentDir = aTempDir;
1011 myMainWindow->setCurrentDir(myCurrentDir, false);
1012 myMainWindow->setModifiedState(false);
1017 //******************************************************
1018 void XGUI_Workshop::onUndo(int theTimes)
1020 processUndoRedo(ActionUndo, theTimes);
1023 //******************************************************
1024 void XGUI_Workshop::onRedo(int theTimes)
1026 processUndoRedo(ActionRedo, theTimes);
1029 //******************************************************
1030 void XGUI_Workshop::processUndoRedo(const ModuleBase_ActionType theActionType, int theTimes)
1032 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1033 if (anActiveWidget) {
1034 ActionIntParamPtr aParam(new ModuleBase_ActionIntParameter(theTimes));
1035 if (anActiveWidget->processAction(theActionType, aParam))
1038 // the viewer update should be blocked in order to avoid the features blinking. For the created
1039 // feature a results are created, the flush of the created signal caused the viewer redisplay for
1040 // each created result. After a redisplay signal is flushed. So, the viewer update is blocked
1041 // until redo of all possible objects happens
1042 bool isUpdateEnabled = myDisplayer->enableUpdateViewer(false);
1044 SessionPtr aMgr = ModelAPI_Session::get();
1045 if (aMgr->isOperation()) {
1046 XGUI_OperationMgr* aOpMgr = operationMgr();
1047 /// this is important for nested operations
1048 /// when sketch operation is active, this condition is false and
1049 /// the sketch operation is not aborted
1050 if (aOpMgr->canStopOperation(aOpMgr->currentOperation()))
1051 aOpMgr->abortOperation(aOpMgr->currentOperation());
1054 myDisplayer->enableUpdateViewer(isUpdateEnabled);
1058 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
1059 std::list<std::string> anActionList = theActionType == ActionUndo ? aMgr->undoList()
1061 std::list<std::string>::const_iterator aIt = anActionList.cbegin();
1062 for (int i = 0; (i < theTimes) && (aIt != anActionList.cend()); ++i, ++aIt) {
1063 if (theActionType == ActionUndo)
1068 if (QString((*aIt).c_str()) == MOVE_TO_END_COMMAND)
1069 myObjectBrowser->rebuildDataTree();
1071 operationMgr()->updateApplyOfOperations();
1072 facesPanel()->reset(true);
1073 updateCommandStatus();
1075 // unblock the viewer update functionality and make update on purpose
1076 myDisplayer->enableUpdateViewer(isUpdateEnabled);
1077 myDisplayer->updateViewer();
1080 //******************************************************
1081 void XGUI_Workshop::onWidgetStateChanged(int thePreviousState)
1083 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1084 //ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
1085 //if (anOperation) {
1086 // ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1088 // anActiveWidget = aPanel->activeWidget();
1091 operationMgr()->onValidateOperation();
1093 myModule->widgetStateChanged(thePreviousState);
1096 //******************************************************
1097 void XGUI_Workshop::onValuesChanged()
1099 ModuleBase_ModelWidget* aSenderWidget = (ModuleBase_ModelWidget*)(sender());
1100 if (!aSenderWidget || aSenderWidget->canAcceptFocus())
1103 ModuleBase_ModelWidget* anActiveWidget = 0;
1104 ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
1106 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1108 anActiveWidget = aPanel->activeWidget();
1110 if (anActiveWidget) {
1111 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1113 if (aWidgetValidated)
1114 aWidgetValidated->clearValidatedCash();
1118 //******************************************************
1119 void XGUI_Workshop::onWidgetObjectUpdated()
1121 operationMgr()->onValidateOperation();
1124 //******************************************************
1125 ModuleBase_IModule* XGUI_Workshop::loadModule(const QString& theModule)
1127 QString libName = QString::fromStdString(library(theModule.toStdString()));
1128 if (libName.isEmpty()) {
1129 qWarning(qPrintable(tr("Information about module \"%1\" doesn't exist.").arg(theModule)));
1134 CREATE_FUNC crtInst = 0;
1137 HINSTANCE modLib = ::LoadLibrary((LPTSTR) qPrintable(libName));
1141 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
1142 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
1143 QString aMsg((char*) &lpMsgBuf);
1144 err = QString("Failed to load %1. %2").arg(libName).arg(aMsg);
1145 ::LocalFree(lpMsgBuf);
1147 crtInst = (CREATE_FUNC) ::GetProcAddress(modLib, CREATE_MODULE);
1151 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
1152 | FORMAT_MESSAGE_IGNORE_INSERTS,
1153 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
1154 QString aMsg((char*) &lpMsgBuf);
1155 err = QString("Failed to find %1 function. %2").arg( CREATE_MODULE).arg(aMsg);
1156 ::LocalFree(lpMsgBuf);
1160 void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY | RTLD_GLOBAL );
1162 err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
1164 crtInst = (CREATE_FUNC)dlsym( modLib, CREATE_MODULE );
1166 err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() );
1171 ModuleBase_IModule* aModule = crtInst ? crtInst(myModuleConnector) : 0;
1173 if (!err.isEmpty()) {
1175 Events_InfoMessage("XGUI_Workshop", err.toStdString()).send();
1177 qWarning(qPrintable(err));
1183 //******************************************************
1184 bool XGUI_Workshop::createModule()
1186 Config_ModuleReader aModuleReader;
1187 QString moduleName = QString::fromStdString(aModuleReader.getModuleName());
1188 myModule = loadModule(moduleName);
1192 //connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
1193 // myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
1194 //connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
1195 // myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
1197 myModule->createFeatures();
1199 salomeConnector()->createFeatureActions();
1201 //myActionsMgr->update();
1205 //******************************************************
1206 void XGUI_Workshop::updateCommandStatus()
1208 QList<QAction*> aCommands;
1210 aCommands = salomeConnector()->commandList();
1212 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
1213 foreach (AppElements_Command* aCmd, aMenuBar->features())
1214 aCommands.append(aCmd);
1216 SessionPtr aMgr = ModelAPI_Session::get();
1217 if (aMgr->hasModuleDocument()) {
1218 foreach(QAction* aCmd, aCommands) {
1219 QString aId = aCmd->data().toString();
1220 if (aId == "UNDO_CMD") {
1221 bool isActionEnabled = false;
1222 // if ultimate is true -> using result of operation only, or using OR combination
1223 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1224 if (anActiveWidget && anActiveWidget->canProcessAction(ActionUndo, isActionEnabled))
1225 aCmd->setEnabled(isActionEnabled);
1227 aCmd->setEnabled(myModule->canUndo());
1229 else if (aId == "REDO_CMD") {
1230 bool isActionEnabled = false;
1231 // if ultimate is true -> using result of operation only, or using OR combination
1232 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1233 if (anActiveWidget && anActiveWidget->canProcessAction(ActionRedo, isActionEnabled))
1234 aCmd->setEnabled(isActionEnabled);
1236 aCmd->setEnabled(myModule->canRedo());
1239 // Enable all commands
1240 aCmd->setEnabled(true);
1244 foreach(QAction* aCmd, aCommands) {
1245 QString aId = aCmd->data().toString();
1246 if (aId == "NEW_CMD")
1247 aCmd->setEnabled(true);
1248 else if (aId == "EXIT_CMD")
1249 aCmd->setEnabled(true);
1251 aCmd->setEnabled(false);
1254 myActionsMgr->updateCommandsStatus();
1255 emit commandStatusUpdated();
1258 //******************************************************
1259 void XGUI_Workshop::updateHistory()
1261 bool isActionEnabled = false;
1262 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1263 QList<ActionInfo> aUndoRes;
1264 QList<ActionInfo> aRedoRes;
1265 if (anActiveWidget && anActiveWidget->canProcessAction(ActionUndo, isActionEnabled)) {
1266 aUndoRes = anActiveWidget->actionsList(ActionUndo);
1267 aRedoRes = anActiveWidget->actionsList(ActionRedo);
1269 std::list<std::string> aUndoList = ModelAPI_Session::get()->undoList();
1270 aUndoRes = processHistoryList(aUndoList);
1272 std::list<std::string> aRedoList = ModelAPI_Session::get()->redoList();
1273 aRedoRes = processHistoryList(aRedoList);
1275 emit updateUndoHistory(aUndoRes);
1276 emit updateRedoHistory(aRedoRes);
1279 //******************************************************
1280 QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
1282 QDockWidget* aObjDock = new QDockWidget(theParent);
1283 aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea |
1284 Qt::RightDockWidgetArea |
1285 Qt::BottomDockWidgetArea);
1286 aObjDock->setWindowTitle(tr("Object browser"));
1287 aObjDock->setStyleSheet(
1288 "::title { position: relative; padding-left: 5px; text-align: left center }");
1289 myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock, this);
1290 myObjectBrowser->setXMLReader(myDataModelXMLReader);
1291 myModule->customizeObjectBrowser(myObjectBrowser);
1292 aObjDock->setWidget(myObjectBrowser);
1294 myContextMenuMgr->connectObjectBrowser();
1298 //******************************************************
1300 * Creates dock widgets, places them in corresponding area
1301 * and tabifies if necessary.
1303 void XGUI_Workshop::createDockWidgets()
1305 QMainWindow* aDesktop = desktop();
1306 QDockWidget* aObjDock = createObjectBrowser(aDesktop);
1307 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
1308 myPropertyPanel = new XGUI_PropertyPanel(aDesktop, myOperationMgr);
1309 myActiveControlMgr->addSelector(new XGUI_PropertyPanelSelector(myPropertyPanel));
1311 myPropertyPanel->setupActions(myActionsMgr);
1312 myPropertyPanel->setAllowedAreas(Qt::LeftDockWidgetArea |
1313 Qt::RightDockWidgetArea |
1314 Qt::BottomDockWidgetArea);
1315 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel);
1316 hidePanel(myPropertyPanel); ///<! Invisible by default
1318 myFacesPanel = new XGUI_FacesPanel(aDesktop, myModuleConnector);
1319 myActiveControlMgr->addSelector(new XGUI_FacesPanelSelector(myFacesPanel));
1320 myFacesPanel->setAllowedAreas(Qt::LeftDockWidgetArea |
1321 Qt::RightDockWidgetArea |
1322 Qt::BottomDockWidgetArea);
1323 connect(myFacesPanel, SIGNAL(closed()), myFacesPanel, SLOT(onClosed()));
1325 aDesktop->addDockWidget(
1327 Qt::RightDockWidgetArea,
1329 Qt::LeftDockWidgetArea,
1332 hidePanel(myFacesPanel); ///<! Invisible by default
1335 bool aShowOnTheRight = Config_PropManager::boolean("Plugins", "show_hide_faces");
1336 if (aShowOnTheRight) {
1337 aDesktop->addDockWidget(Qt::RightDockWidgetArea, myFacesPanel);
1338 showPanel(myFacesPanel);
1341 hideObjectBrowser();
1345 if (!aShowOnTheRight)
1348 aDesktop->tabifyDockWidget(myFacesPanel, aObjDock);
1353 #endif // HAVE_SALOME
1355 aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
1356 myPropertyPanel->installEventFilter(myOperationMgr);
1358 QAction* aOkAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept);
1359 connect(aOkAct, SIGNAL(triggered()), this, SLOT(onAcceptActionClicked()));
1361 QAction* aCancelAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Abort);
1362 connect(aCancelAct, SIGNAL(triggered()), myOperationMgr, SLOT(onAbortOperation()));
1364 QAction* aPreviewAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Preview);
1365 connect(aPreviewAct, SIGNAL(triggered()), this, SLOT(onPreviewActionClicked()));
1367 connect(myPropertyPanel, SIGNAL(keyReleased(QObject*, QKeyEvent*)),
1368 myOperationMgr, SLOT(onKeyReleased(QObject*, QKeyEvent*)));
1369 connect(myPropertyPanel, SIGNAL(enterClicked(QObject*)),
1370 myOperationMgr, SLOT(onProcessEnter(QObject*)));
1373 //******************************************************
1374 void XGUI_Workshop::showPanel(QDockWidget* theDockWidget)
1376 if (theDockWidget == myPropertyPanel) {
1377 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1378 ///<! Restore ability to close panel from the window's menu
1379 aViewAct->setEnabled(true);
1381 theDockWidget->show();
1382 theDockWidget->raise();
1384 // The next code is necessary to made the property panel the active window
1385 // in order to operation manager could process key events of the panel.
1386 // otherwise they are ignored. It happens only if the same(activateWindow) is
1387 // not happened by property panel activation(e.g. resume operation of Sketch)
1388 ModuleBase_Tools::setFocus(theDockWidget, "XGUI_Workshop::showPanel()");
1391 //******************************************************
1392 void XGUI_Workshop::hidePanel(QDockWidget* theDockWidget)
1394 if (theDockWidget && theDockWidget == myPropertyPanel) {
1395 QAction* aViewAct = theDockWidget->toggleViewAction();
1396 ///<! Do not allow to show empty property panel
1397 aViewAct->setEnabled(false);
1399 theDockWidget->hide();
1401 // the property panel is active window of the desktop, when it is
1402 // hidden, it is undefined which window becomes active. By this reason
1403 // it is defined to perform the desktop as the active window.
1404 // in SALOME mode, workstack made the PyConsole the active window,
1405 // set the focus on it. As a result, shortcuts of the application, like
1406 // are processed by this console. For example Undo actions.
1407 // It is possible that this code is to be moved to SHAPER package
1408 QMainWindow* aDesktop = desktop();
1409 ModuleBase_Tools::setFocus(aDesktop, "XGUI_Workshop::hidePanel()");
1412 //******************************************************
1413 void XGUI_Workshop::showObjectBrowser()
1415 if (!isSalomeMode())
1416 myObjectBrowser->parentWidget()->show();
1419 //******************************************************
1420 void XGUI_Workshop::hideObjectBrowser()
1422 if (!isSalomeMode())
1423 myObjectBrowser->parentWidget()->hide();
1426 //******************************************************
1427 void XGUI_Workshop::salomeViewerSelectionChanged()
1429 emit salomeViewerSelection();
1432 //**************************************************************
1433 ModuleBase_IViewer* XGUI_Workshop::salomeViewer() const
1435 return mySalomeConnector->viewer();
1438 //**************************************************************
1439 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
1441 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1442 if (theId == "DELETE_CMD")
1444 else if (theId == "CLEAN_HISTORY_CMD")
1446 else if (theId == "MOVE_CMD")
1448 else if (theId == "COLOR_CMD")
1449 changeColor(aObjects);
1450 else if (theId == "DEFLECTION_CMD")
1451 changeDeflection(aObjects);
1452 #ifdef USE_TRANSPARENCY
1453 else if (theId == "TRANSPARENCY_CMD")
1454 changeTransparency(aObjects);
1456 else if (theId == "SHOW_CMD") {
1457 showObjects(aObjects, true);
1458 mySelector->updateSelectionBy(ModuleBase_ISelection::Browser);
1459 updateCommandStatus();
1461 else if (theId == "HIDE_CMD") {
1462 showObjects(aObjects, false);
1463 updateCommandStatus();
1465 else if (theId == "SHOW_ONLY_CMD") {
1466 showOnlyObjects(aObjects);
1467 mySelector->updateSelectionBy(ModuleBase_ISelection::Browser);
1468 updateCommandStatus();
1470 else if (theId == "SHADING_CMD")
1471 setDisplayMode(aObjects, XGUI_Displayer::Shading);
1472 else if (theId == "WIREFRAME_CMD")
1473 setDisplayMode(aObjects, XGUI_Displayer::Wireframe);
1474 else if (theId == "HIDEALL_CMD") {
1475 QObjectPtrList aList = myDisplayer->displayedObjects();
1476 foreach (ObjectPtr aObj, aList) {
1477 if (module()->canEraseObject(aObj))
1478 aObj->setDisplayed(false);
1480 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1482 //issue #2159 Hide all incomplete behavior
1483 viewer()->eraseAll();
1485 updateCommandStatus();
1486 // Necessary for update icons in ObjectBrowser on Linux
1487 myObjectBrowser->updateAllIndexes();
1488 } else if (theId == "SELECT_VERTEX_CMD") {
1489 setViewerSelectionMode(TopAbs_VERTEX);
1490 } else if (theId == "SELECT_EDGE_CMD") {
1491 setViewerSelectionMode(TopAbs_EDGE);
1492 } else if (theId == "SELECT_FACE_CMD") {
1493 setViewerSelectionMode(TopAbs_FACE);
1494 } else if (theId == "INSERT_FOLDER_CMD") {
1495 insertFeatureFolder();
1496 } else if (theId == "ADD_TO_FOLDER_BEFORE_CMD") {
1497 insertToFolder(true);
1498 } else if (theId == "ADD_TO_FOLDER_AFTER_CMD") {
1499 insertToFolder(false);
1500 } else if (theId == "ADD_OUT_FOLDER_BEFORE_CMD") {
1501 moveOutFolder(true);
1502 } else if (theId == "ADD_OUT_FOLDER_AFTER_CMD") {
1503 moveOutFolder(false);
1504 } else if (theId == "SELECT_RESULT_CMD") {
1505 //setViewerSelectionMode(-1);
1506 //IMP: an attempt to use result selection with other selection modes
1507 setViewerSelectionMode(ModuleBase_ResultPrs::Sel_Result);
1508 setViewerSelectionMode(TopAbs_COMPSOLID);
1509 } else if (theId == "SHOW_RESULTS_CMD") {
1510 highlightResults(aObjects);
1511 } else if (theId == "SHOW_FEATURE_CMD") {
1512 highlightFeature(aObjects);
1515 else if (theId == "TINSPECTOR_VIEW") {
1516 Handle(CDF_Application) anApplication = CDF_Session::CurrentSession()->CurrentApplication();
1517 if (!anApplication.IsNull())
1519 if (!MyTCommunicator)
1521 MyTCommunicator = new TInspector_Communicator();
1523 NCollection_List<Handle(Standard_Transient)> aParameters;
1524 aParameters.Append(anApplication);
1525 Handle(AIS_InteractiveContext) aContext = viewer()->AISContext();
1526 if (!aContext.IsNull())
1527 aParameters.Append(aContext);
1529 #ifdef DEBUG_WITH_MESSAGE_REPORT
1530 Handle(Message_Report) aContextReport = aContext->GetReport();
1531 aContext->SetReportActive (Standard_True);
1532 aContextReport->SetLimit (1000);
1533 if (!aContextReport.IsNull())
1534 aParameters.Append(aContextReport);
1536 MyVCallBack = new VInspector_CallBack();
1537 myDisplayer->setCallBack(MyVCallBack);
1539 AppElements_Viewer* aViewer = mainWindow()->viewer();
1541 aViewer->setCallBack(MyVCallBack);
1543 aParameters.Append(MyVCallBack);
1545 MyTCommunicator->RegisterPlugin("TKDFBrowser");
1546 MyTCommunicator->RegisterPlugin("TKShapeView");
1547 MyTCommunicator->RegisterPlugin("TKVInspector");
1548 #ifdef DEBUG_WITH_MESSAGE_REPORT
1549 MyTCommunicator->RegisterPlugin("TKMessageView");
1551 MyTCommunicator->RegisterPlugin("SMBrowser"); // custom plugin to view ModelAPI
1552 //MyTCommunicator->RegisterPlugin("TKSMBrowser"); // custom plugin to view ModelAPI
1554 MyTCommunicator->Init(aParameters);
1555 MyTCommunicator->Activate("TKSMBrowser"); // to have button in TInspector
1556 #ifndef DEBUG_WITH_MESSAGE_REPORT
1557 MyTCommunicator->Activate("TKVInspector"); // to have filled callback by model
1559 MyTCommunicator->Activate("TKDFBrowser");
1561 #ifdef DEBUG_WITH_MESSAGE_REPORT
1562 MyTCommunicator->Activate("TKMessageView"); // temporary
1563 MyTCommunicator->Activate("TKVInspector"); // to have filled callback by model
1566 MyTCommunicator->SetVisible(true);
1572 //**************************************************************
1573 void XGUI_Workshop::setViewerSelectionMode(int theMode)
1576 myViewerSelMode.clear();
1578 if (myViewerSelMode.contains(theMode))
1579 myViewerSelMode.removeAll(theMode);
1581 myViewerSelMode.append(theMode);
1583 selectionActivate()->updateSelectionModes();
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 selectionActivate()->activateObjects(aModes, theList);
1596 //**************************************************************
1597 bool XGUI_Workshop::prepareForDisplay(const std::set<ObjectPtr>& theObjects) const
1599 if (facesPanel()->isEmpty())
1602 // generate container of objects taking into account sub elments of compsolid
1603 std::set<ObjectPtr> anAllProcessedObjects;
1604 for (std::set<ObjectPtr>::const_iterator anObjectsIt = theObjects.begin();
1605 anObjectsIt != theObjects.end(); anObjectsIt++) {
1606 ObjectPtr anObject = *anObjectsIt;
1607 ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(anObject);
1608 if (aCompRes.get()) {
1609 if (aCompRes->numberOfSubs(true) == 0)
1610 anAllProcessedObjects.insert(anObject);
1612 for (int i = 0; i < aCompRes->numberOfSubs(true); i++) {
1613 ResultPtr aSubRes = aCompRes->subResult(i, true);
1614 anAllProcessedObjects.insert(aCompRes->subResult(i, true));
1619 anAllProcessedObjects.insert(anObject);
1622 // find hidden objects in faces panel
1623 std::set<ObjectPtr> aHiddenObjects;
1624 QStringList aHiddenObjectNames;
1625 for (std::set<ObjectPtr>::const_iterator anObjectsIt = anAllProcessedObjects.begin();
1626 anObjectsIt != anAllProcessedObjects.end(); anObjectsIt++) {
1627 if (!facesPanel()->isObjectHiddenByPanel(*anObjectsIt))
1629 aHiddenObjects.insert(*anObjectsIt);
1630 aHiddenObjectNames.append((*anObjectsIt)->data()->name().c_str());
1632 if (aHiddenObjects.empty()) // in parameter objects there are no hidden objects in hide face
1635 int anAnswer = QMessageBox::question(
1636 desktop(), tr("Show object"),
1637 tr("'%1'\n are hidden by %2:\nRemove objects from the panel to be displayed?")
1638 .arg(aHiddenObjectNames.join(' ,')).arg(facesPanel()->windowTitle()),
1639 QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
1641 bool aToBeDisplayed = anAnswer == QMessageBox::Yes;
1643 facesPanel()->restoreObjects(aHiddenObjects);
1645 return aToBeDisplayed;
1648 //**************************************************************
1649 void XGUI_Workshop::deleteObjects()
1651 ModuleBase_IModule* aModule = module();
1652 // allow the module to delete objects, do nothing if it has succeed
1653 if (aModule->deleteObjects()) {
1654 updateCommandStatus();
1658 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1659 if (!abortAllOperations())
1662 bool hasResult = false;
1663 bool hasFeature = false;
1664 bool hasParameter = false;
1665 bool hasCompositeOwner = false;
1666 bool hasResultInHistory = false;
1667 bool hasFolder = false;
1668 ModuleBase_Tools::checkObjects(anObjects, hasResult, hasFeature, hasParameter, hasCompositeOwner,
1669 hasResultInHistory, hasFolder);
1670 if (!(hasFeature || hasParameter || hasFolder))
1674 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1675 std::set<FeaturePtr> aFeatures;
1676 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1677 ModelAPI_Tools::findAllReferences(aFeatures, aReferences);
1679 std::set<FolderPtr> aFolders;
1680 ModuleBase_Tools::convertToFolders(anObjects, aFolders);
1683 QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text() + " %1";
1684 aDescription = aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
1685 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, module());
1687 operationMgr()->startOperation(anOpAction);
1689 std::set<FeaturePtr> aFeatureRefsToDelete;
1690 if (ModuleBase_Tools::askToDelete(aFeatures, aReferences, desktop(), aFeatureRefsToDelete)) {
1691 // WORKAROUND, should be done before each object remove, if it presents in XGUI_DataModel tree
1692 // It is necessary to clear selection in order to avoid selection changed event during
1693 // deletion and negative consequences connected with processing of already deleted items
1694 mySelector->clearSelection();
1696 if (!aFeatureRefsToDelete.empty())
1697 aFeatures.insert(aFeatureRefsToDelete.begin(), aFeatureRefsToDelete.end());
1698 aDone = ModelAPI_Tools::removeFeatures(aFeatures, false);
1700 if (aFolders.size() > 0) {
1701 std::set<FolderPtr>::const_iterator anIt = aFolders.begin(),
1702 aLast = aFolders.end();
1703 for (; anIt != aLast; anIt++) {
1704 FolderPtr aFolder = *anIt;
1705 if (aFolder.get()) {
1706 DocumentPtr aDoc = aFolder->document();
1707 aDoc->removeFolder(aFolder);
1713 operationMgr()->commitOperation();
1715 operationMgr()->abortOperation(operationMgr()->currentOperation());
1718 //**************************************************************
1719 void addRefsToFeature(const FeaturePtr& theFeature,
1720 const std::map<FeaturePtr, std::set<FeaturePtr> >& theMainList,
1721 std::set<FeaturePtr>& theReferences)
1723 //if (theReferences.find(theFeature) != theReferences.end())
1725 if (theMainList.find(theFeature) == theMainList.end())
1726 return; // this feature is not in the selection list, so exists without references to it
1727 std::set<FeaturePtr> aMainReferences = theMainList.at(theFeature);
1729 std::set<FeaturePtr>::const_iterator anIt = aMainReferences.begin(),
1730 aLast = aMainReferences.end();
1731 for (; anIt != aLast; anIt++) {
1732 FeaturePtr aRefFeature = *anIt;
1733 if (theReferences.find(aRefFeature) == theReferences.end())
1734 theReferences.insert(aRefFeature);
1735 addRefsToFeature(aRefFeature, theMainList, theReferences);
1739 //**************************************************************
1740 void XGUI_Workshop::cleanHistory()
1742 if (!abortAllOperations())
1745 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1746 std::set<FeaturePtr> aFeatures;
1747 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1749 #ifdef DEBUG_CLEAN_HISTORY
1751 std::set<FeaturePtr>::const_iterator aFIt;
1752 for (aFIt = aFeatures.begin(); aFIt != aFeatures.end(); ++aFIt) {
1753 FeaturePtr aFeature = ModelAPI_Feature::feature(*aFIt);
1754 anInfo.append(aFeature->name().c_str());
1756 QString anInfoStr = anInfo.join(";\t");
1757 qDebug(QString("cleanHistory for: [%1] - %2").
1758 arg(aFeatures.size()).arg(anInfoStr).toStdString().c_str());
1761 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1762 ModelAPI_Tools::findAllReferences(aFeatures, aReferences, true, false);
1763 // find for each object whether all reference values are in the map as key, that means that there
1764 // is no other reference in the model to this object, so it might be removed by cleaning history
1765 // sk_1(ext_1, vertex_1) + (sk_3, bool_1) - cann't be deleted, dependency to bool_1
1766 // ext_1(bool_1, sk_3) - cann't be deleted, dependency to bool_1
1768 // sk_2(ext_2) + (bool_1) - cann't be deleted, dependency to bool_1
1769 // ext_2(bool_1) - cann't be deleted, dependency to bool_1
1771 // Information: bool_1 is not selected
1772 std::set<FeaturePtr> anUnusedObjects;
1773 std::map<FeaturePtr, std::set<FeaturePtr> >::const_iterator aMainIt = aReferences.begin(),
1774 aMainLast = aReferences.end();
1775 for (; aMainIt != aMainLast; aMainIt++) {
1776 FeaturePtr aMainListFeature = aMainIt->first;
1777 std::set<FeaturePtr> aMainRefList = aMainIt->second;
1778 std::set<FeaturePtr>::const_iterator aRefIt = aMainRefList.begin(),
1779 aRefLast = aMainRefList.end();
1780 bool aFeatureOutOfTheList = false;
1781 for (; aRefIt != aRefLast && !aFeatureOutOfTheList; aRefIt++) {
1782 FeaturePtr aRefFeature = *aRefIt;
1783 aFeatureOutOfTheList = aReferences.find(aRefFeature) == aReferences.end();
1785 if (!aFeatureOutOfTheList)
1786 anUnusedObjects.insert(aMainListFeature);
1789 #ifdef DEBUG_CLEAN_HISTORY
1791 for (aFIt = anUnusedObjects.begin(); aFIt != anUnusedObjects.end(); ++aFIt) {
1792 FeaturePtr aFeature = *aFIt;
1793 anInfo.append(aFeature->name().c_str());
1795 qDebug(QString("unused objects: [%1] - %2").
1796 arg(anInfo.size()).arg(anInfo.join(";\t")).toStdString().c_str());
1799 // warn about the references remove, break the delete operation if the user chose it
1800 if (!anUnusedObjects.empty()) {
1802 foreach (const FeaturePtr& aFeature, anUnusedObjects) {
1803 aNames.append(aFeature->name().c_str());
1806 QString anUnusedNames = aNames.join(", ");
1808 QString anActionId = "CLEAN_HISTORY_CMD";
1809 QString aDescription = contextMenuMgr()->action(anActionId)->text();
1811 QMessageBox aMessageBox(desktop());
1812 aMessageBox.setWindowTitle(aDescription);
1813 aMessageBox.setIcon(QMessageBox::Warning);
1814 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
1815 aMessageBox.setDefaultButton(QMessageBox::No);
1817 const char* aKeyStr = "Unused features are the following: "
1818 "%1.\nThese features will be deleted.\nWould you like to continue?";
1819 QString aText = QString(tr(aKeyStr).arg(anUnusedNames));
1820 aMessageBox.setText(aText);
1821 if (aMessageBox.exec() == QMessageBox::No)
1824 // 1. start operation
1825 aDescription += "by deleting of " +
1826 aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
1827 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, module());
1828 operationMgr()->startOperation(anOpAction);
1830 // WORKAROUND, should be done before each object remove, if it presents in XGUI_DataModel tree
1831 // It is necessary to clear selection in order to avoid selection changed event during
1832 // deletion and negative consequences connected with processing of already deleted items
1833 mySelector->clearSelection();
1835 std::set<FeaturePtr> anIgnoredFeatures;
1836 if (ModelAPI_Tools::removeFeatures(anUnusedObjects, true)) {
1837 operationMgr()->commitOperation();
1840 operationMgr()->abortOperation(operationMgr()->currentOperation());
1844 QString anActionId = "CLEAN_HISTORY_CMD";
1845 QString aDescription = contextMenuMgr()->action(anActionId)->text();
1847 QMessageBox aMessageBox(desktop());
1848 aMessageBox.setWindowTitle(aDescription);
1849 aMessageBox.setIcon(QMessageBox::Warning);
1850 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
1851 aMessageBox.setDefaultButton(QMessageBox::No);
1854 aMessageBox.setStandardButtons(QMessageBox::Ok);
1855 aMessageBox.setDefaultButton(QMessageBox::Ok);
1857 aText = QString(tr("All features are relevant, there is nothing to be deleted"));
1858 aMessageBox.setText(aText);
1860 if (aMessageBox.exec() == QMessageBox::No)
1865 //**************************************************************
1866 void XGUI_Workshop::moveObjects()
1868 if (!abortAllOperations())
1871 SessionPtr aMgr = ModelAPI_Session::get();
1873 QString anActionId = "MOVE_CMD";
1874 QString aDescription = contextMenuMgr()->action(anActionId)->text();
1875 aMgr->startOperation(aDescription.toStdString());
1877 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1878 // It is necessary to clear selection in order to avoid selection changed event during
1879 // moving and negative consequences connected with processing of already moved items
1880 mySelector->clearSelection();
1881 // check whether the object can be moved. There should not be parts which are not loaded
1882 std::set<FeaturePtr> aFeatures;
1883 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1884 if (!XGUI_Tools::canRemoveOrRename(desktop(), aFeatures))
1887 DocumentPtr anActiveDocument = aMgr->activeDocument();
1888 FeaturePtr aCurrentFeature = anActiveDocument->currentFeature(true);
1889 std::set<FeaturePtr>::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
1890 for (; anIt != aLast; anIt++) {
1891 FeaturePtr aFeature = *anIt;
1892 if (!aFeature.get() || !myModule->canApplyAction(aFeature, anActionId))
1895 anActiveDocument->moveFeature(aFeature, aCurrentFeature);
1896 aCurrentFeature = anActiveDocument->currentFeature(true);
1898 aMgr->finishOperation();
1901 //**************************************************************
1902 bool XGUI_Workshop::deleteFeatures(const QObjectPtrList& theObjects)
1904 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1905 std::set<FeaturePtr> aFeatures;
1906 ModuleBase_Tools::convertToFeatures(theObjects, aFeatures);
1908 return ModelAPI_Tools::removeFeaturesAndReferences(aFeatures);
1911 //******************************************************
1912 bool hasResults(QObjectPtrList theObjects, const std::set<std::string>& theTypes)
1914 bool isFoundResultType = false;
1915 foreach(ObjectPtr anObj, theObjects)
1917 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
1918 if (aResult.get() == NULL)
1921 isFoundResultType = theTypes.find(aResult->groupName()) != theTypes.end();
1922 if (isFoundResultType)
1925 return isFoundResultType;
1928 //**************************************************************
1929 // Returns the list of all features for theDocument and all features of
1930 // all nested parts.
1931 std::list<FeaturePtr> allFeatures(const DocumentPtr& theDocument)
1933 std::list<FeaturePtr> aResultList;
1934 std::list<FeaturePtr> anAllFeatures = theDocument->allFeatures();
1935 foreach (const FeaturePtr& aFeature, anAllFeatures) {
1936 // The order of appending features of the part and the part itself is important
1938 // Append features from a part feature
1939 std::list<ResultPtr> aResults;
1940 ModelAPI_Tools::allResults(aFeature, aResults);
1941 foreach (const ResultPtr& aResult, aResults) {
1942 ResultPartPtr aResultPart =
1943 std::dynamic_pointer_cast<ModelAPI_ResultPart>(aResult);
1944 if (aResultPart.get() && aResultPart->partDoc().get()) {
1946 std::list<FeaturePtr> anAllFeatures = allFeatures(aResultPart->partDoc());
1947 aResultList.insert(aResultList.end(), anAllFeatures.begin(), anAllFeatures.end());
1951 aResultList.push_back(aFeature);
1956 //**************************************************************
1957 // Returns the list of features placed between theObject and the current feature
1958 // in the same document. Excludes theObject, includes the current feature.
1959 std::list<FeaturePtr> toCurrentFeatures(const ObjectPtr& theObject)
1961 std::list<FeaturePtr> aResult;
1962 DocumentPtr aDocument = theObject->document();
1963 std::list<FeaturePtr> anAllFeatures = allFeatures(aDocument);
1964 // find the object iterator
1965 std::list<FeaturePtr>::iterator aObjectIt =
1966 std::find(anAllFeatures.begin(), anAllFeatures.end(), theObject);
1967 if (aObjectIt == anAllFeatures.end())
1969 // find the current feature iterator
1970 std::list<FeaturePtr>::iterator aCurrentIt =
1971 std::find(anAllFeatures.begin(), anAllFeatures.end(), aDocument->currentFeature(true));
1972 if (aCurrentIt == anAllFeatures.end())
1974 // check the right order
1975 if (std::distance(aObjectIt, anAllFeatures.end()) <=
1976 std::distance(aCurrentIt, anAllFeatures.end()))
1978 // exclude the object
1979 std::advance(aObjectIt, 1);
1980 // include the current feature
1981 std::advance(aCurrentIt, 1);
1982 return std::list<FeaturePtr>(aObjectIt, aCurrentIt);
1985 //******************************************************
1986 bool XGUI_Workshop::canMoveFeature()
1988 QString anActionId = "MOVE_CMD";
1990 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1991 QObjectPtrList aValidatedObjects;
1992 foreach (ObjectPtr aObject, aObjects) {
1993 if (!myModule->canApplyAction(aObject, anActionId))
1995 // To be moved feature should be in active document
1996 if (aObject->document() != ModelAPI_Session::get()->activeDocument())
1998 aValidatedObjects.append(aObject);
2000 if (aValidatedObjects.size() != aObjects.size())
2001 aObjects = aValidatedObjects;
2003 bool aCanMove = !aObjects.empty();
2005 QObjectPtrList::const_iterator anIt = aObjects.begin(), aLast = aObjects.end();
2006 for (; anIt != aLast && aCanMove; anIt++) {
2007 ObjectPtr aObject = *anIt;
2008 // 1. Get features placed between selected and current in the document
2009 std::list<FeaturePtr> aFeaturesBetween = toCurrentFeatures(aObject);
2010 // if aFeaturesBetween is empty it means wrong order or aObject is the current feature
2011 if (aFeaturesBetween.empty())
2014 std::set<FeaturePtr> aPlacedFeatures(aFeaturesBetween.begin(), aFeaturesBetween.end());
2015 // 2. Get all reference features to the selected object in the document
2016 std::set<FeaturePtr> aRefFeatures;
2017 ModuleBase_Tools::refsToFeatureInFeatureDocument(aObject, aRefFeatures);
2019 if (aRefFeatures.empty())
2022 // 3. Find any placed features in all reference features
2023 std::set<FeaturePtr> aIntersectionFeatures;
2024 std::set_intersection(aRefFeatures.begin(), aRefFeatures.end(),
2025 aPlacedFeatures.begin(), aPlacedFeatures.end(),
2026 std::inserter(aIntersectionFeatures, aIntersectionFeatures.begin()));
2027 // 4. Return false if any reference feature is placed before current feature
2028 if (!aIntersectionFeatures.empty())
2036 //**************************************************************
2037 bool XGUI_Workshop::canBeShaded(const ObjectPtr& theObject) const
2039 bool aCanBeShaded = myDisplayer->canBeShaded(theObject);
2040 if (!aCanBeShaded) {
2041 ResultCompSolidPtr aCompsolidResult =
2042 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
2043 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
2044 for(int i = 0; i < aCompsolidResult->numberOfSubs() && !aCanBeShaded; i++)
2045 aCanBeShaded = myDisplayer->canBeShaded(aCompsolidResult->subResult(i));
2048 return aCanBeShaded;
2051 //**************************************************************
2052 bool XGUI_Workshop::canChangeProperty(const QString& theActionName) const
2054 if (theActionName == "COLOR_CMD" ||
2055 theActionName == "DEFLECTION_CMD"
2056 #ifdef USE_TRANSPARENCY
2057 || theActionName == "TRANSPARENCY_CMD"
2060 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
2062 std::set<std::string> aTypes;
2063 aTypes.insert(ModelAPI_ResultGroup::group());
2064 aTypes.insert(ModelAPI_ResultConstruction::group());
2065 aTypes.insert(ModelAPI_ResultBody::group());
2066 aTypes.insert(ModelAPI_ResultPart::group());
2068 return hasResults(aObjects, aTypes);
2073 //******************************************************
2074 void setColor(ResultPtr theResult, const std::vector<int>& theColor)
2076 if (!theResult.get())
2079 AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
2080 if (aColorAttr.get() != NULL) {
2081 if (!aColorAttr->size()) {
2082 aColorAttr->setSize(3);
2084 aColorAttr->setValue(0, theColor[0]);
2085 aColorAttr->setValue(1, theColor[1]);
2086 aColorAttr->setValue(2, theColor[2]);
2090 //**************************************************************
2091 void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
2094 AttributeIntArrayPtr aColorAttr;
2095 // 1. find the current color of the object. This is a color of AIS presentation
2096 // The objects are iterated until a first valid color is found
2097 std::vector<int> aColor;
2098 foreach(ObjectPtr anObject, theObjects) {
2099 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
2100 if (aResult.get()) {
2101 XGUI_CustomPrs::getResultColor(aResult, aColor);
2104 // TODO: remove the obtaining a color from the AIS object
2105 // this does not happen never because:
2106 // 1. The color can be changed only on results
2107 // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
2108 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
2109 if (anAISObj.get()) {
2111 anAISObj->getColor(aColor[0], aColor[1], aColor[2]);
2114 if (!aColor.empty())
2117 if (aColor.size() != 3)
2120 if (!abortAllOperations())
2122 // 2. show the dialog to change the value
2123 XGUI_ColorDialog* aDlg = new XGUI_ColorDialog(desktop());
2124 aDlg->setColor(aColor);
2125 aDlg->move(QCursor::pos());
2126 bool isDone = aDlg->exec() == QDialog::Accepted;
2130 bool isRandomColor = aDlg->isRandomColor();
2132 // 3. abort the previous operation and start a new one
2133 SessionPtr aMgr = ModelAPI_Session::get();
2134 QString aDescription = contextMenuMgr()->action("COLOR_CMD")->text();
2135 aMgr->startOperation(aDescription.toStdString());
2137 // 4. set the value to all results
2138 std::vector<int> aColorResult = aDlg->getColor();
2139 foreach(ObjectPtr anObj, theObjects) {
2140 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
2141 if (aResult.get() != NULL) {
2142 ResultCompSolidPtr aCompsolidResult =
2143 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
2144 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
2145 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
2146 setColor(aCompsolidResult->subResult(i), !isRandomColor ? aColorResult :
2147 aDlg->getRandomColor());
2150 setColor(aResult, !isRandomColor ? aColorResult : aDlg->getRandomColor());
2153 aMgr->finishOperation();
2154 updateCommandStatus();
2157 //**************************************************************
2158 void setDeflection(ResultPtr theResult, const double theDeflection)
2160 if (!theResult.get())
2163 AttributeDoublePtr aDeflectionAttr = theResult->data()->real(ModelAPI_Result::DEFLECTION_ID());
2164 if (aDeflectionAttr.get() != NULL)
2165 aDeflectionAttr->setValue(theDeflection);
2168 //**************************************************************
2169 void setTransparency(ResultPtr theResult, double theTransparency)
2171 if (!theResult.get())
2174 AttributeDoublePtr anAttribute = theResult->data()->real(ModelAPI_Result::TRANSPARENCY_ID());
2175 if (anAttribute.get() != NULL)
2176 anAttribute->setValue(theTransparency);
2179 //**************************************************************
2180 void setTransparency(double theTransparency, const QObjectPtrList& theObjects)
2182 foreach(ObjectPtr anObj, theObjects) {
2183 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
2184 if (aResult.get() != NULL) {
2185 ResultCompSolidPtr aCompsolidResult =
2186 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
2187 if (aCompsolidResult.get() != NULL) { // change property for all sub-solids
2188 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
2189 setTransparency(aCompsolidResult->subResult(i), theTransparency);
2192 setTransparency(aResult, theTransparency);
2197 //**************************************************************
2198 void XGUI_Workshop::changeDeflection(const QObjectPtrList& theObjects)
2200 AttributeDoublePtr aDoubleAttr;
2201 // 1. find the current property of the object. This is a property of AIS presentation
2202 // The objects are iterated until a first valid property is found
2203 double aDeflection = -1;
2204 foreach(ObjectPtr anObject, theObjects) {
2205 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
2206 if (aResult.get()) {
2207 aDeflection = XGUI_CustomPrs::getResultDeflection(aResult);
2210 // TODO: remove the obtaining a property from the AIS object
2211 // this does not happen never because:
2212 // 1. The property can be changed only on results
2213 // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
2214 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
2215 if (anAISObj.get()) {
2216 aDeflection = anAISObj->getDeflection();
2219 if (aDeflection > 0)
2222 if (aDeflection < 0)
2225 if (!abortAllOperations())
2227 // 2. show the dialog to change the value
2228 XGUI_DeflectionDialog* aDlg = new XGUI_DeflectionDialog(desktop());
2229 aDlg->setDeflection(aDeflection);
2230 aDlg->move(QCursor::pos());
2231 bool isDone = aDlg->exec() == QDialog::Accepted;
2235 // 3. abort the previous operation and start a new one
2236 SessionPtr aMgr = ModelAPI_Session::get();
2237 QString aDescription = contextMenuMgr()->action("DEFLECTION_CMD")->text();
2238 aMgr->startOperation(aDescription.toStdString());
2240 // 4. set the value to all results
2241 aDeflection = aDlg->getDeflection();
2242 foreach(ObjectPtr anObj, theObjects) {
2243 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
2244 if (aResult.get() != NULL) {
2245 ResultCompSolidPtr aCompsolidResult =
2246 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
2247 if (aCompsolidResult.get() != NULL) { // change property for all sub-solids
2248 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
2249 setDeflection(aCompsolidResult->subResult(i), aDeflection);
2252 setDeflection(aResult, aDeflection);
2255 aMgr->finishOperation();
2256 updateCommandStatus();
2259 //**************************************************************
2260 void XGUI_Workshop::changeTransparency(const QObjectPtrList& theObjects)
2262 AttributeDoublePtr aDoubleAttr;
2263 // 1. find the current property of the object. This is a property of AIS presentation
2264 // The objects are iterated until a first valid property is found
2265 double aCurrentValue = -1;
2266 foreach(ObjectPtr anObject, theObjects) {
2267 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
2268 if (aResult.get()) {
2269 aCurrentValue = XGUI_CustomPrs::getResultTransparency(aResult);
2272 // TODO: remove the obtaining a property from the AIS object
2273 // this does not happen never because:
2274 // 1. The property can be changed only on results
2275 // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
2276 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
2277 if (anAISObj.get()) {
2278 aCurrentValue = anAISObj->getDeflection();
2281 if (aCurrentValue > 0)
2284 if (aCurrentValue < 0)
2287 if (!abortAllOperations())
2290 // 2. show the dialog to change the value
2291 XGUI_PropertyDialog* aDlg = new XGUI_PropertyDialog(desktop());
2292 aDlg->setWindowTitle("Transparency");
2293 XGUI_TransparencyWidget* aTransparencyWidget = new XGUI_TransparencyWidget(aDlg);
2294 connect(aTransparencyWidget, SIGNAL(transparencyValueChanged()),
2295 this, SLOT(onTransparencyValueChanged()));
2296 connect(aTransparencyWidget, SIGNAL(previewStateChanged()),
2297 this, SLOT(onPreviewStateChanged()));
2298 aDlg->setContent(aTransparencyWidget);
2299 aTransparencyWidget->setValue(aCurrentValue);
2301 // 3. abort the previous operation and start a new one
2302 SessionPtr aMgr = ModelAPI_Session::get();
2303 QString aDescription = contextMenuMgr()->action("TRANSPARENCY_CMD")->text();
2304 aMgr->startOperation(aDescription.toStdString());
2306 aDlg->move(QCursor::pos());
2307 bool isDone = aDlg->exec() == QDialog::Accepted;
2311 // 4. set the value to all results
2312 aCurrentValue = aTransparencyWidget->getValue();
2313 setTransparency(aCurrentValue, theObjects);
2315 aMgr->finishOperation();
2316 updateCommandStatus();
2319 //**************************************************************
2320 void XGUI_Workshop::onTransparencyValueChanged()
2322 XGUI_TransparencyWidget* aTransparencyWidget = (XGUI_TransparencyWidget*)sender();
2323 if (!aTransparencyWidget || !aTransparencyWidget->isPreviewNeeded())
2326 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
2327 setTransparency(aTransparencyWidget->getValue(), anObjects);
2328 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2331 //**************************************************************
2332 void XGUI_Workshop::onPreviewStateChanged()
2334 XGUI_TransparencyWidget* aTransparencyWidget = (XGUI_TransparencyWidget*)sender();
2335 if (!aTransparencyWidget || !aTransparencyWidget->isPreviewNeeded())
2338 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
2339 setTransparency(aTransparencyWidget->getValue(), anObjects);
2340 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2343 //**************************************************************
2344 #define SET_DISPLAY_GROUP(aGroupName, aDisplay) \
2345 for (int i = 0; i < aDoc->size(aGroupName); i++) { \
2346 aDoc->object(aGroupName, i)->setDisplayed(aDisplay); \
2349 //******************************************************
2350 void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible)
2353 std::set<ObjectPtr> anObjects;
2354 foreach (ObjectPtr aObj, theList) {
2355 anObjects.insert(aObj);
2357 if (!prepareForDisplay(anObjects))
2361 foreach (ObjectPtr aObj, theList) {
2362 aObj->setDisplayed(isVisible);
2364 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2365 myObjectBrowser->updateAllIndexes();
2368 //**************************************************************
2369 void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList)
2371 // Hide all displayed objects
2372 QObjectPtrList aList = myDisplayer->displayedObjects();
2373 foreach (ObjectPtr aObj, aList) {
2374 if (module()->canEraseObject(aObj))
2375 aObj->setDisplayed(false);
2377 //Do not use eraseAll if you didn't send Redisplay event:
2378 //all objects are erased from viewer, but considered as displayed in displayer
2379 // Problem in bug 2218
2380 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2382 //issue #2159 Hide all incomplete behavior
2383 viewer()->eraseAll();
2386 std::set<ObjectPtr> anObjects;
2387 foreach (ObjectPtr aObj, theList) {
2388 anObjects.insert(aObj);
2391 if (!prepareForDisplay(anObjects))
2394 // Show only objects from the list
2395 foreach (ObjectPtr aObj, theList) {
2396 aObj->setDisplayed(true);
2398 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2400 // Necessary for update icons in ObjectBrowser on Linux
2401 myObjectBrowser->updateAllIndexes();
2404 //**************************************************************
2405 void XGUI_Workshop::registerValidators() const
2407 SessionPtr aMgr = ModelAPI_Session::get();
2408 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
2411 //**************************************************************
2412 void XGUI_Workshop::displayDocumentResults(DocumentPtr theDoc)
2416 displayGroupResults(theDoc, ModelAPI_ResultConstruction::group());
2417 displayGroupResults(theDoc, ModelAPI_ResultBody::group());
2420 //**************************************************************
2421 void XGUI_Workshop::displayGroupResults(DocumentPtr theDoc, std::string theGroup)
2423 for (int i = 0; i < theDoc->size(theGroup); i++)
2424 theDoc->object(theGroup, i)->setDisplayed(true);
2425 //displayObject(theDoc->object(theGroup, i));
2426 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2429 //**************************************************************
2430 void XGUI_Workshop::setDisplayMode(const QObjectPtrList& theList, int theMode)
2432 foreach(ObjectPtr aObj, theList) {
2433 myDisplayer->setDisplayMode(aObj, (XGUI_Displayer::DisplayMode)theMode, false);
2435 ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aObj);
2436 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
2437 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
2438 myDisplayer->setDisplayMode(aCompsolidResult->subResult(i),
2439 (XGUI_Displayer::DisplayMode)theMode, false);
2443 if (theList.size() > 0)
2444 myDisplayer->updateViewer();
2447 //**************************************************************
2448 void XGUI_Workshop::closeDocument()
2450 ModuleBase_Operation* anOperation = operationMgr()->currentOperation();
2451 while (anOperation) {
2452 anOperation->abort();
2453 anOperation = operationMgr()->currentOperation();
2455 //myDisplayer->closeLocalContexts();
2456 myDisplayer->eraseAll();
2457 objectBrowser()->clearContent();
2459 module()->closeDocument();
2460 // we need to clear viewer (with created filters) to do not have problems in 2nd SALOME study
2461 module()->clearViewer();
2464 // data model need not process the document's signals about objects modifications as
2465 // the document is closed
2466 //bool isBlocked = objectBrowser()->dataModel()->blockEventsProcessing(true);
2468 SessionPtr aMgr = ModelAPI_Session::get();
2471 //objectBrowser()->dataModel()->blockEventsProcessing(isBlocked);
2474 //******************************************************
2475 void XGUI_Workshop::addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot)
2477 XGUI_HistoryMenu* aMenu = NULL;
2478 if (isSalomeMode()) {
2479 QAction* anAction = qobject_cast<QAction*>(theObject);
2482 aMenu = new XGUI_HistoryMenu(anAction);
2484 QToolButton* aButton = qobject_cast<QToolButton*>(theObject);
2485 aMenu = new XGUI_HistoryMenu(aButton);
2487 connect(this, theSignal, aMenu, SLOT(setHistory(const QList<ActionInfo>&)));
2488 connect(aMenu, SIGNAL(actionSelected(int)), this, theSlot);
2491 //******************************************************
2492 QList<ActionInfo> XGUI_Workshop::processHistoryList(const std::list<std::string>& theList) const
2494 QList<ActionInfo> aResult;
2495 std::list<std::string>::const_iterator it = theList.cbegin();
2496 for (; it != theList.cend(); it++) {
2497 QString anId = QString::fromStdString(*it);
2498 bool isEditing = anId.endsWith(ModuleBase_OperationFeature::EditSuffix());
2500 anId.chop(ModuleBase_OperationFeature::EditSuffix().size());
2503 QAction* aContextMenuAct = myContextMenuMgr->actionByName(anId);
2504 if (aContextMenuAct) {
2505 anInfo.initFrom(aContextMenuAct);
2507 anInfo = myActionsMgr->actionInfoById(anId);
2510 anInfo.text = anInfo.text.prepend("Modify ");
2517 //******************************************************
2518 void XGUI_Workshop::setStatusBarMessage(const QString& theMessage)
2521 salomeConnector()->putInfo(theMessage, -1);
2523 myMainWindow->putInfo(theMessage, -1);
2528 //******************************************************
2529 void XGUI_Workshop::synchronizeViewer()
2531 SessionPtr aMgr = ModelAPI_Session::get();
2532 QList<DocumentPtr> aDocs;
2533 aDocs.append(aMgr->activeDocument());
2534 aDocs.append(aMgr->moduleDocument());
2536 foreach(DocumentPtr aDoc, aDocs) {
2537 synchronizeGroupInViewer(aDoc, ModelAPI_ResultConstruction::group(), false);
2538 synchronizeGroupInViewer(aDoc, ModelAPI_ResultBody::group(), false);
2539 synchronizeGroupInViewer(aDoc, ModelAPI_ResultPart::group(), false);
2540 synchronizeGroupInViewer(aDoc, ModelAPI_ResultGroup::group(), false);
2544 //******************************************************
2545 void XGUI_Workshop::synchronizeGroupInViewer(const DocumentPtr& theDoc,
2546 const std::string& theGroup,
2547 bool theUpdateViewer)
2550 int aSize = theDoc->size(theGroup);
2551 for (int i = 0; i < aSize; i++) {
2552 aObj = theDoc->object(theGroup, i);
2553 if (aObj->isDisplayed()) {
2554 // Hide the presentation with an empty shape. But isDisplayed state of the object should not
2555 // be changed to the object becomes visible when the shape becomes not empty
2556 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
2557 if (aRes.get() && (!aRes->shape().get() || aRes->shape()->isNull()))
2559 myDisplayer->display(aObj, false);
2562 if (theUpdateViewer)
2563 myDisplayer->updateViewer();
2567 //******************************************************
2568 void XGUI_Workshop::highlightResults(const QObjectPtrList& theObjects)
2570 FeaturePtr aFeature;
2571 QObjectPtrList aSelList = theObjects;
2572 bool aHasHidden = false;
2573 foreach(ObjectPtr aObj, theObjects) {
2574 aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
2575 if (aFeature.get()) {
2576 std::list<ResultPtr> aResults;
2577 ModelAPI_Tools::allResults(aFeature, aResults);
2578 std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aIt;
2579 for(aIt = aResults.cbegin(); aIt != aResults.cend(); aIt++) {
2580 aHasHidden |= (*aIt)->isConcealed();
2581 aSelList.append(*aIt);
2585 if (aSelList.count() > theObjects.count()) {
2586 // if something was found
2587 bool aBlocked = objectBrowser()->blockSignals(true);
2588 objectBrowser()->setObjectsSelected(aSelList);
2589 objectBrowser()->blockSignals(aBlocked);
2592 QMessageBox::information(desktop(), tr("Find results"),
2593 tr("Results not found"), QMessageBox::Ok);
2596 //******************************************************
2597 void XGUI_Workshop::highlightFeature(const QObjectPtrList& theObjects)
2600 QObjectPtrList aSelList = theObjects;
2601 FeaturePtr aFeature;
2602 foreach(ObjectPtr aObj, theObjects) {
2603 aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
2604 if (aResult.get()) {
2605 aFeature = ModelAPI_Feature::feature(aResult);
2606 if (aFeature.get()) {
2607 aSelList.append(aFeature);
2611 if (aSelList.count() > theObjects.count()) {
2612 // if something was found
2613 bool aBlocked = objectBrowser()->blockSignals(true);
2614 objectBrowser()->setObjectsSelected(aSelList);
2615 objectBrowser()->blockSignals(aBlocked);
2619 void XGUI_Workshop::insertFeatureFolder()
2621 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
2622 if (aObjects.isEmpty())
2624 ObjectPtr aObj = aObjects.first();
2625 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
2626 if (aFeature.get() == NULL)
2628 SessionPtr aMgr = ModelAPI_Session::get();
2629 DocumentPtr aDoc = aMgr->activeDocument();
2631 QString aDescription = contextMenuMgr()->action("INSERT_FOLDER_CMD")->text();
2633 aMgr->startOperation(aDescription.toStdString());
2634 aDoc->addFolder(aFeature);
2635 aMgr->finishOperation();
2637 updateCommandStatus();
2641 void XGUI_Workshop::insertToFolder(bool isBefore)
2643 std::list<FeaturePtr> aFeatures = mySelector->getSelectedFeatures();
2644 if (aFeatures.empty())
2647 SessionPtr aMgr = ModelAPI_Session::get();
2648 DocumentPtr aDoc = aMgr->activeDocument();
2650 FolderPtr aFolder = isBefore? aDoc->findFolderAbove(aFeatures):
2651 aDoc->findFolderBelow(aFeatures);
2655 QString aDescription = contextMenuMgr()->action(
2656 isBefore ? "ADD_TO_FOLDER_BEFORE_CMD" : "ADD_TO_FOLDER_AFTER_CMD")->text();
2658 aMgr->startOperation(aDescription.toStdString());
2659 aDoc->moveToFolder(aFeatures, aFolder);
2660 aMgr->finishOperation();
2662 updateCommandStatus();
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();
2675 QString aDescription = contextMenuMgr()->action(
2676 isBefore ? "ADD_OUT_FOLDER_BEFORE_CMD" : "ADD_OUT_FOLDER_AFTER_CMD")->text();
2678 aMgr->startOperation(aDescription.toStdString());
2679 aDoc->removeFromFolder(aFeatures, isBefore);
2680 aMgr->finishOperation();
2682 updateCommandStatus();