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>
53 #include <XGUI_InspectionPanel.h>
56 #include <AppElements_Button.h>
57 #include <AppElements_Command.h>
58 #include <AppElements_MainMenu.h>
59 #include <AppElements_MainWindow.h>
60 #include <AppElements_MenuGroupPanel.h>
61 #include <AppElements_Viewer.h>
62 #include <AppElements_Workbench.h>
65 #include <Config_XMLReader.h>
67 #include <ModelAPI_AttributeDocRef.h>
68 #include <ModelAPI_AttributeIntArray.h>
69 #include <ModelAPI_AttributeDouble.h>
70 #include <ModelAPI_Data.h>
71 #include <ModelAPI_Events.h>
72 #include <ModelAPI_Feature.h>
73 #include <ModelAPI_Object.h>
74 #include <ModelAPI_ResultBody.h>
75 #include <ModelAPI_ResultCompSolid.h>
76 #include <ModelAPI_ResultConstruction.h>
77 #include <ModelAPI_ResultGroup.h>
78 #include <ModelAPI_ResultParameter.h>
79 #include <ModelAPI_ResultField.h>
80 #include <ModelAPI_Session.h>
81 #include <ModelAPI_Validator.h>
82 #include <ModelAPI_Tools.h>
84 //#include <PartSetPlugin_Part.h>
86 #include <Events_Loop.h>
87 #include <Events_InfoMessage.h>
88 #include <Events_LongOp.h>
90 #include <ModuleBase_IModule.h>
91 #include <ModuleBase_IViewer.h>
92 #include <ModuleBase_Operation.h>
93 #include <ModuleBase_OperationDescription.h>
94 #include <ModuleBase_PageBase.h>
95 #include <ModuleBase_Preferences.h>
96 #include <ModuleBase_SelectionValidator.h>
97 #include <ModuleBase_Tools.h>
98 #include <ModuleBase_WidgetFactory.h>
99 #include <ModuleBase_OperationFeature.h>
100 #include <ModuleBase_OperationAction.h>
101 #include <ModuleBase_PagedContainer.h>
102 #include <ModuleBase_WidgetValidated.h>
103 #include <ModuleBase_ModelWidget.h>
104 #include <ModuleBase_ResultPrs.h>
105 #include <ModuleBase_ActionIntParameter.h>
107 #include <Config_Common.h>
108 #include <Config_FeatureMessage.h>
109 #include <Config_ModuleReader.h>
110 #include <Config_PointerMessage.h>
111 #include <Config_PropManager.h>
112 #include <Config_DataModelReader.h>
113 #include <Config_Translator.h>
114 #include <Config_WidgetAPI.h>
115 #include <Config_Keywords.h>
117 #include <SUIT_ResourceMgr.h>
119 #include <AIS_Trihedron.hxx>
120 #ifdef BEFORE_TRIHEDRON_PATCH
121 #include <AIS_Point.hxx>
122 #include <AIS_Axis.hxx>
125 #include <QApplication>
126 #include <QFileDialog>
127 #include <QMessageBox>
128 #include <QMdiSubWindow>
129 #include <QMainWindow>
130 #include <QPushButton>
131 #include <QDockWidget>
136 #include <QToolButton>
138 #include <QDesktopWidget>
143 #include <CDF_Session.hxx>
144 #include <CDF_Application.hxx>
145 #include <inspector/TInspector_Communicator.hxx>
146 #include <inspector/VInspector_CallBack.hxx>
147 static TInspector_Communicator* MyTCommunicator;
148 static Handle(VInspector_CallBack) MyVCallBack;
163 //#define DEBUG_WITH_MESSAGE_REPORT
165 QString XGUI_Workshop::MOVE_TO_END_COMMAND = QObject::tr("Move to the end");
167 //#define DEBUG_DELETE
168 //#define DEBUG_FEATURE_NAME
169 //#define DEBUG_CLEAN_HISTORY
171 //******************************************************
172 XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
174 myCurrentDir(QString()),
176 mySalomeConnector(theConnector),
178 myInspectionPanel(0),
182 //myViewerSelMode(TopAbs_FACE)
184 mySelector = new XGUI_SelectionMgr(this);
185 myModuleConnector = new XGUI_ModuleConnector(this);
186 myOperationMgr = new XGUI_OperationMgr(this, 0);
187 ModuleBase_IWorkshop* aWorkshop = moduleConnector();
188 // Has to be defined first in order to get errors and messages from other components
189 myEventsListener = new XGUI_WorkshopListener(aWorkshop);
190 mySelectionActivate = new XGUI_SelectionActivate(aWorkshop);
192 SUIT_ResourceMgr* aResMgr = ModuleBase_Preferences::resourceMgr();
194 myMainWindow = new AppElements_MainWindow();
196 bool aCloc = aResMgr->booleanValue("language", "locale", true);
198 QLocale::setDefault( QLocale::c() );
200 QLocale::setDefault( QLocale::system() );
202 QString aPath = Config_XMLReader::pluginConfigFile().c_str();
207 aLangs << "*_en.ts"; // load by default eng translations
208 QString aCurrLang = aResMgr->stringValue("language", "language", "en");
209 if(aCurrLang != "en") {
210 aLangs << "*_" + aCurrLang + ".ts"; // then replace with translated files
213 foreach(QString aLang, aLangs) {
214 QStringList aFilters;
216 QStringList aTsFiles = aDir.entryList(aFilters, QDir::Files);
217 foreach(QString aFileName, aTsFiles) {
218 Config_Translator::load(aFileName.toStdString());
222 myDataModelXMLReader = new Config_DataModelReader();
223 //myDataModelXMLReader->readAll();
225 myDisplayer = new XGUI_Displayer(this);
227 connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(updateCommandStatus()));
229 myActionsMgr = new XGUI_ActionsMgr(this);
230 myActiveControlMgr = new XGUI_ActiveControlMgr(myModuleConnector);
231 myMenuMgr = new XGUI_MenuMgr(this);
232 myErrorDlg = new XGUI_ErrorDialog(QApplication::desktop());
233 myContextMenuMgr = new XGUI_ContextMenuMgr(this);
234 connect(myContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), this,
235 SLOT(onContextMenuCommand(const QString&, bool)));
237 myViewerProxy = new XGUI_ViewerProxy(this);
238 //connect(myViewerProxy, SIGNAL(selectionChanged()),
239 // myActionsMgr, SLOT(updateOnViewSelection()));
241 myOperationMgr->setWorkshop(aWorkshop);
243 myErrorMgr = new XGUI_ErrorMgr(this, aWorkshop);
245 connect(myOperationMgr, SIGNAL(operationResumed(ModuleBase_Operation*)),
246 SLOT(onOperationResumed(ModuleBase_Operation*)));
247 connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
248 SLOT(onOperationStopped(ModuleBase_Operation*)));
249 connect(myOperationMgr, SIGNAL(operationCommitted(ModuleBase_Operation*)),
250 SLOT(onOperationCommitted(ModuleBase_Operation*)));
251 connect(myOperationMgr, SIGNAL(operationAborted(ModuleBase_Operation*)),
252 SLOT(onOperationAborted(ModuleBase_Operation*)));
255 connect(myMainWindow, SIGNAL(exitKeySequence()), SLOT(onExit()));
256 onTrihedronVisibilityChanged(true);
259 connect(myEventsListener, SIGNAL(errorOccurred(std::shared_ptr<Events_InfoMessage>)),
260 myErrorDlg, SLOT(addError(std::shared_ptr<Events_InfoMessage>)));
262 //Config_PropManager::registerProp("Visualization", "object_default_color", "Object color",
263 // Config_Prop::Color, "225,225,225");
265 Config_PropManager::registerProp("Visualization", "result_body_color", "Result color",
266 Config_Prop::Color, ModelAPI_ResultBody::DEFAULT_COLOR());
267 Config_PropManager::registerProp("Visualization", "result_group_color", "Group color",
268 Config_Prop::Color, ModelAPI_ResultGroup::DEFAULT_COLOR());
269 Config_PropManager::registerProp("Visualization", "result_construction_color",
270 "Construction color",
272 ModelAPI_ResultConstruction::DEFAULT_COLOR());
273 Config_PropManager::registerProp("Visualization", "result_part_color", "Part color",
274 Config_Prop::Color, ModelAPI_ResultPart::DEFAULT_COLOR());
275 Config_PropManager::registerProp("Visualization", "result_field_color", "Field color",
276 Config_Prop::Color, ModelAPI_ResultField::DEFAULT_COLOR());
278 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "face-selection", true))
279 myViewerSelMode.append(TopAbs_FACE);
280 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "edge-selection", true))
281 myViewerSelMode.append(TopAbs_EDGE);
282 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "vertex-selection", true))
283 myViewerSelMode.append(TopAbs_VERTEX);
284 //IMP: an attempt to use result selection with other selection modes
285 myViewerSelMode.append(ModuleBase_ResultPrs::Sel_Result);//TopAbs_VERTEX);
286 myViewerSelMode.append(TopAbs_COMPSOLID);
289 //******************************************************
290 XGUI_Workshop::~XGUI_Workshop(void)
293 #ifdef MISSED_TRANSLATION
294 // Save Missed translations
295 Config_Translator::saveMissedTranslations();
300 delete myDataModelXMLReader;
303 //******************************************************
304 void XGUI_Workshop::startApplication()
306 //Initialize event listening
307 myEventsListener->initializeEventListening();
309 myDataModelXMLReader->readAll();
312 Config_PropManager::registerProp("Plugins", "default_path", "Default Path",
313 Config_Prop::Directory, "");
315 std::string aDir = Config_XMLReader::resourcesConfigFile();
316 Config_PropManager::registerProp("Plugins", "import_initial_path", "Import initial directory",
317 Config_Prop::Directory, aDir);
320 Config_PropManager::registerProp("Plugins", "create_part_by_start", "Create Part by Start",
321 Config_Prop::Boolean, "false");
323 Config_PropManager::registerProp("Plugins", "show_hide_faces", "Show Hide Faces (on the right)",
324 Config_Prop::Boolean, "false");
326 registerValidators();
328 // Calling of loadCustomProps before activating module is required
329 // by Config_PropManger to restore user-defined path to plugins
330 ModuleBase_Preferences::loadCustomProps();
334 myMainWindow->show();
335 updateCommandStatus();
340 myViewerProxy->connectViewProxy();
341 connect(myViewerProxy, SIGNAL(trihedronVisibilityChanged(bool)),
342 SLOT(onTrihedronVisibilityChanged(bool)));
344 emit applicationStarted();
347 bool aNewPart = Config_PropManager::boolean("Plugins", "create_part_by_start");
349 module()->launchOperation("Part", false); // PartSetPlugin_Part::ID()
354 //******************************************************
355 void XGUI_Workshop::activateModule()
357 selectionActivate()->updateSelectionFilters();
359 connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
360 myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
361 connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
362 myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
364 updateCommandStatus();
366 // TODO: get default selection mode
368 // activate visualized objects in the viewer
369 activateObjectsSelection(displayer()->displayedObjects());
370 myOperationMgr->activate();
373 //******************************************************
374 void XGUI_Workshop::deactivateModule()
376 // remove internal displayer filter
377 displayer()->deactivateSelectionFilters(false);
379 disconnect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
380 myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
381 disconnect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
382 myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
384 XGUI_Displayer* aDisplayer = displayer();
385 QObjectPtrList aDisplayed = aDisplayer->displayedObjects();
386 aDisplayer->deactivateObjects(aDisplayed, true);
387 selectionActivate()->deactivateTrihedronInSelectionModes();
389 #ifdef BEFORE_TRIHEDRON_PATCH
390 //Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(aDisplayer->getTrihedron());
391 /// Trihedron problem: objects stayed in the viewer, should be removed manually
392 /// otherwise in SALOME happens crash by HideAll in the viewer
393 aContext->Remove(aTrihedron->Position(), true);
394 aContext->Remove(aTrihedron->Axis(), true);
395 aContext->Remove(aTrihedron->XAxis(), true);
396 aContext->Remove(aTrihedron->YAxis(), true);
399 myOperationMgr->deactivate();
402 //******************************************************
403 void XGUI_Workshop::initMenu()
405 myContextMenuMgr->createActions();
408 // Create only Undo, Redo commands
409 QAction* aAction = salomeConnector()->addDesktopCommand("UNDO_CMD", tr("Undo"),
410 tr("Undo last command"),
411 QIcon(":pictures/undo.png"),
412 QKeySequence::Undo, false,
414 QString aToolBarTitle = tr( "INF_DESK_TOOLBAR_STANDARD" );
415 salomeConnector()->addActionInToolbar( aAction,aToolBarTitle );
417 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onUndo()));
418 addHistoryMenu(aAction, SIGNAL(updateUndoHistory(const QList<ActionInfo>&)), SLOT(onUndo(int)));
420 aAction = salomeConnector()->addDesktopCommand("REDO_CMD", tr("Redo"), tr("Redo last command"),
421 QIcon(":pictures/redo.png"), QKeySequence::Redo,
422 false, "MEN_DESK_EDIT");
423 salomeConnector()->addActionInToolbar( aAction, aToolBarTitle );
425 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo()));
426 addHistoryMenu(aAction, SIGNAL(updateRedoHistory(const QList<ActionInfo>&)), SLOT(onRedo(int)));
428 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
430 aAction = salomeConnector()->addDesktopCommand("SAVEAS_CMD", tr("Export native..."),
431 tr("Export the current document into a native file"),
432 QIcon(), QKeySequence(),
433 false, "MEN_DESK_FILE");
434 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onSaveAs()));
436 aAction = salomeConnector()->addDesktopCommand("OPEN_CMD", tr("Import native..."),
437 tr("Import native file"),
438 QIcon(), QKeySequence(),
439 false, "MEN_DESK_FILE");
440 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onOpen()));
441 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_FILE");
444 // File commands group
445 AppElements_MenuGroupPanel* aGroup = myMainWindow->menuObject()->generalPage();
447 AppElements_Command* aCommand;
449 aCommand = aGroup->addFeature("SAVE_CMD", tr("Save"), tr("Save the document"),
450 QIcon(":pictures/save.png"), QKeySequence::Save);
451 aCommand->connectTo(this, SLOT(onSave()));
452 //aCommand->disable();
454 aCommand = aGroup->addFeature("SAVEAS_CMD", tr("Save as..."), tr("Save the document into a file"),
455 QIcon(":pictures/save.png"), QKeySequence());
456 aCommand->connectTo(this, SLOT(onSaveAs()));
458 QString aUndoId = "UNDO_CMD";
459 aCommand = aGroup->addFeature(aUndoId, tr("Undo"), tr("Undo last command"),
460 QIcon(":pictures/undo.png"), QKeySequence::Undo);
461 aCommand->connectTo(this, SLOT(onUndo()));
462 AppElements_Button* aUndoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aUndoId));
463 addHistoryMenu(aUndoButton,
464 SIGNAL(updateUndoHistory(const QList<ActionInfo>&)),
467 QString aRedoId = "REDO_CMD";
468 aCommand = aGroup->addFeature(aRedoId, tr("Redo"), tr("Redo last command"),
469 QIcon(":pictures/redo.png"), QKeySequence::Redo);
470 aCommand->connectTo(this, SLOT(onRedo()));
471 AppElements_Button* aRedoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aRedoId));
472 addHistoryMenu(aRedoButton,
473 SIGNAL(updateRedoHistory(const QList<ActionInfo>&)),
476 aCommand = aGroup->addFeature("OPEN_CMD", tr("Open..."), tr("Open a new document"),
477 QIcon(":pictures/open.png"), QKeySequence::Open);
478 aCommand->connectTo(this, SLOT(onOpen()));
480 aCommand = aGroup->addFeature("PREF_CMD", tr("Preferences"), tr("Edit preferences"),
481 QIcon(":pictures/preferences.png"), QKeySequence::Preferences);
482 aCommand->connectTo(this, SLOT(onPreferences()));
484 aCommand = aGroup->addFeature("EXIT_CMD", tr("Exit"), tr("Exit application"),
485 QIcon(":pictures/close.png"), QKeySequence::Close);
486 aCommand->connectTo(this, SLOT(onExit()));
491 //******************************************************
492 AppElements_Workbench* XGUI_Workshop::addWorkbench(const QString& theName)
494 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
495 return aMenuBar->addWorkbench(theName);
499 //******************************************************
500 QMainWindow* XGUI_Workshop::desktop() const
503 return salomeConnector()->desktop();
509 //******************************************************
510 void XGUI_Workshop::onStartWaiting()
512 if (Events_LongOp::isPerformed()) {
513 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
517 //******************************************************
518 void XGUI_Workshop::onAcceptActionClicked()
520 QAction* anAction = dynamic_cast<QAction*>(sender());
521 XGUI_OperationMgr* anOperationMgr = operationMgr();
522 if (anOperationMgr) {
523 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
524 (anOperationMgr->currentOperation());
526 //if (errorMgr()->canProcessClick(anAction, aFOperation->feature()))
527 myOperationMgr->commitOperation();
532 //******************************************************
533 void XGUI_Workshop::onAcceptPlusActionClicked()
535 QAction* anAction = dynamic_cast<QAction*>(sender());
536 XGUI_OperationMgr* anOperationMgr = operationMgr();
537 if (anOperationMgr) {
538 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
539 (anOperationMgr->currentOperation());
541 if (myOperationMgr->commitOperation())
542 module()->launchOperation(aFOperation->id(), false);
547 //******************************************************
548 void XGUI_Workshop::onPreviewActionClicked()
550 ModuleBase_IPropertyPanel* aPanel = propertyPanel();
552 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
553 if (anActiveWidget && anActiveWidget->getValueState() == ModuleBase_ModelWidget::ModifiedInPP) {
554 anActiveWidget->storeValue();
557 std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
558 new Events_Message(Events_Loop::eventByName(EVENT_PREVIEW_REQUESTED)));
559 Events_Loop::loop()->send(aMsg);
562 //******************************************************
563 void XGUI_Workshop::deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer)
565 if (!myModule->canActivateSelection(theObject)) {
566 if (selectionActivate()->isActive(theObject)) {
567 QObjectPtrList anObjects;
568 anObjects.append(theObject);
569 myDisplayer->deactivateObjects(anObjects, theUpdateViewer);
574 //******************************************************
575 bool XGUI_Workshop::isFeatureOfNested(const FeaturePtr& theFeature)
577 bool aHasNested = false;
578 std::string aFeatureKind = theFeature->getKind();
580 XGUI_SalomeConnector* aSalomeConnector = salomeConnector();
581 if (aSalomeConnector->isFeatureOfNested(actionsMgr()->action(aFeatureKind.c_str())))
584 AppElements_MainMenu* aMenuBar = mainWindow()->menuObject();
585 AppElements_Command* aCommand = aMenuBar->feature(aFeatureKind.c_str());
586 if (aCommand && aCommand->button()->additionalButtonWidget())
592 //******************************************************
593 void XGUI_Workshop::fillPropertyPanel(ModuleBase_Operation* theOperation)
595 ModuleBase_OperationFeature* aFOperation =
596 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
600 showPanel(myPropertyPanel);
601 myPropertyPanel->cleanContent();
603 QList<ModuleBase_ModelWidget*> aWidgets;
604 if (!module()->createWidgets(theOperation, aWidgets)) {
605 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
606 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), myModuleConnector);
607 aFactory.createWidget(myPropertyPanel->contentWidget());
608 aWidgets = aFactory.getModelWidgets();
611 // check compatibility of feature and widgets
612 FeaturePtr aFeature = aFOperation->feature();
613 std::string aFeatureKind = aFeature->getKind();
614 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
615 if (aWidget->usesAttribute()) {
616 if (!aWidget->attributeID().empty() && !aFeature->attribute(aWidget->attributeID()).get()) {
617 std::string anErrorMsg = "The feature '%1' has no attribute '%2' used by widget '%3'.";
618 Events_InfoMessage("XGUI_Workshop", anErrorMsg)
619 .arg(aFeatureKind).arg(aWidget->attributeID())
620 .arg(aWidget->metaObject()->className()).send();
621 myPropertyPanel->cleanContent();
626 // for performance purpose, flush should be done after all controls are filled
627 bool isUpdateFlushed = false;
628 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
629 bool isStoreValue = !aFOperation->isEditOperation() &&
630 !aWidget->getDefaultValue().empty() &&
631 !aWidget->isComputedDefault();
632 aWidget->setFeature(aFeature, isStoreValue, isUpdateFlushed);
634 aWidget->restoreValue();
635 aWidget->enableFocusProcessing();
637 // update visible state of Preview button
638 std::shared_ptr<Config_FeatureMessage> aFeatureInfo;
640 aFeatureInfo = mySalomeConnector->featureInfo(aFeatureKind.c_str());
642 AppElements_MainMenu* aMenuBar = mainWindow()->menuObject();
643 AppElements_Command* aCommand = aMenuBar->feature(aFeatureKind.c_str());
645 aFeatureInfo = aCommand->featureMessage();
647 bool anIsAutoPreview = true;
648 if (aFeatureInfo.get())
649 anIsAutoPreview = aFeatureInfo->isAutoPreview();
651 std::string aXmlCfg, aDescription;
652 module()->getXMLRepresentation(aFeatureKind, aXmlCfg, aDescription);
653 ModuleBase_WidgetFactory aFactory(aXmlCfg, moduleConnector());
654 anIsAutoPreview = aFactory.widgetAPI()->getBooleanAttribute(FEATURE_AUTO_PREVIEW, true);
657 if (!anIsAutoPreview) {
658 myPropertyPanel->findButton(PROP_PANEL_PREVIEW)->setVisible(true);
659 // send signal about preview should not be computed automatically, click on preview
660 // button should initiate it
661 std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
662 new Events_Message(Events_Loop::eventByName(EVENT_PREVIEW_BLOCKED)));
663 Events_Loop::loop()->send(aMsg);
665 // if update happens after preview is blocked, it does nothing when blocked
666 // it improves performance for valid objects on feature start
667 ModuleBase_Tools::flushUpdated(aFeature);
669 myPropertyPanel->setModelWidgets(aWidgets);
670 aFOperation->setPropertyPanel(myPropertyPanel);
672 myModule->propertyPanelDefined(theOperation);
674 #ifndef DEBUG_FEATURE_NAME
675 myPropertyPanel->setWindowTitle(theOperation->getDescription()->description());
677 std::string aFeatureName = aFeature->name();
678 myPropertyPanel->setWindowTitle(QString("%1: %2")
679 .arg(theOperation->getDescription()->description())
680 .arg(aFeatureName.c_str()));
683 myErrorMgr->setPropertyPanel(myPropertyPanel);
686 //******************************************************
687 void XGUI_Workshop::connectToPropertyPanel(const bool isToConnect)
689 XGUI_PropertyPanel* aPropertyPanel = propertyPanel();
690 if (aPropertyPanel) {
691 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
692 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
693 myModule->connectToPropertyPanel(aWidget, isToConnect);
695 connect(aWidget, SIGNAL(valueStateChanged(int)), this, SLOT(onWidgetStateChanged(int)));
696 connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
697 connect(aWidget, SIGNAL(objectUpdated()), this, SLOT(onWidgetObjectUpdated()));
700 disconnect(aWidget, SIGNAL(valueStateChanged(int)), this, SLOT(onWidgetStateChanged(int)));
701 disconnect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
702 disconnect(aWidget, SIGNAL(objectUpdated()), this, SLOT(onWidgetObjectUpdated()));
708 //******************************************************
709 void XGUI_Workshop::onOperationResumed(ModuleBase_Operation* theOperation)
711 setGrantedFeatures(theOperation);
713 if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
714 fillPropertyPanel(theOperation);
715 connectToPropertyPanel(true);
717 updateCommandStatus();
719 myModule->operationResumed(theOperation);
722 //******************************************************
723 void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
725 updateCommandStatus();
727 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
732 ModuleBase_ISelection* aSel = mySelector->selection();
733 QObjectPtrList aObj = aSel->selectedPresentations();
734 //!< No need for property panel
735 hidePanel(myPropertyPanel);
736 myPropertyPanel->cleanContent();
738 connectToPropertyPanel(false);
739 myModule->operationStopped(aFOperation);
741 // the deactivated objects of the current operation should be activated back.
742 // They were deactivated on operation start or an object redisplay
743 QObjectPtrList anObjects;
744 FeaturePtr aFeature = aFOperation->feature();
745 if (aFeature.get()) { // feature may be not created (plugin load fail)
746 if (myDisplayer->isVisible(aFeature) && !selectionActivate()->isActive(aFeature))
747 anObjects.append(aFeature);
748 std::list<ResultPtr> aResults;
749 ModelAPI_Tools::allResults(aFeature, aResults);
750 std::list<ResultPtr>::const_iterator aIt;
751 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
752 ResultPtr anObject = *aIt;
753 if (myDisplayer->isVisible(anObject) && !selectionActivate()->isActive(anObject)) {
754 anObjects.append(anObject);
758 activateObjectsSelection(anObjects);
761 //******************************************************
762 void XGUI_Workshop::onOperationCommitted(ModuleBase_Operation* theOperation)
764 myModule->operationCommitted(theOperation);
767 //******************************************************
768 void XGUI_Workshop::onOperationAborted(ModuleBase_Operation* theOperation)
770 myModule->operationAborted(theOperation);
773 //******************************************************
774 void XGUI_Workshop::setGrantedFeatures(ModuleBase_Operation* theOperation)
776 ModuleBase_OperationFeature* aFOperation =
777 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
781 QStringList aGrantedIds;
782 if (isSalomeMode()) {
783 const std::shared_ptr<Config_FeatureMessage>& anInfo =
784 mySalomeConnector->featureInfo(theOperation->id());
786 aGrantedIds = QString::fromStdString(anInfo->nestedFeatures())
787 .split(" ", QString::SkipEmptyParts);
790 aGrantedIds = myActionsMgr->nestedCommands(theOperation->id());
792 ModuleBase_IModule* aModule = module();
794 aModule->grantedOperationIds(theOperation, aGrantedIds);
796 aFOperation->setGrantedOperationIds(aGrantedIds);
799 //******************************************************
800 void XGUI_Workshop::saveDocument(const QString& theName, std::list<std::string>& theFileNames)
802 QApplication::restoreOverrideCursor();
803 SessionPtr aMgr = ModelAPI_Session::get();
805 std::list<DocumentPtr> aDocList = aMgr->allOpenedDocuments();
806 std::list<DocumentPtr>::const_iterator aIt;
807 for (aIt = aDocList.cbegin(); aIt != aDocList.cend(); aIt++) {
808 std::list<bool> aState = myObjectBrowser->getStateForDoc(*aIt);
809 (*aIt)->storeNodesState(aState);
812 aMgr->save(theName.toLatin1().constData(), theFileNames);
814 QApplication::restoreOverrideCursor();
817 //******************************************************
818 bool XGUI_Workshop::abortAllOperations()
820 return myOperationMgr->abortAllOperations();
823 //******************************************************
824 void XGUI_Workshop::operationStarted(ModuleBase_Operation* theOperation)
826 setGrantedFeatures(theOperation);
827 if (!theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
828 updateCommandStatus();
831 myModule->operationStarted(theOperation);
835 //******************************************************
836 void XGUI_Workshop::onOpen()
838 if(!abortAllOperations())
840 //save current file before close if modified
841 SessionPtr aSession = ModelAPI_Session::get();
842 if (aSession->isModified()) {
843 //TODO(sbh): re-launch the app?
844 int anAnswer = QMessageBox::question(
845 desktop(), tr("Save current file"),
846 tr("The document is modified, save before opening another?"),
847 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
848 if (anAnswer == QMessageBox::Save) {
850 } else if (anAnswer == QMessageBox::Cancel) {
856 //show file dialog, check if readable and open
857 QString aDirectory = QFileDialog::getExistingDirectory(desktop(), tr("Select directory"));
858 openDirectory(aDirectory);
861 //******************************************************
862 void XGUI_Workshop::openDirectory(const QString& theDirectory)
864 myCurrentDir = theDirectory;
865 if (myCurrentDir.isEmpty())
868 QFileInfo aFileInfo(myCurrentDir);
869 if (!aFileInfo.exists() || !aFileInfo.isReadable()) {
870 QMessageBox::critical(desktop(), tr("Warning"), tr("Unable to open the file."));
875 QApplication::setOverrideCursor(Qt::WaitCursor);
876 module()->closeDocument();
877 SessionPtr aSession = ModelAPI_Session::get();
878 aSession->closeAll();
879 aSession->load(myCurrentDir.toLatin1().constData());
880 myObjectBrowser->rebuildDataTree();
882 // Open first level of data tree
883 DocumentPtr aRootDoc = aSession->moduleDocument();
884 std::list<bool> aStates;
885 aRootDoc->restoreNodesState(aStates);
886 myObjectBrowser->setStateForDoc(aRootDoc, aStates);
888 updateCommandStatus();
890 myMainWindow->setCurrentDir(myCurrentDir, true);
894 bool aNewPart = Config_PropManager::boolean("Plugins", "create_part_by_start");
897 DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
898 int aSize = aRootDoc->size(ModelAPI_ResultPart::group());
900 ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), 0);
901 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
908 QApplication::restoreOverrideCursor();
911 //******************************************************
912 void XGUI_Workshop::onNew()
914 QApplication::setOverrideCursor(Qt::WaitCursor);
915 if (objectBrowser() == 0) {
917 mySelector->connectViewers();
919 myViewerProxy->connectToViewer();
922 myMainWindow->showPythonConsole();
923 QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
924 aWnd->showMaximized();
925 updateCommandStatus();
927 myContextMenuMgr->connectViewer();
928 QApplication::restoreOverrideCursor();
932 //******************************************************
933 void XGUI_Workshop::onExit()
935 SessionPtr aMgr = ModelAPI_Session::get();
936 if (aMgr->isModified()) {
937 int anAnswer = QMessageBox::question(
938 myMainWindow, tr("Save current file"), tr("The document is modified, save before exit?"),
939 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
940 if (anAnswer == QMessageBox::Save) {
941 bool saved = onSave();
945 } else if (anAnswer == QMessageBox::Cancel) {
952 //******************************************************
953 void XGUI_Workshop::onPreferences()
955 ModuleBase_Prefs aModif;
956 ModuleBase_Preferences::editPreferences(aModif);
957 if (aModif.size() > 0) {
959 foreach (ModuleBase_Pref aPref, aModif)
961 aSection = aPref.first;
962 if (aSection == ModuleBase_Preferences::VIEWER_SECTION) {
963 myMainWindow->viewer()->updateFromResources();
964 } else if (aSection == ModuleBase_Preferences::MENU_SECTION) {
965 myMainWindow->menuObject()->updateFromResources();
968 displayer()->redisplayObjects();
973 //******************************************************
974 void XGUI_Workshop::onTrihedronVisibilityChanged(bool theState)
976 XGUI_Displayer* aDisplayer = displayer();
978 aDisplayer->displayTrihedron(theState);
981 //******************************************************
982 bool XGUI_Workshop::onSave()
984 if(!myOperationMgr->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
986 if (myCurrentDir.isEmpty()) {
989 std::list<std::string> aFiles;
990 saveDocument(myCurrentDir, aFiles);
991 updateCommandStatus();
993 myMainWindow->setModifiedState(false);
998 //******************************************************
999 bool XGUI_Workshop::onSaveAs()
1001 if(!myOperationMgr->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
1003 QFileDialog dialog(desktop());
1004 dialog.setWindowTitle(tr("Select directory to save files..."));
1005 dialog.setFileMode(QFileDialog::Directory);
1006 dialog.setFilter(QDir::AllDirs);
1007 dialog.setOptions(QFileDialog::HideNameFilterDetails | QFileDialog::ShowDirsOnly);
1008 dialog.setViewMode(QFileDialog::Detail);
1010 if (!dialog.exec()) {
1014 QString aTempDir = dialog.selectedFiles().first();
1015 QDir aDir(aTempDir);
1016 if (aDir.exists() && !aDir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries).isEmpty()) {
1017 int answer = QMessageBox::question(
1019 // Title of the dialog which asks user if he wants to save study
1020 // in existing non-empty folder
1022 tr("The directory already contains some files, save anyway?"),
1023 QMessageBox::Save | QMessageBox::Cancel);
1024 if (answer == QMessageBox::Cancel) {
1028 myCurrentDir = aTempDir;
1030 myMainWindow->setCurrentDir(myCurrentDir, false);
1031 myMainWindow->setModifiedState(false);
1036 //******************************************************
1037 void XGUI_Workshop::onUndo(int theTimes)
1039 processUndoRedo(ActionUndo, theTimes);
1040 myObjectBrowser->updateAllIndexes(1);
1043 //******************************************************
1044 void XGUI_Workshop::onRedo(int theTimes)
1046 processUndoRedo(ActionRedo, theTimes);
1047 myObjectBrowser->updateAllIndexes(1);
1050 //******************************************************
1051 void XGUI_Workshop::processUndoRedo(const ModuleBase_ActionType theActionType, int theTimes)
1053 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1054 if (anActiveWidget) {
1055 ActionIntParamPtr aParam(new ModuleBase_ActionIntParameter(theTimes));
1056 if (anActiveWidget->processAction(theActionType, aParam))
1059 // the viewer update should be blocked in order to avoid the features blinking. For the created
1060 // feature a results are created, the flush of the created signal caused the viewer redisplay for
1061 // each created result. After a redisplay signal is flushed. So, the viewer update is blocked
1062 // until redo of all possible objects happens
1063 bool isUpdateEnabled = myDisplayer->enableUpdateViewer(false);
1065 SessionPtr aMgr = ModelAPI_Session::get();
1066 if (aMgr->isOperation()) {
1067 XGUI_OperationMgr* aOpMgr = operationMgr();
1068 /// this is important for nested operations
1069 /// when sketch operation is active, this condition is false and
1070 /// the sketch operation is not aborted
1071 if (aOpMgr->canStopOperation(aOpMgr->currentOperation()))
1072 aOpMgr->abortOperation(aOpMgr->currentOperation());
1075 myDisplayer->enableUpdateViewer(isUpdateEnabled);
1079 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
1080 std::list<std::string> anActionList = theActionType == ActionUndo ? aMgr->undoList()
1082 std::list<std::string>::const_iterator aIt = anActionList.cbegin();
1083 for (int i = 0; (i < theTimes) && (aIt != anActionList.cend()); ++i, ++aIt) {
1084 if (theActionType == ActionUndo)
1089 if (QString((*aIt).c_str()) == MOVE_TO_END_COMMAND)
1090 myObjectBrowser->rebuildDataTree();
1092 operationMgr()->updateApplyOfOperations();
1093 facesPanel()->reset(true);
1094 updateCommandStatus();
1096 // unblock the viewer update functionality and make update on purpose
1097 myDisplayer->enableUpdateViewer(isUpdateEnabled);
1098 myDisplayer->updateViewer();
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 myInspectionPanel = new XGUI_InspectionPanel(aDesktop, mySelector);
1347 myInspectionPanel->setAllowedAreas(Qt::LeftDockWidgetArea |
1348 Qt::RightDockWidgetArea);
1349 aDesktop->addDockWidget(Qt::RightDockWidgetArea, myInspectionPanel);
1351 aDesktop->addDockWidget(
1353 Qt::RightDockWidgetArea,
1355 Qt::LeftDockWidgetArea,
1358 hidePanel(myFacesPanel); ///<! Invisible by default
1361 bool aShowOnTheRight = Config_PropManager::boolean("Plugins", "show_hide_faces");
1362 if (aShowOnTheRight) {
1363 aDesktop->addDockWidget(Qt::RightDockWidgetArea, myFacesPanel);
1364 showPanel(myFacesPanel);
1367 hideObjectBrowser();
1371 if (!aShowOnTheRight)
1374 aDesktop->tabifyDockWidget(myFacesPanel, aObjDock);
1379 #endif // HAVE_SALOME
1381 aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
1382 myPropertyPanel->installEventFilter(myOperationMgr);
1384 QAction* aOkAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept);
1385 connect(aOkAct, SIGNAL(triggered()), this, SLOT(onAcceptActionClicked()));
1387 QAction* aOkContAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptPlus);
1388 connect(aOkContAct, SIGNAL(triggered()), this, SLOT(onAcceptPlusActionClicked()));
1390 QAction* aCancelAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Abort);
1391 connect(aCancelAct, SIGNAL(triggered()), myOperationMgr, SLOT(onAbortOperation()));
1393 QAction* aPreviewAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Preview);
1394 connect(aPreviewAct, SIGNAL(triggered()), this, SLOT(onPreviewActionClicked()));
1396 connect(myPropertyPanel, SIGNAL(keyReleased(QObject*, QKeyEvent*)),
1397 myOperationMgr, SLOT(onKeyReleased(QObject*, QKeyEvent*)));
1398 connect(myPropertyPanel, SIGNAL(enterClicked(QObject*)),
1399 myOperationMgr, SLOT(onProcessEnter(QObject*)));
1402 //******************************************************
1403 void XGUI_Workshop::showPanel(QDockWidget* theDockWidget)
1405 if (theDockWidget == myPropertyPanel) {
1406 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1407 ///<! Restore ability to close panel from the window's menu
1408 aViewAct->setEnabled(true);
1410 theDockWidget->show();
1411 theDockWidget->raise();
1413 // The next code is necessary to made the property panel the active window
1414 // in order to operation manager could process key events of the panel.
1415 // otherwise they are ignored. It happens only if the same(activateWindow) is
1416 // not happened by property panel activation(e.g. resume operation of Sketch)
1417 ModuleBase_Tools::setFocus(theDockWidget, "XGUI_Workshop::showPanel()");
1420 //******************************************************
1421 void XGUI_Workshop::hidePanel(QDockWidget* theDockWidget)
1423 if (theDockWidget && theDockWidget == myPropertyPanel) {
1424 QAction* aViewAct = theDockWidget->toggleViewAction();
1425 ///<! Do not allow to show empty property panel
1426 aViewAct->setEnabled(false);
1428 theDockWidget->hide();
1430 // the property panel is active window of the desktop, when it is
1431 // hidden, it is undefined which window becomes active. By this reason
1432 // it is defined to perform the desktop as the active window.
1433 // in SALOME mode, workstack made the PyConsole the active window,
1434 // set the focus on it. As a result, shortcuts of the application, like
1435 // are processed by this console. For example Undo actions.
1436 // It is possible that this code is to be moved to SHAPER package
1437 QMainWindow* aDesktop = desktop();
1438 ModuleBase_Tools::setFocus(aDesktop, "XGUI_Workshop::hidePanel()");
1441 //******************************************************
1442 void XGUI_Workshop::showObjectBrowser()
1444 if (!isSalomeMode())
1445 myObjectBrowser->parentWidget()->show();
1448 //******************************************************
1449 void XGUI_Workshop::hideObjectBrowser()
1451 if (!isSalomeMode())
1452 myObjectBrowser->parentWidget()->hide();
1455 //******************************************************
1456 void XGUI_Workshop::salomeViewerSelectionChanged()
1458 emit salomeViewerSelection();
1461 //**************************************************************
1462 ModuleBase_IViewer* XGUI_Workshop::salomeViewer() const
1464 return mySalomeConnector->viewer();
1467 //**************************************************************
1468 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
1470 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1471 if (theId == "DELETE_CMD")
1473 else if (theId == "CLEAN_HISTORY_CMD")
1475 else if (theId == "MOVE_CMD")
1477 else if (theId == "COLOR_CMD")
1478 changeColor(aObjects);
1479 else if (theId == "DEFLECTION_CMD")
1480 changeDeflection(aObjects);
1481 #ifdef USE_TRANSPARENCY
1482 else if (theId == "TRANSPARENCY_CMD")
1483 changeTransparency(aObjects);
1485 else if (theId == "SHOW_CMD") {
1486 showObjects(aObjects, true);
1487 mySelector->updateSelectionBy(ModuleBase_ISelection::Browser);
1488 updateCommandStatus();
1490 else if (theId == "HIDE_CMD") {
1491 showObjects(aObjects, false);
1492 updateCommandStatus();
1494 else if (theId == "SHOW_ONLY_CMD") {
1495 showOnlyObjects(aObjects);
1496 mySelector->updateSelectionBy(ModuleBase_ISelection::Browser);
1497 updateCommandStatus();
1499 else if (theId == "SHADING_CMD")
1500 setDisplayMode(aObjects, XGUI_Displayer::Shading);
1501 else if (theId == "WIREFRAME_CMD")
1502 setDisplayMode(aObjects, XGUI_Displayer::Wireframe);
1503 else if (theId == "HIDEALL_CMD") {
1504 QObjectPtrList aList = myDisplayer->displayedObjects();
1505 foreach (ObjectPtr aObj, aList) {
1506 if (module()->canEraseObject(aObj))
1507 aObj->setDisplayed(false);
1509 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1511 //issue #2159 Hide all incomplete behavior
1512 viewer()->eraseAll();
1514 updateCommandStatus();
1515 // Necessary for update icons in ObjectBrowser on Linux
1516 myObjectBrowser->updateAllIndexes();
1517 } else if (theId == "SELECT_VERTEX_CMD") {
1518 setViewerSelectionMode(TopAbs_VERTEX);
1519 } else if (theId == "SELECT_EDGE_CMD") {
1520 setViewerSelectionMode(TopAbs_EDGE);
1521 } else if (theId == "SELECT_FACE_CMD") {
1522 setViewerSelectionMode(TopAbs_FACE);
1523 } else if (theId == "INSERT_FOLDER_CMD") {
1524 insertFeatureFolder();
1525 } else if (theId == "ADD_TO_FOLDER_BEFORE_CMD") {
1526 insertToFolder(true);
1527 } else if (theId == "ADD_TO_FOLDER_AFTER_CMD") {
1528 insertToFolder(false);
1529 } else if (theId == "ADD_OUT_FOLDER_BEFORE_CMD") {
1530 moveOutFolder(true);
1531 } else if (theId == "ADD_OUT_FOLDER_AFTER_CMD") {
1532 moveOutFolder(false);
1533 } else if (theId == "SELECT_RESULT_CMD") {
1534 //setViewerSelectionMode(-1);
1535 //IMP: an attempt to use result selection with other selection modes
1536 setViewerSelectionMode(ModuleBase_ResultPrs::Sel_Result);
1537 setViewerSelectionMode(TopAbs_COMPSOLID);
1538 } else if (theId == "SHOW_RESULTS_CMD") {
1539 highlightResults(aObjects);
1540 } else if (theId == "SHOW_FEATURE_CMD") {
1541 highlightFeature(aObjects);
1544 else if (theId == "TINSPECTOR_VIEW") {
1545 Handle(CDF_Application) anApplication = CDF_Session::CurrentSession()->CurrentApplication();
1546 if (!anApplication.IsNull())
1548 if (!MyTCommunicator)
1550 MyTCommunicator = new TInspector_Communicator();
1552 NCollection_List<Handle(Standard_Transient)> aParameters;
1553 aParameters.Append(anApplication);
1554 Handle(AIS_InteractiveContext) aContext = viewer()->AISContext();
1555 if (!aContext.IsNull())
1556 aParameters.Append(aContext);
1558 #ifdef DEBUG_WITH_MESSAGE_REPORT
1559 Handle(Message_Report) aContextReport = aContext->GetReport();
1560 aContext->SetReportActive (Standard_True);
1561 aContextReport->SetLimit (1000);
1562 if (!aContextReport.IsNull())
1563 aParameters.Append(aContextReport);
1565 MyVCallBack = new VInspector_CallBack();
1566 myDisplayer->setCallBack(MyVCallBack);
1568 AppElements_Viewer* aViewer = mainWindow()->viewer();
1570 aViewer->setCallBack(MyVCallBack);
1572 aParameters.Append(MyVCallBack);
1574 MyTCommunicator->RegisterPlugin("TKDFBrowser");
1575 MyTCommunicator->RegisterPlugin("TKShapeView");
1576 MyTCommunicator->RegisterPlugin("TKVInspector");
1577 #ifdef DEBUG_WITH_MESSAGE_REPORT
1578 MyTCommunicator->RegisterPlugin("TKMessageView");
1580 MyTCommunicator->RegisterPlugin("SMBrowser"); // custom plugin to view ModelAPI
1581 //MyTCommunicator->RegisterPlugin("TKSMBrowser"); // custom plugin to view ModelAPI
1583 MyTCommunicator->Init(aParameters);
1584 MyTCommunicator->Activate("TKSMBrowser"); // to have button in TInspector
1585 #ifndef DEBUG_WITH_MESSAGE_REPORT
1586 MyTCommunicator->Activate("TKVInspector"); // to have filled callback by model
1588 MyTCommunicator->Activate("TKDFBrowser");
1590 #ifdef DEBUG_WITH_MESSAGE_REPORT
1591 MyTCommunicator->Activate("TKMessageView"); // temporary
1592 MyTCommunicator->Activate("TKVInspector"); // to have filled callback by model
1595 MyTCommunicator->SetVisible(true);
1601 //**************************************************************
1602 void XGUI_Workshop::setViewerSelectionMode(int theMode)
1605 myViewerSelMode.clear();
1607 if (myViewerSelMode.contains(theMode))
1608 myViewerSelMode.removeAll(theMode);
1610 myViewerSelMode.append(theMode);
1612 selectionActivate()->updateSelectionModes();
1615 //**************************************************************
1616 void XGUI_Workshop::activateObjectsSelection(const QObjectPtrList& theList)
1619 module()->activeSelectionModes(aModes);
1620 if (aModes.isEmpty() && (myViewerSelMode.length() > 0))
1621 aModes.append(myViewerSelMode);
1622 selectionActivate()->activateObjects(aModes, theList);
1625 //**************************************************************
1626 bool XGUI_Workshop::prepareForDisplay(const std::set<ObjectPtr>& theObjects) const
1628 if (facesPanel()->isEmpty())
1631 // generate container of objects taking into account sub elments of compsolid
1632 std::set<ObjectPtr> anAllProcessedObjects;
1633 for (std::set<ObjectPtr>::const_iterator anObjectsIt = theObjects.begin();
1634 anObjectsIt != theObjects.end(); anObjectsIt++) {
1635 ObjectPtr anObject = *anObjectsIt;
1636 ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(anObject);
1637 if (aCompRes.get()) {
1638 if (aCompRes->numberOfSubs(true) == 0)
1639 anAllProcessedObjects.insert(anObject);
1641 for (int i = 0; i < aCompRes->numberOfSubs(true); i++) {
1642 ResultPtr aSubRes = aCompRes->subResult(i, true);
1643 anAllProcessedObjects.insert(aCompRes->subResult(i, true));
1648 anAllProcessedObjects.insert(anObject);
1651 // find hidden objects in faces panel
1652 std::set<ObjectPtr> aHiddenObjects;
1653 QStringList aHiddenObjectNames;
1654 for (std::set<ObjectPtr>::const_iterator anObjectsIt = anAllProcessedObjects.begin();
1655 anObjectsIt != anAllProcessedObjects.end(); anObjectsIt++) {
1656 if (!facesPanel()->isObjectHiddenByPanel(*anObjectsIt))
1658 aHiddenObjects.insert(*anObjectsIt);
1659 aHiddenObjectNames.append((*anObjectsIt)->data()->name().c_str());
1661 if (aHiddenObjects.empty()) // in parameter objects there are no hidden objects in hide face
1664 int anAnswer = QMessageBox::question(
1665 desktop(), tr("Show object"),
1666 tr("'%1'\n are hidden by %2:\nRemove objects from the panel to be displayed?")
1667 .arg(aHiddenObjectNames.join(", ")).arg(facesPanel()->windowTitle()),
1668 QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
1670 bool aToBeDisplayed = anAnswer == QMessageBox::Yes;
1672 facesPanel()->restoreObjects(aHiddenObjects);
1674 return aToBeDisplayed;
1677 //**************************************************************
1678 void XGUI_Workshop::deleteObjects()
1680 ModuleBase_IModule* aModule = module();
1681 // allow the module to delete objects, do nothing if it has succeed
1682 if (aModule->deleteObjects()) {
1683 updateCommandStatus();
1687 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1688 if (!abortAllOperations())
1691 bool hasResult = false;
1692 bool hasFeature = false;
1693 bool hasParameter = false;
1694 bool hasCompositeOwner = false;
1695 bool hasResultInHistory = false;
1696 bool hasFolder = false;
1697 ModuleBase_Tools::checkObjects(anObjects, hasResult, hasFeature, hasParameter, hasCompositeOwner,
1698 hasResultInHistory, hasFolder);
1699 if (!(hasFeature || hasParameter || hasFolder))
1703 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1704 std::set<FeaturePtr> aFeatures;
1705 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1706 ModelAPI_Tools::findAllReferences(aFeatures, aReferences);
1708 std::set<FolderPtr> aFolders;
1709 ModuleBase_Tools::convertToFolders(anObjects, aFolders);
1712 QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text() + " %1";
1713 aDescription = aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
1714 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, module());
1716 operationMgr()->startOperation(anOpAction);
1718 std::set<FeaturePtr> aFeatureRefsToDelete;
1719 if (ModuleBase_Tools::askToDelete(aFeatures, aReferences, desktop(), aFeatureRefsToDelete)) {
1720 // WORKAROUND, should be done before each object remove, if it presents in XGUI_DataModel tree
1721 // It is necessary to clear selection in order to avoid selection changed event during
1722 // deletion and negative consequences connected with processing of already deleted items
1723 mySelector->clearSelection();
1725 if (!aFeatureRefsToDelete.empty())
1726 aFeatures.insert(aFeatureRefsToDelete.begin(), aFeatureRefsToDelete.end());
1727 aDone = ModelAPI_Tools::removeFeatures(aFeatures, false);
1729 if (aFolders.size() > 0) {
1730 std::set<FolderPtr>::const_iterator anIt = aFolders.begin(),
1731 aLast = aFolders.end();
1732 for (; anIt != aLast; anIt++) {
1733 FolderPtr aFolder = *anIt;
1734 if (aFolder.get()) {
1735 DocumentPtr aDoc = aFolder->document();
1736 aDoc->removeFolder(aFolder);
1742 operationMgr()->commitOperation();
1744 operationMgr()->abortOperation(operationMgr()->currentOperation());
1747 //**************************************************************
1748 void addRefsToFeature(const FeaturePtr& theFeature,
1749 const std::map<FeaturePtr, std::set<FeaturePtr> >& theMainList,
1750 std::set<FeaturePtr>& theReferences)
1752 //if (theReferences.find(theFeature) != theReferences.end())
1754 if (theMainList.find(theFeature) == theMainList.end())
1755 return; // this feature is not in the selection list, so exists without references to it
1756 std::set<FeaturePtr> aMainReferences = theMainList.at(theFeature);
1758 std::set<FeaturePtr>::const_iterator anIt = aMainReferences.begin(),
1759 aLast = aMainReferences.end();
1760 for (; anIt != aLast; anIt++) {
1761 FeaturePtr aRefFeature = *anIt;
1762 if (theReferences.find(aRefFeature) == theReferences.end())
1763 theReferences.insert(aRefFeature);
1764 addRefsToFeature(aRefFeature, theMainList, theReferences);
1768 //**************************************************************
1769 void XGUI_Workshop::cleanHistory()
1771 if (!abortAllOperations())
1774 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1775 std::set<FeaturePtr> aFeatures;
1776 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1778 #ifdef DEBUG_CLEAN_HISTORY
1780 std::set<FeaturePtr>::const_iterator aFIt;
1781 for (aFIt = aFeatures.begin(); aFIt != aFeatures.end(); ++aFIt) {
1782 FeaturePtr aFeature = ModelAPI_Feature::feature(*aFIt);
1783 anInfo.append(aFeature->name().c_str());
1785 QString anInfoStr = anInfo.join(";\t");
1786 qDebug(QString("cleanHistory for: [%1] - %2").
1787 arg(aFeatures.size()).arg(anInfoStr).toStdString().c_str());
1790 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1791 ModelAPI_Tools::findAllReferences(aFeatures, aReferences, true, false);
1792 // find for each object whether all reference values are in the map as key, that means that there
1793 // is no other reference in the model to this object, so it might be removed by cleaning history
1794 // sk_1(ext_1, vertex_1) + (sk_3, bool_1) - cann't be deleted, dependency to bool_1
1795 // ext_1(bool_1, sk_3) - cann't be deleted, dependency to bool_1
1797 // sk_2(ext_2) + (bool_1) - cann't be deleted, dependency to bool_1
1798 // ext_2(bool_1) - cann't be deleted, dependency to bool_1
1800 // Information: bool_1 is not selected
1801 std::set<FeaturePtr> anUnusedObjects;
1802 std::map<FeaturePtr, std::set<FeaturePtr> >::const_iterator aMainIt = aReferences.begin(),
1803 aMainLast = aReferences.end();
1804 for (; aMainIt != aMainLast; aMainIt++) {
1805 FeaturePtr aMainListFeature = aMainIt->first;
1806 std::set<FeaturePtr> aMainRefList = aMainIt->second;
1807 std::set<FeaturePtr>::const_iterator aRefIt = aMainRefList.begin(),
1808 aRefLast = aMainRefList.end();
1809 bool aFeatureOutOfTheList = false;
1810 for (; aRefIt != aRefLast && !aFeatureOutOfTheList; aRefIt++) {
1811 FeaturePtr aRefFeature = *aRefIt;
1812 aFeatureOutOfTheList = aReferences.find(aRefFeature) == aReferences.end();
1814 if (!aFeatureOutOfTheList)
1815 anUnusedObjects.insert(aMainListFeature);
1818 #ifdef DEBUG_CLEAN_HISTORY
1820 for (aFIt = anUnusedObjects.begin(); aFIt != anUnusedObjects.end(); ++aFIt) {
1821 FeaturePtr aFeature = *aFIt;
1822 anInfo.append(aFeature->name().c_str());
1824 qDebug(QString("unused objects: [%1] - %2").
1825 arg(anInfo.size()).arg(anInfo.join(";\t")).toStdString().c_str());
1828 // warn about the references remove, break the delete operation if the user chose it
1829 if (!anUnusedObjects.empty()) {
1831 foreach (const FeaturePtr& aFeature, anUnusedObjects) {
1832 aNames.append(aFeature->name().c_str());
1835 QString anUnusedNames = aNames.join(", ");
1837 QString anActionId = "CLEAN_HISTORY_CMD";
1838 QString aDescription = contextMenuMgr()->action(anActionId)->text();
1840 QMessageBox aMessageBox(desktop());
1841 aMessageBox.setWindowTitle(aDescription);
1842 aMessageBox.setIcon(QMessageBox::Warning);
1843 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
1844 aMessageBox.setDefaultButton(QMessageBox::No);
1846 const char* aKeyStr = "Unused features are the following: "
1847 "%1.\nThese features will be deleted.\nWould you like to continue?";
1848 QString aText = QString(tr(aKeyStr).arg(anUnusedNames));
1849 aMessageBox.setText(aText);
1850 if (aMessageBox.exec() == QMessageBox::No)
1853 // 1. start operation
1854 aDescription += "by deleting of " +
1855 aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
1856 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, module());
1857 operationMgr()->startOperation(anOpAction);
1859 // WORKAROUND, should be done before each object remove, if it presents in XGUI_DataModel tree
1860 // It is necessary to clear selection in order to avoid selection changed event during
1861 // deletion and negative consequences connected with processing of already deleted items
1862 mySelector->clearSelection();
1864 std::set<FeaturePtr> anIgnoredFeatures;
1865 if (ModelAPI_Tools::removeFeatures(anUnusedObjects, true)) {
1866 operationMgr()->commitOperation();
1869 operationMgr()->abortOperation(operationMgr()->currentOperation());
1873 QString anActionId = "CLEAN_HISTORY_CMD";
1874 QString aDescription = contextMenuMgr()->action(anActionId)->text();
1876 QMessageBox aMessageBox(desktop());
1877 aMessageBox.setWindowTitle(aDescription);
1878 aMessageBox.setIcon(QMessageBox::Warning);
1879 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
1880 aMessageBox.setDefaultButton(QMessageBox::No);
1883 aMessageBox.setStandardButtons(QMessageBox::Ok);
1884 aMessageBox.setDefaultButton(QMessageBox::Ok);
1886 aText = QString(tr("All features are relevant, there is nothing to be deleted"));
1887 aMessageBox.setText(aText);
1889 if (aMessageBox.exec() == QMessageBox::No)
1894 //**************************************************************
1895 void XGUI_Workshop::moveObjects()
1897 if (!abortAllOperations())
1900 SessionPtr aMgr = ModelAPI_Session::get();
1902 QString anActionId = "MOVE_CMD";
1903 QString aDescription = contextMenuMgr()->action(anActionId)->text();
1904 aMgr->startOperation(aDescription.toStdString());
1906 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1907 // It is necessary to clear selection in order to avoid selection changed event during
1908 // moving and negative consequences connected with processing of already moved items
1909 mySelector->clearSelection();
1910 // check whether the object can be moved. There should not be parts which are not loaded
1911 std::set<FeaturePtr> aFeatures;
1912 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1913 if (!XGUI_Tools::canRemoveOrRename(desktop(), aFeatures))
1916 DocumentPtr anActiveDocument = aMgr->activeDocument();
1917 FeaturePtr aCurrentFeature = anActiveDocument->currentFeature(true);
1918 std::set<FeaturePtr>::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
1919 for (; anIt != aLast; anIt++) {
1920 FeaturePtr aFeature = *anIt;
1921 if (!aFeature.get() || !myModule->canApplyAction(aFeature, anActionId))
1924 anActiveDocument->moveFeature(aFeature, aCurrentFeature);
1925 aCurrentFeature = anActiveDocument->currentFeature(true);
1927 aMgr->finishOperation();
1930 //**************************************************************
1931 bool XGUI_Workshop::deleteFeatures(const QObjectPtrList& theObjects)
1933 std::set<FeaturePtr> aFeatures;
1934 ModuleBase_Tools::convertToFeatures(theObjects, aFeatures);
1936 return ModelAPI_Tools::removeFeaturesAndReferences(aFeatures);
1939 //******************************************************
1940 bool hasResults(QObjectPtrList theObjects, const std::set<std::string>& theTypes)
1942 bool isFoundResultType = false;
1943 foreach(ObjectPtr anObj, theObjects)
1945 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
1946 if (aResult.get() == NULL)
1949 isFoundResultType = theTypes.find(aResult->groupName()) != theTypes.end();
1950 if (isFoundResultType)
1953 return isFoundResultType;
1956 //**************************************************************
1957 // Returns the list of all features for theDocument and all features of
1958 // all nested parts.
1959 std::list<FeaturePtr> allFeatures(const DocumentPtr& theDocument)
1961 std::list<FeaturePtr> aResultList;
1962 std::list<FeaturePtr> anAllFeatures = theDocument->allFeatures();
1963 foreach (const FeaturePtr& aFeature, anAllFeatures) {
1964 // The order of appending features of the part and the part itself is important
1966 // Append features from a part feature
1967 std::list<ResultPtr> aResults;
1968 ModelAPI_Tools::allResults(aFeature, aResults);
1969 foreach (const ResultPtr& aResult, aResults) {
1970 ResultPartPtr aResultPart =
1971 std::dynamic_pointer_cast<ModelAPI_ResultPart>(aResult);
1972 if (aResultPart.get() && aResultPart->partDoc().get()) {
1974 std::list<FeaturePtr> anAllFeatures = allFeatures(aResultPart->partDoc());
1975 aResultList.insert(aResultList.end(), anAllFeatures.begin(), anAllFeatures.end());
1979 aResultList.push_back(aFeature);
1984 //**************************************************************
1985 // Returns the list of features placed between theObject and the current feature
1986 // in the same document. Excludes theObject, includes the current feature.
1987 std::list<FeaturePtr> toCurrentFeatures(const ObjectPtr& theObject)
1989 std::list<FeaturePtr> aResult;
1990 DocumentPtr aDocument = theObject->document();
1991 std::list<FeaturePtr> anAllFeatures = allFeatures(aDocument);
1992 // find the object iterator
1993 std::list<FeaturePtr>::iterator aObjectIt =
1994 std::find(anAllFeatures.begin(), anAllFeatures.end(), theObject);
1995 if (aObjectIt == anAllFeatures.end())
1997 // find the current feature iterator
1998 std::list<FeaturePtr>::iterator aCurrentIt =
1999 std::find(anAllFeatures.begin(), anAllFeatures.end(), aDocument->currentFeature(true));
2000 if (aCurrentIt == anAllFeatures.end())
2002 // check the right order
2003 if (std::distance(aObjectIt, anAllFeatures.end()) <=
2004 std::distance(aCurrentIt, anAllFeatures.end()))
2006 // exclude the object
2007 std::advance(aObjectIt, 1);
2008 // include the current feature
2009 std::advance(aCurrentIt, 1);
2010 return std::list<FeaturePtr>(aObjectIt, aCurrentIt);
2013 //******************************************************
2014 bool XGUI_Workshop::canMoveFeature()
2016 QString anActionId = "MOVE_CMD";
2018 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
2019 QObjectPtrList aValidatedObjects;
2020 foreach (ObjectPtr aObject, aObjects) {
2021 if (!myModule->canApplyAction(aObject, anActionId))
2023 // To be moved feature should be in active document
2024 if (aObject->document() != ModelAPI_Session::get()->activeDocument())
2026 aValidatedObjects.append(aObject);
2028 if (aValidatedObjects.size() != aObjects.size())
2029 aObjects = aValidatedObjects;
2031 bool aCanMove = !aObjects.empty();
2033 QObjectPtrList::const_iterator anIt = aObjects.begin(), aLast = aObjects.end();
2034 for (; anIt != aLast && aCanMove; anIt++) {
2035 ObjectPtr aObject = *anIt;
2036 if (!aObject.get() || !aObject->data().get() || !aObject->data()->isValid()) {
2040 FeaturePtr aFeat = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
2041 // only groups can be moved to the end for now (#2451)
2042 if (aFeat.get() && aFeat->getKind() != "Group") {
2047 // 1. Get features placed between selected and current in the document
2048 std::list<FeaturePtr> aFeaturesBetween = toCurrentFeatures(aObject);
2049 // if aFeaturesBetween is empty it means wrong order or aObject is the current feature
2050 if (aFeaturesBetween.empty())
2053 std::set<FeaturePtr> aPlacedFeatures(aFeaturesBetween.begin(), aFeaturesBetween.end());
2054 // 2. Get all reference features to the selected object in the document
2055 std::set<FeaturePtr> aRefFeatures;
2056 ModuleBase_Tools::refsToFeatureInFeatureDocument(aObject, aRefFeatures);
2058 if (aRefFeatures.empty())
2061 // 3. Find any placed features in all reference features
2062 std::set<FeaturePtr> aIntersectionFeatures;
2063 std::set_intersection(aRefFeatures.begin(), aRefFeatures.end(),
2064 aPlacedFeatures.begin(), aPlacedFeatures.end(),
2065 std::inserter(aIntersectionFeatures, aIntersectionFeatures.begin()));
2066 // 4. Return false if any reference feature is placed before current feature
2067 if (!aIntersectionFeatures.empty())
2075 //**************************************************************
2076 bool XGUI_Workshop::canBeShaded(const ObjectPtr& theObject) const
2078 bool aCanBeShaded = myDisplayer->canBeShaded(theObject);
2079 if (!aCanBeShaded) {
2080 ResultCompSolidPtr aCompsolidResult =
2081 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
2082 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
2083 for(int i = 0; i < aCompsolidResult->numberOfSubs() && !aCanBeShaded; i++)
2084 aCanBeShaded = myDisplayer->canBeShaded(aCompsolidResult->subResult(i));
2087 return aCanBeShaded;
2090 //**************************************************************
2091 bool XGUI_Workshop::canChangeProperty(const QString& theActionName) const
2093 if (theActionName == "COLOR_CMD" ||
2094 theActionName == "DEFLECTION_CMD"
2095 #ifdef USE_TRANSPARENCY
2096 || theActionName == "TRANSPARENCY_CMD"
2099 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
2101 std::set<std::string> aTypes;
2102 aTypes.insert(ModelAPI_ResultGroup::group());
2103 aTypes.insert(ModelAPI_ResultConstruction::group());
2104 aTypes.insert(ModelAPI_ResultBody::group());
2105 aTypes.insert(ModelAPI_ResultPart::group());
2107 return hasResults(aObjects, aTypes);
2112 //******************************************************
2113 void setColor(ResultPtr theResult, const std::vector<int>& theColor)
2115 if (!theResult.get())
2118 AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
2119 if (aColorAttr.get() != NULL) {
2120 if (!aColorAttr->size()) {
2121 aColorAttr->setSize(3);
2123 aColorAttr->setValue(0, theColor[0]);
2124 aColorAttr->setValue(1, theColor[1]);
2125 aColorAttr->setValue(2, theColor[2]);
2129 //**************************************************************
2130 void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
2133 AttributeIntArrayPtr aColorAttr;
2134 // 1. find the current color of the object. This is a color of AIS presentation
2135 // The objects are iterated until a first valid color is found
2136 std::vector<int> aColor;
2137 foreach(ObjectPtr anObject, theObjects) {
2138 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
2139 if (aResult.get()) {
2140 XGUI_CustomPrs::getResultColor(aResult, aColor);
2143 // TODO: remove the obtaining a color from the AIS object
2144 // this does not happen never because:
2145 // 1. The color can be changed only on results
2146 // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
2147 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
2148 if (anAISObj.get()) {
2150 anAISObj->getColor(aColor[0], aColor[1], aColor[2]);
2153 if (!aColor.empty())
2156 if (aColor.size() != 3)
2159 if (!abortAllOperations())
2161 // 2. show the dialog to change the value
2162 XGUI_ColorDialog* aDlg = new XGUI_ColorDialog(desktop());
2163 aDlg->setColor(aColor);
2164 aDlg->move(QCursor::pos());
2165 bool isDone = aDlg->exec() == QDialog::Accepted;
2169 bool isRandomColor = aDlg->isRandomColor();
2171 // 3. abort the previous operation and start a new one
2172 SessionPtr aMgr = ModelAPI_Session::get();
2173 QString aDescription = contextMenuMgr()->action("COLOR_CMD")->text();
2174 aMgr->startOperation(aDescription.toStdString());
2176 // 4. set the value to all results
2177 std::vector<int> aColorResult = aDlg->getColor();
2178 foreach(ObjectPtr anObj, theObjects) {
2179 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
2180 if (aResult.get() != NULL) {
2181 ResultCompSolidPtr aCompsolidResult =
2182 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
2183 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
2184 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
2185 setColor(aCompsolidResult->subResult(i), !isRandomColor ? aColorResult :
2186 aDlg->getRandomColor());
2189 setColor(aResult, !isRandomColor ? aColorResult : aDlg->getRandomColor());
2192 aMgr->finishOperation();
2193 updateCommandStatus();
2196 //**************************************************************
2197 void setDeflection(ResultPtr theResult, const double theDeflection)
2199 if (!theResult.get())
2202 AttributeDoublePtr aDeflectionAttr = theResult->data()->real(ModelAPI_Result::DEFLECTION_ID());
2203 if (aDeflectionAttr.get() != NULL)
2204 aDeflectionAttr->setValue(theDeflection);
2207 //**************************************************************
2208 void setTransparency(ResultPtr theResult, double theTransparency)
2210 if (!theResult.get())
2213 AttributeDoublePtr anAttribute = theResult->data()->real(ModelAPI_Result::TRANSPARENCY_ID());
2214 if (anAttribute.get() != NULL)
2215 anAttribute->setValue(theTransparency);
2218 //**************************************************************
2219 void setTransparency(double theTransparency, const QObjectPtrList& theObjects)
2221 foreach(ObjectPtr anObj, theObjects) {
2222 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
2223 if (aResult.get() != NULL) {
2224 ResultCompSolidPtr aCompsolidResult =
2225 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
2226 if (aCompsolidResult.get() != NULL) { // change property for all sub-solids
2227 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
2228 setTransparency(aCompsolidResult->subResult(i), theTransparency);
2231 setTransparency(aResult, theTransparency);
2236 //**************************************************************
2237 void XGUI_Workshop::changeDeflection(const QObjectPtrList& theObjects)
2239 AttributeDoublePtr aDoubleAttr;
2240 // 1. find the current property of the object. This is a property of AIS presentation
2241 // The objects are iterated until a first valid property is found
2242 double aDeflection = -1;
2243 foreach(ObjectPtr anObject, theObjects) {
2244 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
2245 if (aResult.get()) {
2246 aDeflection = XGUI_CustomPrs::getResultDeflection(aResult);
2249 // TODO: remove the obtaining a property from the AIS object
2250 // this does not happen never because:
2251 // 1. The property can be changed only on results
2252 // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
2253 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
2254 if (anAISObj.get()) {
2255 aDeflection = anAISObj->getDeflection();
2258 if (aDeflection > 0)
2261 if (aDeflection < 0)
2264 if (!abortAllOperations())
2266 // 2. show the dialog to change the value
2267 XGUI_DeflectionDialog* aDlg = new XGUI_DeflectionDialog(desktop());
2268 aDlg->setDeflection(aDeflection);
2269 aDlg->move(QCursor::pos());
2270 bool isDone = aDlg->exec() == QDialog::Accepted;
2274 // 3. abort the previous operation and start a new one
2275 SessionPtr aMgr = ModelAPI_Session::get();
2276 QString aDescription = contextMenuMgr()->action("DEFLECTION_CMD")->text();
2277 aMgr->startOperation(aDescription.toStdString());
2279 // 4. set the value to all results
2280 aDeflection = aDlg->getDeflection();
2281 foreach(ObjectPtr anObj, theObjects) {
2282 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
2283 if (aResult.get() != NULL) {
2284 ResultCompSolidPtr aCompsolidResult =
2285 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
2286 if (aCompsolidResult.get() != NULL) { // change property for all sub-solids
2287 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
2288 setDeflection(aCompsolidResult->subResult(i), aDeflection);
2291 setDeflection(aResult, aDeflection);
2294 aMgr->finishOperation();
2295 updateCommandStatus();
2298 //**************************************************************
2299 void XGUI_Workshop::changeTransparency(const QObjectPtrList& theObjects)
2301 AttributeDoublePtr aDoubleAttr;
2302 // 1. find the current property of the object. This is a property of AIS presentation
2303 // The objects are iterated until a first valid property is found
2304 double aCurrentValue = -1;
2305 foreach(ObjectPtr anObject, theObjects) {
2306 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
2307 if (aResult.get()) {
2308 aCurrentValue = XGUI_CustomPrs::getResultTransparency(aResult);
2311 // TODO: remove the obtaining a property from the AIS object
2312 // this does not happen never because:
2313 // 1. The property can be changed only on results
2314 // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
2315 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
2316 if (anAISObj.get()) {
2317 aCurrentValue = anAISObj->getDeflection();
2320 if (aCurrentValue > 0)
2323 if (aCurrentValue < 0)
2326 if (!abortAllOperations())
2329 // 2. show the dialog to change the value
2330 XGUI_PropertyDialog* aDlg = new XGUI_PropertyDialog(desktop());
2331 aDlg->setWindowTitle("Transparency");
2332 XGUI_TransparencyWidget* aTransparencyWidget = new XGUI_TransparencyWidget(aDlg);
2333 connect(aTransparencyWidget, SIGNAL(transparencyValueChanged()),
2334 this, SLOT(onTransparencyValueChanged()));
2335 connect(aTransparencyWidget, SIGNAL(previewStateChanged()),
2336 this, SLOT(onPreviewStateChanged()));
2337 aDlg->setContent(aTransparencyWidget);
2338 aTransparencyWidget->setValue(aCurrentValue);
2340 // 3. abort the previous operation and start a new one
2341 SessionPtr aMgr = ModelAPI_Session::get();
2342 QString aDescription = contextMenuMgr()->action("TRANSPARENCY_CMD")->text();
2343 aMgr->startOperation(aDescription.toStdString());
2345 aDlg->move(QCursor::pos());
2346 bool isDone = aDlg->exec() == QDialog::Accepted;
2350 // 4. set the value to all results
2351 aCurrentValue = aTransparencyWidget->getValue();
2352 setTransparency(aCurrentValue, theObjects);
2354 aMgr->finishOperation();
2355 updateCommandStatus();
2358 //**************************************************************
2359 void XGUI_Workshop::onTransparencyValueChanged()
2361 XGUI_TransparencyWidget* aTransparencyWidget = (XGUI_TransparencyWidget*)sender();
2362 if (!aTransparencyWidget || !aTransparencyWidget->isPreviewNeeded())
2365 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
2366 setTransparency(aTransparencyWidget->getValue(), anObjects);
2367 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2370 //**************************************************************
2371 void XGUI_Workshop::onPreviewStateChanged()
2373 XGUI_TransparencyWidget* aTransparencyWidget = (XGUI_TransparencyWidget*)sender();
2374 if (!aTransparencyWidget || !aTransparencyWidget->isPreviewNeeded())
2377 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
2378 setTransparency(aTransparencyWidget->getValue(), anObjects);
2379 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2382 //**************************************************************
2383 #define SET_DISPLAY_GROUP(aGroupName, aDisplay) \
2384 for (int i = 0; i < aDoc->size(aGroupName); i++) { \
2385 aDoc->object(aGroupName, i)->setDisplayed(aDisplay); \
2388 //******************************************************
2389 void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible)
2392 std::set<ObjectPtr> anObjects;
2393 foreach (ObjectPtr aObj, theList) {
2394 anObjects.insert(aObj);
2396 if (!prepareForDisplay(anObjects))
2400 foreach (ObjectPtr aObj, theList) {
2401 aObj->setDisplayed(isVisible);
2403 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2404 myObjectBrowser->updateAllIndexes();
2407 //**************************************************************
2408 void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList)
2410 // Hide all displayed objects
2411 QObjectPtrList aList = myDisplayer->displayedObjects();
2412 foreach (ObjectPtr aObj, aList) {
2413 if (module()->canEraseObject(aObj))
2414 aObj->setDisplayed(false);
2416 //Do not use eraseAll if you didn't send Redisplay event:
2417 //all objects are erased from viewer, but considered as displayed in displayer
2418 // Problem in bug 2218
2419 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2421 //issue #2159 Hide all incomplete behavior
2422 viewer()->eraseAll();
2425 std::set<ObjectPtr> anObjects;
2426 foreach (ObjectPtr aObj, theList) {
2427 anObjects.insert(aObj);
2430 if (!prepareForDisplay(anObjects))
2433 // Show only objects from the list
2434 foreach (ObjectPtr aObj, theList) {
2435 aObj->setDisplayed(true);
2437 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2439 // Necessary for update icons in ObjectBrowser on Linux
2440 myObjectBrowser->updateAllIndexes();
2443 //**************************************************************
2444 void XGUI_Workshop::registerValidators() const
2446 SessionPtr aMgr = ModelAPI_Session::get();
2447 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
2450 //**************************************************************
2451 void XGUI_Workshop::displayDocumentResults(DocumentPtr theDoc)
2455 displayGroupResults(theDoc, ModelAPI_ResultConstruction::group());
2456 displayGroupResults(theDoc, ModelAPI_ResultBody::group());
2459 //**************************************************************
2460 void XGUI_Workshop::displayGroupResults(DocumentPtr theDoc, std::string theGroup)
2462 for (int i = 0; i < theDoc->size(theGroup); i++)
2463 theDoc->object(theGroup, i)->setDisplayed(true);
2464 //displayObject(theDoc->object(theGroup, i));
2465 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2468 //**************************************************************
2469 void XGUI_Workshop::setDisplayMode(const QObjectPtrList& theList, int theMode)
2471 foreach(ObjectPtr aObj, theList) {
2472 myDisplayer->setDisplayMode(aObj, (XGUI_Displayer::DisplayMode)theMode, false);
2474 ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aObj);
2475 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
2476 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
2477 myDisplayer->setDisplayMode(aCompsolidResult->subResult(i),
2478 (XGUI_Displayer::DisplayMode)theMode, false);
2482 if (theList.size() > 0)
2483 myDisplayer->updateViewer();
2486 //**************************************************************
2487 void XGUI_Workshop::closeDocument()
2489 ModuleBase_Operation* anOperation = operationMgr()->currentOperation();
2490 while (anOperation) {
2491 anOperation->abort();
2492 anOperation = operationMgr()->currentOperation();
2494 //myDisplayer->closeLocalContexts();
2495 myDisplayer->eraseAll();
2496 objectBrowser()->clearContent();
2498 module()->closeDocument();
2499 // we need to clear viewer (with created filters) to do not have problems in 2nd SALOME study
2500 module()->clearViewer();
2503 // data model need not process the document's signals about objects modifications as
2504 // the document is closed
2505 //bool isBlocked = objectBrowser()->dataModel()->blockEventsProcessing(true);
2507 SessionPtr aMgr = ModelAPI_Session::get();
2510 //objectBrowser()->dataModel()->blockEventsProcessing(isBlocked);
2513 //******************************************************
2514 void XGUI_Workshop::addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot)
2516 XGUI_HistoryMenu* aMenu = NULL;
2517 if (isSalomeMode()) {
2518 QAction* anAction = qobject_cast<QAction*>(theObject);
2521 aMenu = new XGUI_HistoryMenu(anAction);
2523 QToolButton* aButton = qobject_cast<QToolButton*>(theObject);
2524 aMenu = new XGUI_HistoryMenu(aButton);
2526 connect(this, theSignal, aMenu, SLOT(setHistory(const QList<ActionInfo>&)));
2527 connect(aMenu, SIGNAL(actionSelected(int)), this, theSlot);
2530 //******************************************************
2531 QList<ActionInfo> XGUI_Workshop::processHistoryList(const std::list<std::string>& theList) const
2533 QList<ActionInfo> aResult;
2534 std::list<std::string>::const_iterator it = theList.cbegin();
2535 for (; it != theList.cend(); it++) {
2536 QString anId = QString::fromStdString(*it);
2537 bool isEditing = anId.endsWith(ModuleBase_OperationFeature::EditSuffix());
2539 anId.chop(ModuleBase_OperationFeature::EditSuffix().size());
2542 QAction* aContextMenuAct = myContextMenuMgr->actionByName(anId);
2543 if (aContextMenuAct) {
2544 anInfo.initFrom(aContextMenuAct);
2546 anInfo = myActionsMgr->actionInfoById(anId);
2549 anInfo.text = anInfo.text.prepend("Modify ");
2556 //******************************************************
2557 void XGUI_Workshop::setStatusBarMessage(const QString& theMessage)
2560 salomeConnector()->putInfo(theMessage, -1);
2562 myMainWindow->putInfo(theMessage, -1);
2567 //******************************************************
2568 void XGUI_Workshop::synchronizeViewer()
2570 SessionPtr aMgr = ModelAPI_Session::get();
2571 QList<DocumentPtr> aDocs;
2572 aDocs.append(aMgr->activeDocument());
2573 aDocs.append(aMgr->moduleDocument());
2575 foreach(DocumentPtr aDoc, aDocs) {
2576 synchronizeGroupInViewer(aDoc, ModelAPI_ResultConstruction::group(), false);
2577 synchronizeGroupInViewer(aDoc, ModelAPI_ResultBody::group(), false);
2578 synchronizeGroupInViewer(aDoc, ModelAPI_ResultPart::group(), false);
2579 synchronizeGroupInViewer(aDoc, ModelAPI_ResultGroup::group(), false);
2583 //******************************************************
2584 void XGUI_Workshop::synchronizeGroupInViewer(const DocumentPtr& theDoc,
2585 const std::string& theGroup,
2586 bool theUpdateViewer)
2589 int aSize = theDoc->size(theGroup);
2590 for (int i = 0; i < aSize; i++) {
2591 aObj = theDoc->object(theGroup, i);
2592 if (aObj->isDisplayed()) {
2593 // Hide the presentation with an empty shape. But isDisplayed state of the object should not
2594 // be changed to the object becomes visible when the shape becomes not empty
2595 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
2596 if (aRes.get() && (!aRes->shape().get() || aRes->shape()->isNull()))
2598 myDisplayer->display(aObj, false);
2601 if (theUpdateViewer)
2602 myDisplayer->updateViewer();
2606 //******************************************************
2607 void XGUI_Workshop::highlightResults(const QObjectPtrList& theObjects)
2609 FeaturePtr aFeature;
2610 QObjectPtrList aSelList = theObjects;
2611 QObjectPtrList aNewSel;
2612 bool aHasHidden = false;
2613 foreach(ObjectPtr aObj, theObjects) {
2614 aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
2615 if (aFeature.get()) {
2616 std::list<ResultPtr> aResults;
2617 ModelAPI_Tools::allResults(aFeature, aResults);
2618 std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aIt;
2619 for(aIt = aResults.cbegin(); aIt != aResults.cend(); aIt++) {
2620 aHasHidden |= (*aIt)->isConcealed();
2621 aSelList.append(*aIt);
2622 aNewSel.append(*aIt);
2626 if (aSelList.count() > theObjects.count()) {
2627 // if something was found
2628 bool aBlocked = objectBrowser()->blockSignals(true);
2629 objectBrowser()->setObjectsSelected(aSelList);
2630 objectBrowser()->blockSignals(aBlocked);
2631 objectBrowser()->ensureVisible(aNewSel.first());
2634 QMessageBox::information(desktop(), tr("Find results"),
2635 tr("Results not found"), QMessageBox::Ok);
2638 //******************************************************
2639 void XGUI_Workshop::highlightFeature(const QObjectPtrList& theObjects)
2642 QObjectPtrList aSelList = theObjects;
2643 QObjectPtrList aNewSel;
2644 FeaturePtr aFeature;
2645 foreach(ObjectPtr aObj, theObjects) {
2646 aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
2647 if (aResult.get()) {
2648 aFeature = ModelAPI_Feature::feature(aResult);
2649 if (aFeature.get()) {
2650 aSelList.append(aFeature);
2651 aNewSel.append(aFeature);
2655 if (aSelList.count() > theObjects.count()) {
2656 // if something was found
2657 bool aBlocked = objectBrowser()->blockSignals(true);
2658 objectBrowser()->setObjectsSelected(aSelList);
2659 objectBrowser()->blockSignals(aBlocked);
2660 objectBrowser()->ensureVisible(aNewSel.first());
2664 void XGUI_Workshop::insertFeatureFolder()
2666 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
2667 if (aObjects.isEmpty())
2669 ObjectPtr aObj = aObjects.first();
2670 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
2671 if (aFeature.get() == NULL)
2673 SessionPtr aMgr = ModelAPI_Session::get();
2674 DocumentPtr aDoc = aMgr->activeDocument();
2676 QString aDescription = contextMenuMgr()->action("INSERT_FOLDER_CMD")->text();
2678 aMgr->startOperation(aDescription.toStdString());
2679 aDoc->addFolder(aFeature);
2680 aMgr->finishOperation();
2682 updateCommandStatus();
2686 void XGUI_Workshop::insertToFolder(bool isBefore)
2688 std::list<FeaturePtr> aFeatures = mySelector->getSelectedFeatures();
2689 if (aFeatures.empty())
2692 SessionPtr aMgr = ModelAPI_Session::get();
2693 DocumentPtr aDoc = aMgr->activeDocument();
2695 FolderPtr aFolder = isBefore? aDoc->findFolderAbove(aFeatures):
2696 aDoc->findFolderBelow(aFeatures);
2700 QString aDescription = contextMenuMgr()->action(
2701 isBefore ? "ADD_TO_FOLDER_BEFORE_CMD" : "ADD_TO_FOLDER_AFTER_CMD")->text();
2703 QMap<ObjectPtr, bool> aStates = myObjectBrowser->getFoldersState(aDoc);
2705 aMgr->startOperation(aDescription.toStdString());
2706 aDoc->moveToFolder(aFeatures, aFolder);
2707 aMgr->finishOperation();
2709 myObjectBrowser->setFoldersState(aStates);
2711 updateCommandStatus();
2714 void XGUI_Workshop::moveOutFolder(bool isBefore)
2716 std::list<FeaturePtr> aFeatures = mySelector->getSelectedFeatures();
2717 if (aFeatures.empty())
2720 SessionPtr aMgr = ModelAPI_Session::get();
2721 DocumentPtr aDoc = aMgr->activeDocument();
2723 QString aDescription = contextMenuMgr()->action(
2724 isBefore ? "ADD_OUT_FOLDER_BEFORE_CMD" : "ADD_OUT_FOLDER_AFTER_CMD")->text();
2726 QMap<ObjectPtr, bool> aStates = myObjectBrowser->getFoldersState(aDoc);
2728 aMgr->startOperation(aDescription.toStdString());
2729 aDoc->removeFromFolder(aFeatures, isBefore);
2730 aMgr->finishOperation();
2732 myObjectBrowser->setFoldersState(aStates);
2734 updateCommandStatus();