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::onAcceptPlusActionClicked()
533 QAction* anAction = dynamic_cast<QAction*>(sender());
534 XGUI_OperationMgr* anOperationMgr = operationMgr();
535 if (anOperationMgr) {
536 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
537 (anOperationMgr->currentOperation());
539 if (myOperationMgr->commitOperation())
540 module()->launchOperation(aFOperation->id(), false);
545 //******************************************************
546 void XGUI_Workshop::onPreviewActionClicked()
548 ModuleBase_IPropertyPanel* aPanel = propertyPanel();
550 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
551 if (anActiveWidget && anActiveWidget->getValueState() == ModuleBase_ModelWidget::ModifiedInPP) {
552 anActiveWidget->storeValue();
555 std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
556 new Events_Message(Events_Loop::eventByName(EVENT_PREVIEW_REQUESTED)));
557 Events_Loop::loop()->send(aMsg);
560 //******************************************************
561 void XGUI_Workshop::deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer)
563 if (!myModule->canActivateSelection(theObject)) {
564 if (selectionActivate()->isActive(theObject)) {
565 QObjectPtrList anObjects;
566 anObjects.append(theObject);
567 myDisplayer->deactivateObjects(anObjects, theUpdateViewer);
572 //******************************************************
573 bool XGUI_Workshop::isFeatureOfNested(const FeaturePtr& theFeature)
575 bool aHasNested = false;
576 std::string aFeatureKind = theFeature->getKind();
578 XGUI_SalomeConnector* aSalomeConnector = salomeConnector();
579 if (aSalomeConnector->isFeatureOfNested(actionsMgr()->action(aFeatureKind.c_str())))
582 AppElements_MainMenu* aMenuBar = mainWindow()->menuObject();
583 AppElements_Command* aCommand = aMenuBar->feature(aFeatureKind.c_str());
584 if (aCommand && aCommand->button()->additionalButtonWidget())
590 //******************************************************
591 void XGUI_Workshop::fillPropertyPanel(ModuleBase_Operation* theOperation)
593 ModuleBase_OperationFeature* aFOperation =
594 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
598 showPanel(myPropertyPanel);
599 myPropertyPanel->cleanContent();
601 QList<ModuleBase_ModelWidget*> aWidgets;
602 if (!module()->createWidgets(theOperation, aWidgets)) {
603 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
604 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), myModuleConnector);
605 aFactory.createWidget(myPropertyPanel->contentWidget());
606 aWidgets = aFactory.getModelWidgets();
609 // check compatibility of feature and widgets
610 FeaturePtr aFeature = aFOperation->feature();
611 std::string aFeatureKind = aFeature->getKind();
612 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
613 if (aWidget->usesAttribute()) {
614 if (!aWidget->attributeID().empty() && !aFeature->attribute(aWidget->attributeID()).get()) {
615 std::string anErrorMsg = "The feature '%1' has no attribute '%2' used by widget '%3'.";
616 Events_InfoMessage("XGUI_Workshop", anErrorMsg)
617 .arg(aFeatureKind).arg(aWidget->attributeID())
618 .arg(aWidget->metaObject()->className()).send();
619 myPropertyPanel->cleanContent();
624 // for performance purpose, flush should be done after all controls are filled
625 bool isUpdateFlushed = false;
626 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
627 bool isStoreValue = !aFOperation->isEditOperation() &&
628 !aWidget->getDefaultValue().empty() &&
629 !aWidget->isComputedDefault();
630 aWidget->setFeature(aFeature, isStoreValue, isUpdateFlushed);
632 aWidget->restoreValue();
633 aWidget->enableFocusProcessing();
635 // update visible state of Preview button
636 std::shared_ptr<Config_FeatureMessage> aFeatureInfo;
638 aFeatureInfo = mySalomeConnector->featureInfo(aFeatureKind.c_str());
640 AppElements_MainMenu* aMenuBar = mainWindow()->menuObject();
641 AppElements_Command* aCommand = aMenuBar->feature(aFeatureKind.c_str());
643 aFeatureInfo = aCommand->featureMessage();
645 bool anIsAutoPreview = true;
646 if (aFeatureInfo.get())
647 anIsAutoPreview = aFeatureInfo->isAutoPreview();
649 std::string aXmlCfg, aDescription;
650 module()->getXMLRepresentation(aFeatureKind, aXmlCfg, aDescription);
651 ModuleBase_WidgetFactory aFactory(aXmlCfg, moduleConnector());
652 anIsAutoPreview = aFactory.widgetAPI()->getBooleanAttribute(FEATURE_AUTO_PREVIEW, true);
655 if (!anIsAutoPreview) {
656 myPropertyPanel->findButton(PROP_PANEL_PREVIEW)->setVisible(true);
657 // send signal about preview should not be computed automatically, click on preview
658 // button should initiate it
659 std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
660 new Events_Message(Events_Loop::eventByName(EVENT_PREVIEW_BLOCKED)));
661 Events_Loop::loop()->send(aMsg);
663 // if update happens after preview is blocked, it does nothing when blocked
664 // it improves performance for valid objects on feature start
665 ModuleBase_Tools::flushUpdated(aFeature);
667 myPropertyPanel->setModelWidgets(aWidgets);
668 aFOperation->setPropertyPanel(myPropertyPanel);
670 myModule->propertyPanelDefined(theOperation);
672 #ifndef DEBUG_FEATURE_NAME
673 myPropertyPanel->setWindowTitle(theOperation->getDescription()->description());
675 std::string aFeatureName = aFeature->name();
676 myPropertyPanel->setWindowTitle(QString("%1: %2")
677 .arg(theOperation->getDescription()->description())
678 .arg(aFeatureName.c_str()));
681 myErrorMgr->setPropertyPanel(myPropertyPanel);
684 //******************************************************
685 void XGUI_Workshop::connectToPropertyPanel(const bool isToConnect)
687 XGUI_PropertyPanel* aPropertyPanel = propertyPanel();
688 if (aPropertyPanel) {
689 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
690 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
691 myModule->connectToPropertyPanel(aWidget, isToConnect);
693 connect(aWidget, SIGNAL(valueStateChanged(int)), this, SLOT(onWidgetStateChanged(int)));
694 connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
695 connect(aWidget, SIGNAL(objectUpdated()), this, SLOT(onWidgetObjectUpdated()));
698 disconnect(aWidget, SIGNAL(valueStateChanged(int)), this, SLOT(onWidgetStateChanged(int)));
699 disconnect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
700 disconnect(aWidget, SIGNAL(objectUpdated()), this, SLOT(onWidgetObjectUpdated()));
706 //******************************************************
707 void XGUI_Workshop::onOperationResumed(ModuleBase_Operation* theOperation)
709 setGrantedFeatures(theOperation);
711 if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
712 fillPropertyPanel(theOperation);
713 connectToPropertyPanel(true);
715 updateCommandStatus();
717 myModule->operationResumed(theOperation);
720 //******************************************************
721 void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
723 updateCommandStatus();
725 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
730 ModuleBase_ISelection* aSel = mySelector->selection();
731 QObjectPtrList aObj = aSel->selectedPresentations();
732 //!< No need for property panel
733 hidePanel(myPropertyPanel);
734 myPropertyPanel->cleanContent();
736 connectToPropertyPanel(false);
737 myModule->operationStopped(aFOperation);
739 // the deactivated objects of the current operation should be activated back.
740 // They were deactivated on operation start or an object redisplay
741 QObjectPtrList anObjects;
742 FeaturePtr aFeature = aFOperation->feature();
743 if (aFeature.get()) { // feature may be not created (plugin load fail)
744 if (myDisplayer->isVisible(aFeature) && !selectionActivate()->isActive(aFeature))
745 anObjects.append(aFeature);
746 std::list<ResultPtr> aResults;
747 ModelAPI_Tools::allResults(aFeature, aResults);
748 std::list<ResultPtr>::const_iterator aIt;
749 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
750 ResultPtr anObject = *aIt;
751 if (myDisplayer->isVisible(anObject) && !selectionActivate()->isActive(anObject)) {
752 anObjects.append(anObject);
756 activateObjectsSelection(anObjects);
759 //******************************************************
760 void XGUI_Workshop::onOperationCommitted(ModuleBase_Operation* theOperation)
762 myModule->operationCommitted(theOperation);
765 //******************************************************
766 void XGUI_Workshop::onOperationAborted(ModuleBase_Operation* theOperation)
768 myModule->operationAborted(theOperation);
771 //******************************************************
772 void XGUI_Workshop::setGrantedFeatures(ModuleBase_Operation* theOperation)
774 ModuleBase_OperationFeature* aFOperation =
775 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
779 QStringList aGrantedIds;
780 if (isSalomeMode()) {
781 const std::shared_ptr<Config_FeatureMessage>& anInfo =
782 mySalomeConnector->featureInfo(theOperation->id());
784 aGrantedIds = QString::fromStdString(anInfo->nestedFeatures())
785 .split(" ", QString::SkipEmptyParts);
788 aGrantedIds = myActionsMgr->nestedCommands(theOperation->id());
790 ModuleBase_IModule* aModule = module();
792 aModule->grantedOperationIds(theOperation, aGrantedIds);
794 aFOperation->setGrantedOperationIds(aGrantedIds);
797 //******************************************************
798 void XGUI_Workshop::saveDocument(const QString& theName, std::list<std::string>& theFileNames)
800 QApplication::restoreOverrideCursor();
801 SessionPtr aMgr = ModelAPI_Session::get();
803 std::list<DocumentPtr> aDocList = aMgr->allOpenedDocuments();
804 std::list<DocumentPtr>::const_iterator aIt;
805 for (aIt = aDocList.cbegin(); aIt != aDocList.cend(); aIt++) {
806 std::list<bool> aState = myObjectBrowser->getStateForDoc(*aIt);
807 (*aIt)->storeNodesState(aState);
810 aMgr->save(theName.toLatin1().constData(), theFileNames);
812 QApplication::restoreOverrideCursor();
815 //******************************************************
816 bool XGUI_Workshop::abortAllOperations()
818 return myOperationMgr->abortAllOperations();
821 //******************************************************
822 void XGUI_Workshop::operationStarted(ModuleBase_Operation* theOperation)
824 setGrantedFeatures(theOperation);
825 if (!theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
826 updateCommandStatus();
829 myModule->operationStarted(theOperation);
833 //******************************************************
834 void XGUI_Workshop::onOpen()
836 if(!abortAllOperations())
838 //save current file before close if modified
839 SessionPtr aSession = ModelAPI_Session::get();
840 if (aSession->isModified()) {
841 //TODO(sbh): re-launch the app?
842 int anAnswer = QMessageBox::question(
843 desktop(), tr("Save current file"),
844 tr("The document is modified, save before opening another?"),
845 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
846 if (anAnswer == QMessageBox::Save) {
848 } else if (anAnswer == QMessageBox::Cancel) {
854 //show file dialog, check if readable and open
855 QString aDirectory = QFileDialog::getExistingDirectory(desktop(), tr("Select directory"));
856 openDirectory(aDirectory);
859 //******************************************************
860 void XGUI_Workshop::openDirectory(const QString& theDirectory)
862 myCurrentDir = theDirectory;
863 if (myCurrentDir.isEmpty())
866 QFileInfo aFileInfo(myCurrentDir);
867 if (!aFileInfo.exists() || !aFileInfo.isReadable()) {
868 QMessageBox::critical(desktop(), tr("Warning"), tr("Unable to open the file."));
873 QApplication::setOverrideCursor(Qt::WaitCursor);
874 module()->closeDocument();
875 SessionPtr aSession = ModelAPI_Session::get();
876 aSession->closeAll();
877 aSession->load(myCurrentDir.toLatin1().constData());
878 myObjectBrowser->rebuildDataTree();
880 // Open first level of data tree
881 DocumentPtr aRootDoc = aSession->moduleDocument();
882 std::list<bool> aStates;
883 aRootDoc->restoreNodesState(aStates);
884 myObjectBrowser->setStateForDoc(aRootDoc, aStates);
886 updateCommandStatus();
888 myMainWindow->setCurrentDir(myCurrentDir, true);
892 bool aNewPart = Config_PropManager::boolean("Plugins", "create_part_by_start");
895 DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
896 int aSize = aRootDoc->size(ModelAPI_ResultPart::group());
898 ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), 0);
899 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
906 QApplication::restoreOverrideCursor();
909 //******************************************************
910 void XGUI_Workshop::onNew()
912 QApplication::setOverrideCursor(Qt::WaitCursor);
913 if (objectBrowser() == 0) {
915 mySelector->connectViewers();
917 myViewerProxy->connectToViewer();
920 myMainWindow->showPythonConsole();
921 QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
922 aWnd->showMaximized();
923 updateCommandStatus();
925 myContextMenuMgr->connectViewer();
926 QApplication::restoreOverrideCursor();
930 //******************************************************
931 void XGUI_Workshop::onExit()
933 SessionPtr aMgr = ModelAPI_Session::get();
934 if (aMgr->isModified()) {
935 int anAnswer = QMessageBox::question(
936 myMainWindow, tr("Save current file"), tr("The document is modified, save before exit?"),
937 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
938 if (anAnswer == QMessageBox::Save) {
939 bool saved = onSave();
943 } else if (anAnswer == QMessageBox::Cancel) {
950 //******************************************************
951 void XGUI_Workshop::onPreferences()
953 ModuleBase_Prefs aModif;
954 ModuleBase_Preferences::editPreferences(aModif);
955 if (aModif.size() > 0) {
957 foreach (ModuleBase_Pref aPref, aModif)
959 aSection = aPref.first;
960 if (aSection == ModuleBase_Preferences::VIEWER_SECTION) {
961 myMainWindow->viewer()->updateFromResources();
962 } else if (aSection == ModuleBase_Preferences::MENU_SECTION) {
963 myMainWindow->menuObject()->updateFromResources();
966 displayer()->redisplayObjects();
971 //******************************************************
972 void XGUI_Workshop::onTrihedronVisibilityChanged(bool theState)
974 XGUI_Displayer* aDisplayer = displayer();
976 aDisplayer->displayTrihedron(theState);
979 //******************************************************
980 bool XGUI_Workshop::onSave()
982 if(!myOperationMgr->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
984 if (myCurrentDir.isEmpty()) {
987 std::list<std::string> aFiles;
988 saveDocument(myCurrentDir, aFiles);
989 updateCommandStatus();
991 myMainWindow->setModifiedState(false);
996 //******************************************************
997 bool XGUI_Workshop::onSaveAs()
999 if(!myOperationMgr->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
1001 QFileDialog dialog(desktop());
1002 dialog.setWindowTitle(tr("Select directory to save files..."));
1003 dialog.setFileMode(QFileDialog::Directory);
1004 dialog.setFilter(QDir::AllDirs);
1005 dialog.setOptions(QFileDialog::HideNameFilterDetails | QFileDialog::ShowDirsOnly);
1006 dialog.setViewMode(QFileDialog::Detail);
1008 if (!dialog.exec()) {
1012 QString aTempDir = dialog.selectedFiles().first();
1013 QDir aDir(aTempDir);
1014 if (aDir.exists() && !aDir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries).isEmpty()) {
1015 int answer = QMessageBox::question(
1017 // Title of the dialog which asks user if he wants to save study
1018 // in existing non-empty folder
1020 tr("The directory already contains some files, save anyway?"),
1021 QMessageBox::Save | QMessageBox::Cancel);
1022 if (answer == QMessageBox::Cancel) {
1026 myCurrentDir = aTempDir;
1028 myMainWindow->setCurrentDir(myCurrentDir, false);
1029 myMainWindow->setModifiedState(false);
1034 //******************************************************
1035 void XGUI_Workshop::onUndo(int theTimes)
1037 processUndoRedo(ActionUndo, theTimes);
1038 myObjectBrowser->updateAllIndexes(1);
1041 //******************************************************
1042 void XGUI_Workshop::onRedo(int theTimes)
1044 processUndoRedo(ActionRedo, theTimes);
1045 myObjectBrowser->updateAllIndexes(1);
1048 //******************************************************
1049 void XGUI_Workshop::processUndoRedo(const ModuleBase_ActionType theActionType, int theTimes)
1051 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1052 if (anActiveWidget) {
1053 ActionIntParamPtr aParam(new ModuleBase_ActionIntParameter(theTimes));
1054 if (anActiveWidget->processAction(theActionType, aParam))
1057 // the viewer update should be blocked in order to avoid the features blinking. For the created
1058 // feature a results are created, the flush of the created signal caused the viewer redisplay for
1059 // each created result. After a redisplay signal is flushed. So, the viewer update is blocked
1060 // until redo of all possible objects happens
1061 bool isUpdateEnabled = myDisplayer->enableUpdateViewer(false);
1063 SessionPtr aMgr = ModelAPI_Session::get();
1064 if (aMgr->isOperation()) {
1065 XGUI_OperationMgr* aOpMgr = operationMgr();
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 if (aOpMgr->canStopOperation(aOpMgr->currentOperation()))
1070 aOpMgr->abortOperation(aOpMgr->currentOperation());
1073 myDisplayer->enableUpdateViewer(isUpdateEnabled);
1077 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
1078 std::list<std::string> anActionList = theActionType == ActionUndo ? aMgr->undoList()
1080 std::list<std::string>::const_iterator aIt = anActionList.cbegin();
1081 for (int i = 0; (i < theTimes) && (aIt != anActionList.cend()); ++i, ++aIt) {
1082 if (theActionType == ActionUndo)
1087 if (QString((*aIt).c_str()) == MOVE_TO_END_COMMAND)
1088 myObjectBrowser->rebuildDataTree();
1090 operationMgr()->updateApplyOfOperations();
1091 facesPanel()->reset(true);
1092 updateCommandStatus();
1094 // unblock the viewer update functionality and make update on purpose
1095 myDisplayer->enableUpdateViewer(isUpdateEnabled);
1096 myDisplayer->updateViewer();
1097 // Clear messages in status bar from previous operations if exists
1098 setStatusBarMessage("");
1101 //******************************************************
1102 void XGUI_Workshop::onWidgetStateChanged(int thePreviousState)
1104 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1105 //ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
1106 //if (anOperation) {
1107 // ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1109 // anActiveWidget = aPanel->activeWidget();
1112 operationMgr()->onValidateOperation();
1114 myModule->widgetStateChanged(thePreviousState);
1117 //******************************************************
1118 void XGUI_Workshop::onValuesChanged()
1120 ModuleBase_ModelWidget* aSenderWidget = (ModuleBase_ModelWidget*)(sender());
1121 if (!aSenderWidget || aSenderWidget->canAcceptFocus())
1124 ModuleBase_ModelWidget* anActiveWidget = 0;
1125 ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
1127 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1129 anActiveWidget = aPanel->activeWidget();
1131 if (anActiveWidget) {
1132 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1134 if (aWidgetValidated)
1135 aWidgetValidated->clearValidatedCash();
1139 //******************************************************
1140 void XGUI_Workshop::onWidgetObjectUpdated()
1142 operationMgr()->onValidateOperation();
1145 //******************************************************
1146 ModuleBase_IModule* XGUI_Workshop::loadModule(const QString& theModule)
1148 QString libName = QString::fromStdString(library(theModule.toStdString()));
1149 if (libName.isEmpty()) {
1150 qWarning(qPrintable(tr("Information about module \"%1\" doesn't exist.").arg(theModule)));
1155 CREATE_FUNC crtInst = 0;
1158 HINSTANCE modLib = ::LoadLibrary((LPTSTR) qPrintable(libName));
1162 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
1163 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
1164 QString aMsg((char*) &lpMsgBuf);
1165 err = QString("Failed to load %1. %2").arg(libName).arg(aMsg);
1166 ::LocalFree(lpMsgBuf);
1168 crtInst = (CREATE_FUNC) ::GetProcAddress(modLib, CREATE_MODULE);
1172 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
1173 | FORMAT_MESSAGE_IGNORE_INSERTS,
1174 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
1175 QString aMsg((char*) &lpMsgBuf);
1176 err = QString("Failed to find %1 function. %2").arg( CREATE_MODULE).arg(aMsg);
1177 ::LocalFree(lpMsgBuf);
1181 void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY | RTLD_GLOBAL );
1183 err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
1185 crtInst = (CREATE_FUNC)dlsym( modLib, CREATE_MODULE );
1187 err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() );
1192 ModuleBase_IModule* aModule = crtInst ? crtInst(myModuleConnector) : 0;
1194 if (!err.isEmpty()) {
1196 Events_InfoMessage("XGUI_Workshop", err.toStdString()).send();
1198 qWarning(qPrintable(err));
1204 //******************************************************
1205 bool XGUI_Workshop::createModule()
1207 Config_ModuleReader aModuleReader;
1208 QString moduleName = QString::fromStdString(aModuleReader.getModuleName());
1209 myModule = loadModule(moduleName);
1213 //connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
1214 // myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
1215 //connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
1216 // myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
1218 myModule->createFeatures();
1220 salomeConnector()->createFeatureActions();
1222 //myActionsMgr->update();
1226 //******************************************************
1227 void XGUI_Workshop::updateCommandStatus()
1229 QList<QAction*> aCommands;
1231 aCommands = salomeConnector()->commandList();
1233 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
1234 foreach (AppElements_Command* aCmd, aMenuBar->features())
1235 aCommands.append(aCmd);
1237 SessionPtr aMgr = ModelAPI_Session::get();
1238 if (aMgr->hasModuleDocument()) {
1239 foreach(QAction* aCmd, aCommands) {
1240 QString aId = aCmd->data().toString();
1241 if (aId == "UNDO_CMD") {
1242 bool isActionEnabled = false;
1243 // if ultimate is true -> using result of operation only, or using OR combination
1244 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1245 if (anActiveWidget && anActiveWidget->canProcessAction(ActionUndo, isActionEnabled))
1246 aCmd->setEnabled(isActionEnabled);
1248 aCmd->setEnabled(myModule->canUndo());
1250 else if (aId == "REDO_CMD") {
1251 bool isActionEnabled = false;
1252 // if ultimate is true -> using result of operation only, or using OR combination
1253 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1254 if (anActiveWidget && anActiveWidget->canProcessAction(ActionRedo, isActionEnabled))
1255 aCmd->setEnabled(isActionEnabled);
1257 aCmd->setEnabled(myModule->canRedo());
1260 // Enable all commands
1261 aCmd->setEnabled(true);
1265 foreach(QAction* aCmd, aCommands) {
1266 QString aId = aCmd->data().toString();
1267 if (aId == "NEW_CMD")
1268 aCmd->setEnabled(true);
1269 else if (aId == "EXIT_CMD")
1270 aCmd->setEnabled(true);
1272 aCmd->setEnabled(false);
1275 myActionsMgr->updateCommandsStatus();
1276 emit commandStatusUpdated();
1279 //******************************************************
1280 void XGUI_Workshop::updateHistory()
1282 bool isActionEnabled = false;
1283 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1284 QList<ActionInfo> aUndoRes;
1285 QList<ActionInfo> aRedoRes;
1286 if (anActiveWidget && anActiveWidget->canProcessAction(ActionUndo, isActionEnabled)) {
1287 aUndoRes = anActiveWidget->actionsList(ActionUndo);
1288 aRedoRes = anActiveWidget->actionsList(ActionRedo);
1290 std::list<std::string> aUndoList = ModelAPI_Session::get()->undoList();
1291 aUndoRes = processHistoryList(aUndoList);
1293 std::list<std::string> aRedoList = ModelAPI_Session::get()->redoList();
1294 aRedoRes = processHistoryList(aRedoList);
1296 emit updateUndoHistory(aUndoRes);
1297 emit updateRedoHistory(aRedoRes);
1300 //******************************************************
1301 QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
1303 QDockWidget* aObjDock = new QDockWidget(theParent);
1304 aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea |
1305 Qt::RightDockWidgetArea |
1306 Qt::BottomDockWidgetArea);
1307 aObjDock->setWindowTitle(tr("Object browser"));
1308 aObjDock->setStyleSheet(
1309 "::title { position: relative; padding-left: 5px; text-align: left center }");
1310 myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock, this);
1311 myObjectBrowser->setXMLReader(myDataModelXMLReader);
1312 myModule->customizeObjectBrowser(myObjectBrowser);
1313 aObjDock->setWidget(myObjectBrowser);
1315 myContextMenuMgr->connectObjectBrowser();
1319 //******************************************************
1321 * Creates dock widgets, places them in corresponding area
1322 * and tabifies if necessary.
1324 void XGUI_Workshop::createDockWidgets()
1326 QMainWindow* aDesktop = desktop();
1327 QDockWidget* aObjDock = createObjectBrowser(aDesktop);
1328 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
1329 myPropertyPanel = new XGUI_PropertyPanel(aDesktop, myOperationMgr);
1330 myActiveControlMgr->addSelector(new XGUI_PropertyPanelSelector(myPropertyPanel));
1332 myPropertyPanel->setupActions(myActionsMgr);
1333 myPropertyPanel->setAllowedAreas(Qt::LeftDockWidgetArea |
1334 Qt::RightDockWidgetArea |
1335 Qt::BottomDockWidgetArea);
1336 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel);
1337 hidePanel(myPropertyPanel); ///<! Invisible by default
1339 myFacesPanel = new XGUI_FacesPanel(aDesktop, myModuleConnector);
1340 myActiveControlMgr->addSelector(new XGUI_FacesPanelSelector(myFacesPanel));
1341 myFacesPanel->setAllowedAreas(Qt::LeftDockWidgetArea |
1342 Qt::RightDockWidgetArea |
1343 Qt::BottomDockWidgetArea);
1344 connect(myFacesPanel, SIGNAL(closed()), myFacesPanel, SLOT(onClosed()));
1346 aDesktop->addDockWidget(
1348 Qt::RightDockWidgetArea,
1350 Qt::LeftDockWidgetArea,
1353 hidePanel(myFacesPanel); ///<! Invisible by default
1356 bool aShowOnTheRight = Config_PropManager::boolean("Plugins", "show_hide_faces");
1357 if (aShowOnTheRight) {
1358 aDesktop->addDockWidget(Qt::RightDockWidgetArea, myFacesPanel);
1359 showPanel(myFacesPanel);
1362 hideObjectBrowser();
1366 if (!aShowOnTheRight)
1369 aDesktop->tabifyDockWidget(myFacesPanel, aObjDock);
1374 #endif // HAVE_SALOME
1376 aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
1377 myPropertyPanel->installEventFilter(myOperationMgr);
1379 QAction* aOkAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept);
1380 connect(aOkAct, SIGNAL(triggered()), this, SLOT(onAcceptActionClicked()));
1382 QAction* aOkContAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptPlus);
1383 connect(aOkContAct, SIGNAL(triggered()), this, SLOT(onAcceptPlusActionClicked()));
1385 QAction* aCancelAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Abort);
1386 connect(aCancelAct, SIGNAL(triggered()), myOperationMgr, SLOT(onAbortOperation()));
1388 QAction* aPreviewAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Preview);
1389 connect(aPreviewAct, SIGNAL(triggered()), this, SLOT(onPreviewActionClicked()));
1391 connect(myPropertyPanel, SIGNAL(keyReleased(QObject*, QKeyEvent*)),
1392 myOperationMgr, SLOT(onKeyReleased(QObject*, QKeyEvent*)));
1393 connect(myPropertyPanel, SIGNAL(enterClicked(QObject*)),
1394 myOperationMgr, SLOT(onProcessEnter(QObject*)));
1397 //******************************************************
1398 void XGUI_Workshop::showPanel(QDockWidget* theDockWidget)
1400 if (theDockWidget == myPropertyPanel) {
1401 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1402 ///<! Restore ability to close panel from the window's menu
1403 aViewAct->setEnabled(true);
1405 theDockWidget->show();
1406 theDockWidget->raise();
1408 // The next code is necessary to made the property panel the active window
1409 // in order to operation manager could process key events of the panel.
1410 // otherwise they are ignored. It happens only if the same(activateWindow) is
1411 // not happened by property panel activation(e.g. resume operation of Sketch)
1412 ModuleBase_Tools::setFocus(theDockWidget, "XGUI_Workshop::showPanel()");
1415 //******************************************************
1416 void XGUI_Workshop::hidePanel(QDockWidget* theDockWidget)
1418 if (theDockWidget && theDockWidget == myPropertyPanel) {
1419 QAction* aViewAct = theDockWidget->toggleViewAction();
1420 ///<! Do not allow to show empty property panel
1421 aViewAct->setEnabled(false);
1423 theDockWidget->hide();
1425 // the property panel is active window of the desktop, when it is
1426 // hidden, it is undefined which window becomes active. By this reason
1427 // it is defined to perform the desktop as the active window.
1428 // in SALOME mode, workstack made the PyConsole the active window,
1429 // set the focus on it. As a result, shortcuts of the application, like
1430 // are processed by this console. For example Undo actions.
1431 // It is possible that this code is to be moved to SHAPER package
1432 QMainWindow* aDesktop = desktop();
1433 ModuleBase_Tools::setFocus(aDesktop, "XGUI_Workshop::hidePanel()");
1436 //******************************************************
1437 void XGUI_Workshop::showObjectBrowser()
1439 if (!isSalomeMode())
1440 myObjectBrowser->parentWidget()->show();
1443 //******************************************************
1444 void XGUI_Workshop::hideObjectBrowser()
1446 if (!isSalomeMode())
1447 myObjectBrowser->parentWidget()->hide();
1450 //******************************************************
1451 void XGUI_Workshop::salomeViewerSelectionChanged()
1453 emit salomeViewerSelection();
1456 //**************************************************************
1457 ModuleBase_IViewer* XGUI_Workshop::salomeViewer() const
1459 return mySalomeConnector->viewer();
1462 //**************************************************************
1463 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
1465 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1466 if (theId == "DELETE_CMD")
1468 else if (theId == "CLEAN_HISTORY_CMD")
1470 else if (theId == "MOVE_CMD")
1472 else if (theId == "COLOR_CMD")
1473 changeColor(aObjects);
1474 else if (theId == "DEFLECTION_CMD")
1475 changeDeflection(aObjects);
1476 #ifdef USE_TRANSPARENCY
1477 else if (theId == "TRANSPARENCY_CMD")
1478 changeTransparency(aObjects);
1480 else if (theId == "SHOW_CMD") {
1481 showObjects(aObjects, true);
1482 mySelector->updateSelectionBy(ModuleBase_ISelection::Browser);
1483 updateCommandStatus();
1485 else if (theId == "HIDE_CMD") {
1486 showObjects(aObjects, false);
1487 updateCommandStatus();
1489 else if (theId == "SHOW_ONLY_CMD") {
1490 showOnlyObjects(aObjects);
1491 mySelector->updateSelectionBy(ModuleBase_ISelection::Browser);
1492 updateCommandStatus();
1494 else if (theId == "SHADING_CMD")
1495 setDisplayMode(aObjects, XGUI_Displayer::Shading);
1496 else if (theId == "WIREFRAME_CMD")
1497 setDisplayMode(aObjects, XGUI_Displayer::Wireframe);
1498 else if (theId == "HIDEALL_CMD") {
1499 QObjectPtrList aList = myDisplayer->displayedObjects();
1500 foreach (ObjectPtr aObj, aList) {
1501 if (module()->canEraseObject(aObj))
1502 aObj->setDisplayed(false);
1504 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1506 //issue #2159 Hide all incomplete behavior
1507 viewer()->eraseAll();
1509 updateCommandStatus();
1510 // Necessary for update icons in ObjectBrowser on Linux
1511 myObjectBrowser->updateAllIndexes();
1512 } else if (theId == "SELECT_VERTEX_CMD") {
1513 setViewerSelectionMode(TopAbs_VERTEX);
1514 } else if (theId == "SELECT_EDGE_CMD") {
1515 setViewerSelectionMode(TopAbs_EDGE);
1516 } else if (theId == "SELECT_FACE_CMD") {
1517 setViewerSelectionMode(TopAbs_FACE);
1518 } else if (theId == "INSERT_FOLDER_CMD") {
1519 insertFeatureFolder();
1520 } else if (theId == "ADD_TO_FOLDER_BEFORE_CMD") {
1521 insertToFolder(true);
1522 } else if (theId == "ADD_TO_FOLDER_AFTER_CMD") {
1523 insertToFolder(false);
1524 } else if (theId == "ADD_OUT_FOLDER_BEFORE_CMD") {
1525 moveOutFolder(true);
1526 } else if (theId == "ADD_OUT_FOLDER_AFTER_CMD") {
1527 moveOutFolder(false);
1528 } else if (theId == "SELECT_RESULT_CMD") {
1529 //setViewerSelectionMode(-1);
1530 //IMP: an attempt to use result selection with other selection modes
1531 setViewerSelectionMode(ModuleBase_ResultPrs::Sel_Result);
1532 setViewerSelectionMode(TopAbs_COMPSOLID);
1533 } else if (theId == "SHOW_RESULTS_CMD") {
1534 highlightResults(aObjects);
1535 } else if (theId == "SHOW_FEATURE_CMD") {
1536 highlightFeature(aObjects);
1539 else if (theId == "TINSPECTOR_VIEW") {
1540 Handle(CDF_Application) anApplication = CDF_Session::CurrentSession()->CurrentApplication();
1541 if (!anApplication.IsNull())
1543 if (!MyTCommunicator)
1545 MyTCommunicator = new TInspector_Communicator();
1547 NCollection_List<Handle(Standard_Transient)> aParameters;
1548 aParameters.Append(anApplication);
1549 Handle(AIS_InteractiveContext) aContext = viewer()->AISContext();
1550 if (!aContext.IsNull())
1551 aParameters.Append(aContext);
1553 #ifdef DEBUG_WITH_MESSAGE_REPORT
1554 Handle(Message_Report) aContextReport = aContext->GetReport();
1555 aContext->SetReportActive (Standard_True);
1556 aContextReport->SetLimit (1000);
1557 if (!aContextReport.IsNull())
1558 aParameters.Append(aContextReport);
1560 MyVCallBack = new VInspector_CallBack();
1561 myDisplayer->setCallBack(MyVCallBack);
1563 AppElements_Viewer* aViewer = mainWindow()->viewer();
1565 aViewer->setCallBack(MyVCallBack);
1567 aParameters.Append(MyVCallBack);
1569 MyTCommunicator->RegisterPlugin("TKDFBrowser");
1570 MyTCommunicator->RegisterPlugin("TKShapeView");
1571 MyTCommunicator->RegisterPlugin("TKVInspector");
1572 #ifdef DEBUG_WITH_MESSAGE_REPORT
1573 MyTCommunicator->RegisterPlugin("TKMessageView");
1575 MyTCommunicator->RegisterPlugin("SMBrowser"); // custom plugin to view ModelAPI
1576 //MyTCommunicator->RegisterPlugin("TKSMBrowser"); // custom plugin to view ModelAPI
1578 MyTCommunicator->Init(aParameters);
1579 MyTCommunicator->Activate("TKSMBrowser"); // to have button in TInspector
1580 #ifndef DEBUG_WITH_MESSAGE_REPORT
1581 MyTCommunicator->Activate("TKVInspector"); // to have filled callback by model
1583 MyTCommunicator->Activate("TKDFBrowser");
1585 #ifdef DEBUG_WITH_MESSAGE_REPORT
1586 MyTCommunicator->Activate("TKMessageView"); // temporary
1587 MyTCommunicator->Activate("TKVInspector"); // to have filled callback by model
1590 MyTCommunicator->SetVisible(true);
1596 //**************************************************************
1597 void XGUI_Workshop::setViewerSelectionMode(int theMode)
1600 myViewerSelMode.clear();
1602 if (myViewerSelMode.contains(theMode))
1603 myViewerSelMode.removeAll(theMode);
1605 myViewerSelMode.append(theMode);
1607 selectionActivate()->updateSelectionModes();
1610 //**************************************************************
1611 void XGUI_Workshop::activateObjectsSelection(const QObjectPtrList& theList)
1614 module()->activeSelectionModes(aModes);
1615 if (aModes.isEmpty() && (myViewerSelMode.length() > 0))
1616 aModes.append(myViewerSelMode);
1617 selectionActivate()->activateObjects(aModes, theList);
1620 //**************************************************************
1621 bool XGUI_Workshop::prepareForDisplay(const std::set<ObjectPtr>& theObjects) const
1623 if (facesPanel()->isEmpty())
1626 // generate container of objects taking into account sub elments of compsolid
1627 std::set<ObjectPtr> anAllProcessedObjects;
1628 for (std::set<ObjectPtr>::const_iterator anObjectsIt = theObjects.begin();
1629 anObjectsIt != theObjects.end(); anObjectsIt++) {
1630 ObjectPtr anObject = *anObjectsIt;
1631 ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(anObject);
1632 if (aCompRes.get()) {
1633 if (aCompRes->numberOfSubs(true) == 0)
1634 anAllProcessedObjects.insert(anObject);
1636 for (int i = 0; i < aCompRes->numberOfSubs(true); i++) {
1637 ResultPtr aSubRes = aCompRes->subResult(i, true);
1638 anAllProcessedObjects.insert(aCompRes->subResult(i, true));
1643 anAllProcessedObjects.insert(anObject);
1646 // find hidden objects in faces panel
1647 std::set<ObjectPtr> aHiddenObjects;
1648 QStringList aHiddenObjectNames;
1649 for (std::set<ObjectPtr>::const_iterator anObjectsIt = anAllProcessedObjects.begin();
1650 anObjectsIt != anAllProcessedObjects.end(); anObjectsIt++) {
1651 if (!facesPanel()->isObjectHiddenByPanel(*anObjectsIt))
1653 aHiddenObjects.insert(*anObjectsIt);
1654 aHiddenObjectNames.append((*anObjectsIt)->data()->name().c_str());
1656 if (aHiddenObjects.empty()) // in parameter objects there are no hidden objects in hide face
1659 int anAnswer = QMessageBox::question(
1660 desktop(), tr("Show object"),
1661 tr("'%1'\n are hidden by %2:\nRemove objects from the panel to be displayed?")
1662 .arg(aHiddenObjectNames.join(", ")).arg(facesPanel()->windowTitle()),
1663 QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
1665 bool aToBeDisplayed = anAnswer == QMessageBox::Yes;
1667 facesPanel()->restoreObjects(aHiddenObjects);
1669 return aToBeDisplayed;
1672 //**************************************************************
1673 void XGUI_Workshop::deleteObjects()
1675 ModuleBase_IModule* aModule = module();
1676 // allow the module to delete objects, do nothing if it has succeed
1677 if (aModule->deleteObjects()) {
1678 updateCommandStatus();
1682 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1683 if (!abortAllOperations())
1686 bool hasResult = false;
1687 bool hasFeature = false;
1688 bool hasParameter = false;
1689 bool hasCompositeOwner = false;
1690 bool hasResultInHistory = false;
1691 bool hasFolder = false;
1692 ModuleBase_Tools::checkObjects(anObjects, hasResult, hasFeature, hasParameter, hasCompositeOwner,
1693 hasResultInHistory, hasFolder);
1694 if (!(hasFeature || hasParameter || hasFolder))
1698 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1699 std::set<FeaturePtr> aFeatures;
1700 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1701 ModelAPI_Tools::findAllReferences(aFeatures, aReferences);
1703 std::set<FolderPtr> aFolders;
1704 ModuleBase_Tools::convertToFolders(anObjects, aFolders);
1707 QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text() + " %1";
1708 aDescription = aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
1709 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, module());
1711 operationMgr()->startOperation(anOpAction);
1713 std::set<FeaturePtr> aFeatureRefsToDelete;
1714 if (ModuleBase_Tools::askToDelete(aFeatures, aReferences, desktop(), aFeatureRefsToDelete)) {
1715 // WORKAROUND, should be done before each object remove, if it presents in XGUI_DataModel tree
1716 // It is necessary to clear selection in order to avoid selection changed event during
1717 // deletion and negative consequences connected with processing of already deleted items
1718 mySelector->clearSelection();
1720 if (!aFeatureRefsToDelete.empty())
1721 aFeatures.insert(aFeatureRefsToDelete.begin(), aFeatureRefsToDelete.end());
1722 aDone = ModelAPI_Tools::removeFeatures(aFeatures, false);
1724 if (aFolders.size() > 0) {
1725 std::set<FolderPtr>::const_iterator anIt = aFolders.begin(),
1726 aLast = aFolders.end();
1727 for (; anIt != aLast; anIt++) {
1728 FolderPtr aFolder = *anIt;
1729 if (aFolder.get()) {
1730 DocumentPtr aDoc = aFolder->document();
1731 aDoc->removeFolder(aFolder);
1737 operationMgr()->commitOperation();
1739 operationMgr()->abortOperation(operationMgr()->currentOperation());
1742 //**************************************************************
1743 void addRefsToFeature(const FeaturePtr& theFeature,
1744 const std::map<FeaturePtr, std::set<FeaturePtr> >& theMainList,
1745 std::set<FeaturePtr>& theReferences)
1747 //if (theReferences.find(theFeature) != theReferences.end())
1749 if (theMainList.find(theFeature) == theMainList.end())
1750 return; // this feature is not in the selection list, so exists without references to it
1751 std::set<FeaturePtr> aMainReferences = theMainList.at(theFeature);
1753 std::set<FeaturePtr>::const_iterator anIt = aMainReferences.begin(),
1754 aLast = aMainReferences.end();
1755 for (; anIt != aLast; anIt++) {
1756 FeaturePtr aRefFeature = *anIt;
1757 if (theReferences.find(aRefFeature) == theReferences.end())
1758 theReferences.insert(aRefFeature);
1759 addRefsToFeature(aRefFeature, theMainList, theReferences);
1763 //**************************************************************
1764 void XGUI_Workshop::cleanHistory()
1766 if (!abortAllOperations())
1769 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1770 std::set<FeaturePtr> aFeatures;
1771 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1773 #ifdef DEBUG_CLEAN_HISTORY
1775 std::set<FeaturePtr>::const_iterator aFIt;
1776 for (aFIt = aFeatures.begin(); aFIt != aFeatures.end(); ++aFIt) {
1777 FeaturePtr aFeature = ModelAPI_Feature::feature(*aFIt);
1778 anInfo.append(aFeature->name().c_str());
1780 QString anInfoStr = anInfo.join(";\t");
1781 qDebug(QString("cleanHistory for: [%1] - %2").
1782 arg(aFeatures.size()).arg(anInfoStr).toStdString().c_str());
1785 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1786 ModelAPI_Tools::findAllReferences(aFeatures, aReferences, true, false);
1787 // find for each object whether all reference values are in the map as key, that means that there
1788 // is no other reference in the model to this object, so it might be removed by cleaning history
1789 // sk_1(ext_1, vertex_1) + (sk_3, bool_1) - cann't be deleted, dependency to bool_1
1790 // ext_1(bool_1, sk_3) - cann't be deleted, dependency to bool_1
1792 // sk_2(ext_2) + (bool_1) - cann't be deleted, dependency to bool_1
1793 // ext_2(bool_1) - cann't be deleted, dependency to bool_1
1795 // Information: bool_1 is not selected
1796 std::set<FeaturePtr> anUnusedObjects;
1797 std::map<FeaturePtr, std::set<FeaturePtr> >::const_iterator aMainIt = aReferences.begin(),
1798 aMainLast = aReferences.end();
1799 for (; aMainIt != aMainLast; aMainIt++) {
1800 FeaturePtr aMainListFeature = aMainIt->first;
1801 std::set<FeaturePtr> aMainRefList = aMainIt->second;
1802 std::set<FeaturePtr>::const_iterator aRefIt = aMainRefList.begin(),
1803 aRefLast = aMainRefList.end();
1804 bool aFeatureOutOfTheList = false;
1805 for (; aRefIt != aRefLast && !aFeatureOutOfTheList; aRefIt++) {
1806 FeaturePtr aRefFeature = *aRefIt;
1807 aFeatureOutOfTheList = aReferences.find(aRefFeature) == aReferences.end();
1809 if (!aFeatureOutOfTheList)
1810 anUnusedObjects.insert(aMainListFeature);
1813 #ifdef DEBUG_CLEAN_HISTORY
1815 for (aFIt = anUnusedObjects.begin(); aFIt != anUnusedObjects.end(); ++aFIt) {
1816 FeaturePtr aFeature = *aFIt;
1817 anInfo.append(aFeature->name().c_str());
1819 qDebug(QString("unused objects: [%1] - %2").
1820 arg(anInfo.size()).arg(anInfo.join(";\t")).toStdString().c_str());
1823 // warn about the references remove, break the delete operation if the user chose it
1824 if (!anUnusedObjects.empty()) {
1826 foreach (const FeaturePtr& aFeature, anUnusedObjects) {
1827 aNames.append(aFeature->name().c_str());
1830 QString anUnusedNames = aNames.join(", ");
1832 QString anActionId = "CLEAN_HISTORY_CMD";
1833 QString aDescription = contextMenuMgr()->action(anActionId)->text();
1835 QMessageBox aMessageBox(desktop());
1836 aMessageBox.setWindowTitle(aDescription);
1837 aMessageBox.setIcon(QMessageBox::Warning);
1838 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
1839 aMessageBox.setDefaultButton(QMessageBox::No);
1841 const char* aKeyStr = "Unused features are the following: "
1842 "%1.\nThese features will be deleted.\nWould you like to continue?";
1843 QString aText = QString(tr(aKeyStr).arg(anUnusedNames));
1844 aMessageBox.setText(aText);
1845 if (aMessageBox.exec() == QMessageBox::No)
1848 // 1. start operation
1849 aDescription += "by deleting of " +
1850 aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
1851 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, module());
1852 operationMgr()->startOperation(anOpAction);
1854 // WORKAROUND, should be done before each object remove, if it presents in XGUI_DataModel tree
1855 // It is necessary to clear selection in order to avoid selection changed event during
1856 // deletion and negative consequences connected with processing of already deleted items
1857 mySelector->clearSelection();
1859 std::set<FeaturePtr> anIgnoredFeatures;
1860 if (ModelAPI_Tools::removeFeatures(anUnusedObjects, true)) {
1861 operationMgr()->commitOperation();
1864 operationMgr()->abortOperation(operationMgr()->currentOperation());
1868 QString anActionId = "CLEAN_HISTORY_CMD";
1869 QString aDescription = contextMenuMgr()->action(anActionId)->text();
1871 QMessageBox aMessageBox(desktop());
1872 aMessageBox.setWindowTitle(aDescription);
1873 aMessageBox.setIcon(QMessageBox::Warning);
1874 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
1875 aMessageBox.setDefaultButton(QMessageBox::No);
1878 aMessageBox.setStandardButtons(QMessageBox::Ok);
1879 aMessageBox.setDefaultButton(QMessageBox::Ok);
1881 aText = QString(tr("All features are relevant, there is nothing to be deleted"));
1882 aMessageBox.setText(aText);
1884 if (aMessageBox.exec() == QMessageBox::No)
1889 //**************************************************************
1890 void XGUI_Workshop::moveObjects()
1892 if (!abortAllOperations())
1895 SessionPtr aMgr = ModelAPI_Session::get();
1897 QString anActionId = "MOVE_CMD";
1898 QString aDescription = contextMenuMgr()->action(anActionId)->text();
1899 aMgr->startOperation(aDescription.toStdString());
1901 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1902 // It is necessary to clear selection in order to avoid selection changed event during
1903 // moving and negative consequences connected with processing of already moved items
1904 mySelector->clearSelection();
1905 // check whether the object can be moved. There should not be parts which are not loaded
1906 std::set<FeaturePtr> aFeatures;
1907 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1908 if (!XGUI_Tools::canRemoveOrRename(desktop(), aFeatures))
1911 DocumentPtr anActiveDocument = aMgr->activeDocument();
1912 FeaturePtr aCurrentFeature = anActiveDocument->currentFeature(true);
1913 std::set<FeaturePtr>::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
1914 for (; anIt != aLast; anIt++) {
1915 FeaturePtr aFeature = *anIt;
1916 if (!aFeature.get() || !myModule->canApplyAction(aFeature, anActionId))
1919 anActiveDocument->moveFeature(aFeature, aCurrentFeature);
1920 aCurrentFeature = anActiveDocument->currentFeature(true);
1922 aMgr->finishOperation();
1925 //**************************************************************
1926 bool XGUI_Workshop::deleteFeatures(const QObjectPtrList& theObjects)
1928 std::set<FeaturePtr> aFeatures;
1929 ModuleBase_Tools::convertToFeatures(theObjects, aFeatures);
1931 return ModelAPI_Tools::removeFeaturesAndReferences(aFeatures);
1934 //******************************************************
1935 bool hasResults(QObjectPtrList theObjects, const std::set<std::string>& theTypes)
1937 bool isFoundResultType = false;
1938 foreach(ObjectPtr anObj, theObjects)
1940 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
1941 if (aResult.get() == NULL)
1944 isFoundResultType = theTypes.find(aResult->groupName()) != theTypes.end();
1945 if (isFoundResultType)
1948 return isFoundResultType;
1951 //**************************************************************
1952 // Returns the list of all features for theDocument and all features of
1953 // all nested parts.
1954 std::list<FeaturePtr> allFeatures(const DocumentPtr& theDocument)
1956 std::list<FeaturePtr> aResultList;
1957 std::list<FeaturePtr> anAllFeatures = theDocument->allFeatures();
1958 foreach (const FeaturePtr& aFeature, anAllFeatures) {
1959 // The order of appending features of the part and the part itself is important
1961 // Append features from a part feature
1962 std::list<ResultPtr> aResults;
1963 ModelAPI_Tools::allResults(aFeature, aResults);
1964 foreach (const ResultPtr& aResult, aResults) {
1965 ResultPartPtr aResultPart =
1966 std::dynamic_pointer_cast<ModelAPI_ResultPart>(aResult);
1967 if (aResultPart.get() && aResultPart->partDoc().get()) {
1969 std::list<FeaturePtr> anAllFeatures = allFeatures(aResultPart->partDoc());
1970 aResultList.insert(aResultList.end(), anAllFeatures.begin(), anAllFeatures.end());
1974 aResultList.push_back(aFeature);
1979 //**************************************************************
1980 // Returns the list of features placed between theObject and the current feature
1981 // in the same document. Excludes theObject, includes the current feature.
1982 std::list<FeaturePtr> toCurrentFeatures(const ObjectPtr& theObject)
1984 std::list<FeaturePtr> aResult;
1985 DocumentPtr aDocument = theObject->document();
1986 std::list<FeaturePtr> anAllFeatures = allFeatures(aDocument);
1987 // find the object iterator
1988 std::list<FeaturePtr>::iterator aObjectIt =
1989 std::find(anAllFeatures.begin(), anAllFeatures.end(), theObject);
1990 if (aObjectIt == anAllFeatures.end())
1992 // find the current feature iterator
1993 std::list<FeaturePtr>::iterator aCurrentIt =
1994 std::find(anAllFeatures.begin(), anAllFeatures.end(), aDocument->currentFeature(true));
1995 if (aCurrentIt == anAllFeatures.end())
1997 // check the right order
1998 if (std::distance(aObjectIt, anAllFeatures.end()) <=
1999 std::distance(aCurrentIt, anAllFeatures.end()))
2001 // exclude the object
2002 std::advance(aObjectIt, 1);
2003 // include the current feature
2004 std::advance(aCurrentIt, 1);
2005 return std::list<FeaturePtr>(aObjectIt, aCurrentIt);
2008 //******************************************************
2009 bool XGUI_Workshop::canMoveFeature()
2011 QString anActionId = "MOVE_CMD";
2013 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
2014 QObjectPtrList aValidatedObjects;
2015 foreach (ObjectPtr aObject, aObjects) {
2016 if (!myModule->canApplyAction(aObject, anActionId))
2018 // To be moved feature should be in active document
2019 if (aObject->document() != ModelAPI_Session::get()->activeDocument())
2021 aValidatedObjects.append(aObject);
2023 if (aValidatedObjects.size() != aObjects.size())
2024 aObjects = aValidatedObjects;
2026 bool aCanMove = !aObjects.empty();
2028 QObjectPtrList::const_iterator anIt = aObjects.begin(), aLast = aObjects.end();
2029 for (; anIt != aLast && aCanMove; anIt++) {
2030 ObjectPtr aObject = *anIt;
2031 if (!aObject.get() || !aObject->data().get() || !aObject->data()->isValid()) {
2035 FeaturePtr aFeat = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
2036 // only groups can be moved to the end for now (#2451)
2037 if (aFeat.get() && aFeat->getKind() != "Group") {
2042 // 1. Get features placed between selected and current in the document
2043 std::list<FeaturePtr> aFeaturesBetween = toCurrentFeatures(aObject);
2044 // if aFeaturesBetween is empty it means wrong order or aObject is the current feature
2045 if (aFeaturesBetween.empty())
2048 std::set<FeaturePtr> aPlacedFeatures(aFeaturesBetween.begin(), aFeaturesBetween.end());
2049 // 2. Get all reference features to the selected object in the document
2050 std::set<FeaturePtr> aRefFeatures;
2051 ModuleBase_Tools::refsToFeatureInFeatureDocument(aObject, aRefFeatures);
2053 if (aRefFeatures.empty())
2056 // 3. Find any placed features in all reference features
2057 std::set<FeaturePtr> aIntersectionFeatures;
2058 std::set_intersection(aRefFeatures.begin(), aRefFeatures.end(),
2059 aPlacedFeatures.begin(), aPlacedFeatures.end(),
2060 std::inserter(aIntersectionFeatures, aIntersectionFeatures.begin()));
2061 // 4. Return false if any reference feature is placed before current feature
2062 if (!aIntersectionFeatures.empty())
2070 //**************************************************************
2071 bool XGUI_Workshop::canBeShaded(const ObjectPtr& theObject) const
2073 bool aCanBeShaded = myDisplayer->canBeShaded(theObject);
2074 if (!aCanBeShaded) {
2075 ResultCompSolidPtr aCompsolidResult =
2076 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
2077 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
2078 for(int i = 0; i < aCompsolidResult->numberOfSubs() && !aCanBeShaded; i++)
2079 aCanBeShaded = myDisplayer->canBeShaded(aCompsolidResult->subResult(i));
2082 return aCanBeShaded;
2085 //**************************************************************
2086 bool XGUI_Workshop::canChangeProperty(const QString& theActionName) const
2088 if (theActionName == "COLOR_CMD" ||
2089 theActionName == "DEFLECTION_CMD"
2090 #ifdef USE_TRANSPARENCY
2091 || theActionName == "TRANSPARENCY_CMD"
2094 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
2096 std::set<std::string> aTypes;
2097 aTypes.insert(ModelAPI_ResultGroup::group());
2098 aTypes.insert(ModelAPI_ResultConstruction::group());
2099 aTypes.insert(ModelAPI_ResultBody::group());
2100 aTypes.insert(ModelAPI_ResultPart::group());
2102 return hasResults(aObjects, aTypes);
2107 //******************************************************
2108 void setColor(ResultPtr theResult, const std::vector<int>& theColor)
2110 if (!theResult.get())
2113 AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
2114 if (aColorAttr.get() != NULL) {
2115 if (!aColorAttr->size()) {
2116 aColorAttr->setSize(3);
2118 aColorAttr->setValue(0, theColor[0]);
2119 aColorAttr->setValue(1, theColor[1]);
2120 aColorAttr->setValue(2, theColor[2]);
2124 //**************************************************************
2125 void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
2128 AttributeIntArrayPtr aColorAttr;
2129 // 1. find the current color of the object. This is a color of AIS presentation
2130 // The objects are iterated until a first valid color is found
2131 std::vector<int> aColor;
2132 foreach(ObjectPtr anObject, theObjects) {
2133 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
2134 if (aResult.get()) {
2135 XGUI_CustomPrs::getResultColor(aResult, aColor);
2138 // TODO: remove the obtaining a color from the AIS object
2139 // this does not happen never because:
2140 // 1. The color can be changed only on results
2141 // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
2142 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
2143 if (anAISObj.get()) {
2145 anAISObj->getColor(aColor[0], aColor[1], aColor[2]);
2148 if (!aColor.empty())
2151 if (aColor.size() != 3)
2154 if (!abortAllOperations())
2156 // 2. show the dialog to change the value
2157 XGUI_ColorDialog* aDlg = new XGUI_ColorDialog(desktop());
2158 aDlg->setColor(aColor);
2159 aDlg->move(QCursor::pos());
2160 bool isDone = aDlg->exec() == QDialog::Accepted;
2164 bool isRandomColor = aDlg->isRandomColor();
2166 // 3. abort the previous operation and start a new one
2167 SessionPtr aMgr = ModelAPI_Session::get();
2168 QString aDescription = contextMenuMgr()->action("COLOR_CMD")->text();
2169 aMgr->startOperation(aDescription.toStdString());
2171 // 4. set the value to all results
2172 std::vector<int> aColorResult = aDlg->getColor();
2173 foreach(ObjectPtr anObj, theObjects) {
2174 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
2175 if (aResult.get() != NULL) {
2176 ResultCompSolidPtr aCompsolidResult =
2177 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
2178 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
2179 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
2180 setColor(aCompsolidResult->subResult(i), !isRandomColor ? aColorResult :
2181 aDlg->getRandomColor());
2184 setColor(aResult, !isRandomColor ? aColorResult : aDlg->getRandomColor());
2187 aMgr->finishOperation();
2188 updateCommandStatus();
2191 //**************************************************************
2192 void setDeflection(ResultPtr theResult, const double theDeflection)
2194 if (!theResult.get())
2197 AttributeDoublePtr aDeflectionAttr = theResult->data()->real(ModelAPI_Result::DEFLECTION_ID());
2198 if (aDeflectionAttr.get() != NULL)
2199 aDeflectionAttr->setValue(theDeflection);
2202 //**************************************************************
2203 void setTransparency(ResultPtr theResult, double theTransparency)
2205 if (!theResult.get())
2208 AttributeDoublePtr anAttribute = theResult->data()->real(ModelAPI_Result::TRANSPARENCY_ID());
2209 if (anAttribute.get() != NULL)
2210 anAttribute->setValue(theTransparency);
2213 //**************************************************************
2214 void setTransparency(double theTransparency, const QObjectPtrList& theObjects)
2216 foreach(ObjectPtr anObj, theObjects) {
2217 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
2218 if (aResult.get() != NULL) {
2219 ResultCompSolidPtr aCompsolidResult =
2220 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
2221 if (aCompsolidResult.get() != NULL) { // change property for all sub-solids
2222 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
2223 setTransparency(aCompsolidResult->subResult(i), theTransparency);
2226 setTransparency(aResult, theTransparency);
2231 //**************************************************************
2232 void XGUI_Workshop::changeDeflection(const QObjectPtrList& theObjects)
2234 AttributeDoublePtr aDoubleAttr;
2235 // 1. find the current property of the object. This is a property of AIS presentation
2236 // The objects are iterated until a first valid property is found
2237 double aDeflection = -1;
2238 foreach(ObjectPtr anObject, theObjects) {
2239 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
2240 if (aResult.get()) {
2241 aDeflection = XGUI_CustomPrs::getResultDeflection(aResult);
2244 // TODO: remove the obtaining a property from the AIS object
2245 // this does not happen never because:
2246 // 1. The property can be changed only on results
2247 // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
2248 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
2249 if (anAISObj.get()) {
2250 aDeflection = anAISObj->getDeflection();
2253 if (aDeflection > 0)
2256 if (aDeflection < 0)
2259 if (!abortAllOperations())
2261 // 2. show the dialog to change the value
2262 XGUI_DeflectionDialog* aDlg = new XGUI_DeflectionDialog(desktop());
2263 aDlg->setDeflection(aDeflection);
2264 aDlg->move(QCursor::pos());
2265 bool isDone = aDlg->exec() == QDialog::Accepted;
2269 // 3. abort the previous operation and start a new one
2270 SessionPtr aMgr = ModelAPI_Session::get();
2271 QString aDescription = contextMenuMgr()->action("DEFLECTION_CMD")->text();
2272 aMgr->startOperation(aDescription.toStdString());
2274 // 4. set the value to all results
2275 aDeflection = aDlg->getDeflection();
2276 foreach(ObjectPtr anObj, theObjects) {
2277 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
2278 if (aResult.get() != NULL) {
2279 ResultCompSolidPtr aCompsolidResult =
2280 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
2281 if (aCompsolidResult.get() != NULL) { // change property for all sub-solids
2282 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
2283 setDeflection(aCompsolidResult->subResult(i), aDeflection);
2286 setDeflection(aResult, aDeflection);
2289 aMgr->finishOperation();
2290 updateCommandStatus();
2293 //**************************************************************
2294 void XGUI_Workshop::changeTransparency(const QObjectPtrList& theObjects)
2296 AttributeDoublePtr aDoubleAttr;
2297 // 1. find the current property of the object. This is a property of AIS presentation
2298 // The objects are iterated until a first valid property is found
2299 double aCurrentValue = -1;
2300 foreach(ObjectPtr anObject, theObjects) {
2301 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
2302 if (aResult.get()) {
2303 aCurrentValue = XGUI_CustomPrs::getResultTransparency(aResult);
2306 // TODO: remove the obtaining a property from the AIS object
2307 // this does not happen never because:
2308 // 1. The property can be changed only on results
2309 // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
2310 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
2311 if (anAISObj.get()) {
2312 aCurrentValue = anAISObj->getDeflection();
2315 if (aCurrentValue > 0)
2318 if (aCurrentValue < 0)
2321 if (!abortAllOperations())
2324 // 2. show the dialog to change the value
2325 XGUI_PropertyDialog* aDlg = new XGUI_PropertyDialog(desktop());
2326 aDlg->setWindowTitle("Transparency");
2327 XGUI_TransparencyWidget* aTransparencyWidget = new XGUI_TransparencyWidget(aDlg);
2328 connect(aTransparencyWidget, SIGNAL(transparencyValueChanged()),
2329 this, SLOT(onTransparencyValueChanged()));
2330 connect(aTransparencyWidget, SIGNAL(previewStateChanged()),
2331 this, SLOT(onPreviewStateChanged()));
2332 aDlg->setContent(aTransparencyWidget);
2333 aTransparencyWidget->setValue(aCurrentValue);
2335 // 3. abort the previous operation and start a new one
2336 SessionPtr aMgr = ModelAPI_Session::get();
2337 QString aDescription = contextMenuMgr()->action("TRANSPARENCY_CMD")->text();
2338 aMgr->startOperation(aDescription.toStdString());
2340 aDlg->move(QCursor::pos());
2341 bool isDone = aDlg->exec() == QDialog::Accepted;
2345 // 4. set the value to all results
2346 aCurrentValue = aTransparencyWidget->getValue();
2347 setTransparency(aCurrentValue, theObjects);
2349 aMgr->finishOperation();
2350 updateCommandStatus();
2353 //**************************************************************
2354 void XGUI_Workshop::onTransparencyValueChanged()
2356 XGUI_TransparencyWidget* aTransparencyWidget = (XGUI_TransparencyWidget*)sender();
2357 if (!aTransparencyWidget || !aTransparencyWidget->isPreviewNeeded())
2360 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
2361 setTransparency(aTransparencyWidget->getValue(), anObjects);
2362 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2365 //**************************************************************
2366 void XGUI_Workshop::onPreviewStateChanged()
2368 XGUI_TransparencyWidget* aTransparencyWidget = (XGUI_TransparencyWidget*)sender();
2369 if (!aTransparencyWidget || !aTransparencyWidget->isPreviewNeeded())
2372 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
2373 setTransparency(aTransparencyWidget->getValue(), anObjects);
2374 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2377 //**************************************************************
2378 #define SET_DISPLAY_GROUP(aGroupName, aDisplay) \
2379 for (int i = 0; i < aDoc->size(aGroupName); i++) { \
2380 aDoc->object(aGroupName, i)->setDisplayed(aDisplay); \
2383 //******************************************************
2384 void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible)
2387 std::set<ObjectPtr> anObjects;
2388 foreach (ObjectPtr aObj, theList) {
2389 anObjects.insert(aObj);
2391 if (!prepareForDisplay(anObjects))
2395 foreach (ObjectPtr aObj, theList) {
2396 aObj->setDisplayed(isVisible);
2398 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2399 myObjectBrowser->updateAllIndexes();
2402 //**************************************************************
2403 void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList)
2405 // Hide all displayed objects
2406 QObjectPtrList aList = myDisplayer->displayedObjects();
2407 foreach (ObjectPtr aObj, aList) {
2408 if (module()->canEraseObject(aObj))
2409 aObj->setDisplayed(false);
2411 //Do not use eraseAll if you didn't send Redisplay event:
2412 //all objects are erased from viewer, but considered as displayed in displayer
2413 // Problem in bug 2218
2414 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2416 //issue #2159 Hide all incomplete behavior
2417 viewer()->eraseAll();
2420 std::set<ObjectPtr> anObjects;
2421 foreach (ObjectPtr aObj, theList) {
2422 anObjects.insert(aObj);
2425 if (!prepareForDisplay(anObjects))
2428 // Show only objects from the list
2429 foreach (ObjectPtr aObj, theList) {
2430 aObj->setDisplayed(true);
2432 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2434 // Necessary for update icons in ObjectBrowser on Linux
2435 myObjectBrowser->updateAllIndexes();
2438 //**************************************************************
2439 void XGUI_Workshop::registerValidators() const
2441 SessionPtr aMgr = ModelAPI_Session::get();
2442 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
2445 //**************************************************************
2446 void XGUI_Workshop::displayDocumentResults(DocumentPtr theDoc)
2450 displayGroupResults(theDoc, ModelAPI_ResultConstruction::group());
2451 displayGroupResults(theDoc, ModelAPI_ResultBody::group());
2454 //**************************************************************
2455 void XGUI_Workshop::displayGroupResults(DocumentPtr theDoc, std::string theGroup)
2457 for (int i = 0; i < theDoc->size(theGroup); i++)
2458 theDoc->object(theGroup, i)->setDisplayed(true);
2459 //displayObject(theDoc->object(theGroup, i));
2460 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2463 //**************************************************************
2464 void XGUI_Workshop::setDisplayMode(const QObjectPtrList& theList, int theMode)
2466 foreach(ObjectPtr aObj, theList) {
2467 myDisplayer->setDisplayMode(aObj, (XGUI_Displayer::DisplayMode)theMode, false);
2469 ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aObj);
2470 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
2471 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
2472 myDisplayer->setDisplayMode(aCompsolidResult->subResult(i),
2473 (XGUI_Displayer::DisplayMode)theMode, false);
2477 if (theList.size() > 0)
2478 myDisplayer->updateViewer();
2481 //**************************************************************
2482 void XGUI_Workshop::closeDocument()
2484 ModuleBase_Operation* anOperation = operationMgr()->currentOperation();
2485 while (anOperation) {
2486 anOperation->abort();
2487 anOperation = operationMgr()->currentOperation();
2489 //myDisplayer->closeLocalContexts();
2490 myDisplayer->eraseAll();
2491 objectBrowser()->clearContent();
2493 module()->closeDocument();
2494 // we need to clear viewer (with created filters) to do not have problems in 2nd SALOME study
2495 module()->clearViewer();
2498 // data model need not process the document's signals about objects modifications as
2499 // the document is closed
2500 //bool isBlocked = objectBrowser()->dataModel()->blockEventsProcessing(true);
2502 SessionPtr aMgr = ModelAPI_Session::get();
2505 //objectBrowser()->dataModel()->blockEventsProcessing(isBlocked);
2508 //******************************************************
2509 void XGUI_Workshop::addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot)
2511 XGUI_HistoryMenu* aMenu = NULL;
2512 if (isSalomeMode()) {
2513 QAction* anAction = qobject_cast<QAction*>(theObject);
2516 aMenu = new XGUI_HistoryMenu(anAction);
2518 QToolButton* aButton = qobject_cast<QToolButton*>(theObject);
2519 aMenu = new XGUI_HistoryMenu(aButton);
2521 connect(this, theSignal, aMenu, SLOT(setHistory(const QList<ActionInfo>&)));
2522 connect(aMenu, SIGNAL(actionSelected(int)), this, theSlot);
2525 //******************************************************
2526 QList<ActionInfo> XGUI_Workshop::processHistoryList(const std::list<std::string>& theList) const
2528 QList<ActionInfo> aResult;
2529 std::list<std::string>::const_iterator it = theList.cbegin();
2530 for (; it != theList.cend(); it++) {
2531 QString anId = QString::fromStdString(*it);
2532 bool isEditing = anId.endsWith(ModuleBase_OperationFeature::EditSuffix());
2534 anId.chop(ModuleBase_OperationFeature::EditSuffix().size());
2537 QAction* aContextMenuAct = myContextMenuMgr->actionByName(anId);
2538 if (aContextMenuAct) {
2539 anInfo.initFrom(aContextMenuAct);
2541 anInfo = myActionsMgr->actionInfoById(anId);
2544 anInfo.text = anInfo.text.prepend("Modify ");
2551 //******************************************************
2552 void XGUI_Workshop::setStatusBarMessage(const QString& theMessage)
2555 salomeConnector()->putInfo(theMessage, -1);
2557 myMainWindow->putInfo(theMessage, -1);
2562 //******************************************************
2563 void XGUI_Workshop::synchronizeViewer()
2565 SessionPtr aMgr = ModelAPI_Session::get();
2566 QList<DocumentPtr> aDocs;
2567 aDocs.append(aMgr->activeDocument());
2568 aDocs.append(aMgr->moduleDocument());
2570 foreach(DocumentPtr aDoc, aDocs) {
2571 synchronizeGroupInViewer(aDoc, ModelAPI_ResultConstruction::group(), false);
2572 synchronizeGroupInViewer(aDoc, ModelAPI_ResultBody::group(), false);
2573 synchronizeGroupInViewer(aDoc, ModelAPI_ResultPart::group(), false);
2574 synchronizeGroupInViewer(aDoc, ModelAPI_ResultGroup::group(), false);
2578 //******************************************************
2579 void XGUI_Workshop::synchronizeGroupInViewer(const DocumentPtr& theDoc,
2580 const std::string& theGroup,
2581 bool theUpdateViewer)
2584 int aSize = theDoc->size(theGroup);
2585 for (int i = 0; i < aSize; i++) {
2586 aObj = theDoc->object(theGroup, i);
2587 if (aObj->isDisplayed()) {
2588 // Hide the presentation with an empty shape. But isDisplayed state of the object should not
2589 // be changed to the object becomes visible when the shape becomes not empty
2590 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
2591 if (aRes.get() && (!aRes->shape().get() || aRes->shape()->isNull()))
2593 myDisplayer->display(aObj, false);
2596 if (theUpdateViewer)
2597 myDisplayer->updateViewer();
2601 //******************************************************
2602 void XGUI_Workshop::highlightResults(const QObjectPtrList& theObjects)
2604 FeaturePtr aFeature;
2605 QObjectPtrList aSelList = theObjects;
2606 QObjectPtrList aNewSel;
2607 bool aHasHidden = false;
2608 foreach(ObjectPtr aObj, theObjects) {
2609 aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
2610 if (aFeature.get()) {
2611 std::list<ResultPtr> aResults;
2612 ModelAPI_Tools::allResults(aFeature, aResults);
2613 std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aIt;
2614 for(aIt = aResults.cbegin(); aIt != aResults.cend(); aIt++) {
2615 aHasHidden |= (*aIt)->isConcealed();
2616 aSelList.append(*aIt);
2617 aNewSel.append(*aIt);
2621 if (aSelList.count() > theObjects.count()) {
2622 // if something was found
2623 bool aBlocked = objectBrowser()->blockSignals(true);
2624 objectBrowser()->setObjectsSelected(aSelList);
2625 objectBrowser()->blockSignals(aBlocked);
2626 objectBrowser()->ensureVisible(aNewSel.first());
2629 QMessageBox::information(desktop(), tr("Find results"),
2630 tr("Results not found"), QMessageBox::Ok);
2633 //******************************************************
2634 void XGUI_Workshop::highlightFeature(const QObjectPtrList& theObjects)
2637 QObjectPtrList aSelList = theObjects;
2638 QObjectPtrList aNewSel;
2639 FeaturePtr aFeature;
2640 foreach(ObjectPtr aObj, theObjects) {
2641 aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
2642 if (aResult.get()) {
2643 aFeature = ModelAPI_Feature::feature(aResult);
2644 if (aFeature.get()) {
2645 aSelList.append(aFeature);
2646 aNewSel.append(aFeature);
2650 if (aSelList.count() > theObjects.count()) {
2651 // if something was found
2652 bool aBlocked = objectBrowser()->blockSignals(true);
2653 objectBrowser()->setObjectsSelected(aSelList);
2654 objectBrowser()->blockSignals(aBlocked);
2655 objectBrowser()->ensureVisible(aNewSel.first());
2659 void XGUI_Workshop::insertFeatureFolder()
2661 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
2662 if (aObjects.isEmpty())
2664 ObjectPtr aObj = aObjects.first();
2665 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
2666 if (aFeature.get() == NULL)
2668 SessionPtr aMgr = ModelAPI_Session::get();
2669 DocumentPtr aDoc = aMgr->activeDocument();
2671 QString aDescription = contextMenuMgr()->action("INSERT_FOLDER_CMD")->text();
2673 aMgr->startOperation(aDescription.toStdString());
2674 aDoc->addFolder(aFeature);
2675 aMgr->finishOperation();
2677 updateCommandStatus();
2681 void XGUI_Workshop::insertToFolder(bool isBefore)
2683 std::list<FeaturePtr> aFeatures = mySelector->getSelectedFeatures();
2684 if (aFeatures.empty())
2687 SessionPtr aMgr = ModelAPI_Session::get();
2688 DocumentPtr aDoc = aMgr->activeDocument();
2690 FolderPtr aFolder = isBefore? aDoc->findFolderAbove(aFeatures):
2691 aDoc->findFolderBelow(aFeatures);
2695 QString aDescription = contextMenuMgr()->action(
2696 isBefore ? "ADD_TO_FOLDER_BEFORE_CMD" : "ADD_TO_FOLDER_AFTER_CMD")->text();
2698 QMap<ObjectPtr, bool> aStates = myObjectBrowser->getFoldersState(aDoc);
2700 aMgr->startOperation(aDescription.toStdString());
2701 aDoc->moveToFolder(aFeatures, aFolder);
2702 aMgr->finishOperation();
2704 myObjectBrowser->setFoldersState(aStates);
2706 updateCommandStatus();
2709 void XGUI_Workshop::moveOutFolder(bool isBefore)
2711 std::list<FeaturePtr> aFeatures = mySelector->getSelectedFeatures();
2712 if (aFeatures.empty())
2715 SessionPtr aMgr = ModelAPI_Session::get();
2716 DocumentPtr aDoc = aMgr->activeDocument();
2718 QString aDescription = contextMenuMgr()->action(
2719 isBefore ? "ADD_OUT_FOLDER_BEFORE_CMD" : "ADD_OUT_FOLDER_AFTER_CMD")->text();
2721 QMap<ObjectPtr, bool> aStates = myObjectBrowser->getFoldersState(aDoc);
2723 aMgr->startOperation(aDescription.toStdString());
2724 aDoc->removeFromFolder(aFeatures, isBefore);
2725 aMgr->finishOperation();
2727 myObjectBrowser->setFoldersState(aStates);
2729 updateCommandStatus();