1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 //#include "XGUI_Constants.h"
4 #include "XGUI_Workshop.h"
6 #include "XGUI_ActionsMgr.h"
7 #include "XGUI_MenuMgr.h"
8 #include "XGUI_ColorDialog.h"
9 #include "XGUI_DeflectionDialog.h"
10 #include "XGUI_ContextMenuMgr.h"
11 #include "XGUI_Displayer.h"
12 #include "XGUI_ErrorDialog.h"
13 #include "XGUI_ErrorMgr.h"
14 #include "XGUI_ModuleConnector.h"
15 #include "XGUI_ObjectsBrowser.h"
16 #include "XGUI_OperationMgr.h"
17 #include "XGUI_PropertyPanel.h"
18 #include "XGUI_SalomeConnector.h"
19 #include "XGUI_Selection.h"
20 #include "XGUI_SelectionMgr.h"
21 #include "XGUI_Tools.h"
22 #include "XGUI_ViewerProxy.h"
23 #include "XGUI_WorkshopListener.h"
24 #include <XGUI_CustomPrs.h>
25 #include <XGUI_HistoryMenu.h>
26 #include <XGUI_QtEvents.h>
27 #include <XGUI_DataModel.h>
30 #include <AppElements_Button.h>
31 #include <AppElements_Command.h>
32 #include <AppElements_MainMenu.h>
33 #include <AppElements_MainWindow.h>
34 #include <AppElements_MenuGroupPanel.h>
35 #include <AppElements_Viewer.h>
36 #include <AppElements_Workbench.h>
39 #include <ModelAPI_AttributeDocRef.h>
40 #include <ModelAPI_AttributeIntArray.h>
41 #include <ModelAPI_AttributeDouble.h>
42 #include <ModelAPI_Data.h>
43 #include <ModelAPI_Events.h>
44 #include <ModelAPI_Feature.h>
45 #include <ModelAPI_Object.h>
46 #include <ModelAPI_ResultBody.h>
47 #include <ModelAPI_ResultConstruction.h>
48 #include <ModelAPI_ResultGroup.h>
49 #include <ModelAPI_ResultParameter.h>
50 #include <ModelAPI_Session.h>
51 #include <ModelAPI_Validator.h>
52 #include <ModelAPI_ResultCompSolid.h>
53 #include <ModelAPI_Tools.h>
55 //#include <PartSetPlugin_Part.h>
57 #include <Events_Loop.h>
58 #include <Events_InfoMessage.h>
59 #include <Events_LongOp.h>
61 #include <ModuleBase_FilterFactory.h>
62 #include <ModuleBase_IModule.h>
63 #include <ModuleBase_IViewer.h>
64 #include <ModuleBase_Operation.h>
65 #include <ModuleBase_OperationDescription.h>
66 #include <ModuleBase_PageBase.h>
67 #include <ModuleBase_Preferences.h>
68 #include <ModuleBase_SelectionValidator.h>
69 #include <ModuleBase_Tools.h>
70 #include <ModuleBase_WidgetFactory.h>
71 #include <ModuleBase_OperationFeature.h>
72 #include <ModuleBase_OperationAction.h>
73 #include <ModuleBase_PagedContainer.h>
74 #include <ModuleBase_WidgetValidated.h>
75 #include <ModuleBase_ModelWidget.h>
76 #include <ModuleBase_ResultPrs.h>
78 #include <Config_Common.h>
79 #include <Config_FeatureMessage.h>
80 #include <Config_ModuleReader.h>
81 #include <Config_PointerMessage.h>
82 #include <Config_PropManager.h>
83 #include <Config_SelectionFilterMessage.h>
84 #include <Config_DataModelReader.h>
85 #include <Config_Translator.h>
87 #include <SUIT_ResourceMgr.h>
89 #include <AIS_Trihedron.hxx>
90 #include <AIS_Point.hxx>
91 #include <AIS_Axis.hxx>
93 #include <QApplication>
94 #include <QFileDialog>
95 #include <QMessageBox>
96 #include <QMdiSubWindow>
97 #include <QMainWindow>
98 #include <QPushButton>
99 #include <QDockWidget>
104 #include <QToolButton>
106 #include <QDesktopWidget>
111 #include <CDF_Session.hxx>
112 #include <CDF_Application.hxx>
113 #include <DFBrowserAPI_Communicator.hxx>
114 static bool DFBrowser_FirstCall = true;
128 QString XGUI_Workshop::MOVE_TO_END_COMMAND = QObject::tr("Move to the end");
130 //#define DEBUG_DELETE
131 //#define DEBUG_FEATURE_NAME
132 //#define DEBUG_CLEAN_HISTORY
134 XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
136 myCurrentDir(QString()),
138 mySalomeConnector(theConnector),
142 //myViewerSelMode(TopAbs_FACE)
144 mySelector = new XGUI_SelectionMgr(this);
145 myModuleConnector = new XGUI_ModuleConnector(this);
146 myOperationMgr = new XGUI_OperationMgr(this, 0);
147 ModuleBase_IWorkshop* aWorkshop = moduleConnector();
148 // Has to be defined first in order to get errors and messages from other components
149 myEventsListener = new XGUI_WorkshopListener(aWorkshop);
151 SUIT_ResourceMgr* aResMgr = ModuleBase_Preferences::resourceMgr();
153 myMainWindow = new AppElements_MainWindow();
155 bool aCloc = aResMgr->booleanValue("language", "locale", true);
157 QLocale::setDefault( QLocale::c() );
159 QLocale::setDefault( QLocale::system() );
161 QString aPath = Config_XMLReader::pluginConfigFile().c_str();
166 aLangs << "*_en.ts"; // load by default eng translations
167 QString aCurrLang = aResMgr->stringValue("language", "language", "en");
168 if(aCurrLang != "en") {
169 aLangs << "*_" + aCurrLang + ".ts"; // then replace with translated files
172 foreach(QString aLang, aLangs) {
173 QStringList aFilters;
175 QStringList aTsFiles = aDir.entryList(aFilters, QDir::Files);
176 foreach(QString aFileName, aTsFiles) {
177 Config_Translator::load(aFileName.toStdString());
181 myDataModelXMLReader = new Config_DataModelReader();
182 //myDataModelXMLReader->readAll();
184 myDisplayer = new XGUI_Displayer(this);
186 connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(updateCommandStatus()));
188 myActionsMgr = new XGUI_ActionsMgr(this);
189 myMenuMgr = new XGUI_MenuMgr(this);
190 myErrorDlg = new XGUI_ErrorDialog(QApplication::desktop());
191 myContextMenuMgr = new XGUI_ContextMenuMgr(this);
192 connect(myContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), this,
193 SLOT(onContextMenuCommand(const QString&, bool)));
195 myViewerProxy = new XGUI_ViewerProxy(this);
196 //connect(myViewerProxy, SIGNAL(selectionChanged()),
197 // myActionsMgr, SLOT(updateOnViewSelection()));
199 myOperationMgr->setWorkshop(aWorkshop);
201 myErrorMgr = new XGUI_ErrorMgr(this, aWorkshop);
203 connect(myOperationMgr, SIGNAL(operationResumed(ModuleBase_Operation*)),
204 SLOT(onOperationResumed(ModuleBase_Operation*)));
205 connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
206 SLOT(onOperationStopped(ModuleBase_Operation*)));
207 connect(myOperationMgr, SIGNAL(operationCommitted(ModuleBase_Operation*)),
208 SLOT(onOperationCommitted(ModuleBase_Operation*)));
209 connect(myOperationMgr, SIGNAL(operationAborted(ModuleBase_Operation*)),
210 SLOT(onOperationAborted(ModuleBase_Operation*)));
213 connect(myMainWindow, SIGNAL(exitKeySequence()), SLOT(onExit()));
214 onTrihedronVisibilityChanged(true);
217 connect(myEventsListener, SIGNAL(errorOccurred(std::shared_ptr<Events_InfoMessage>)),
218 myErrorDlg, SLOT(addError(std::shared_ptr<Events_InfoMessage>)));
220 //Config_PropManager::registerProp("Visualization", "object_default_color", "Object color",
221 // Config_Prop::Color, "225,225,225");
223 Config_PropManager::registerProp("Visualization", "result_body_color", "Result color",
224 Config_Prop::Color, ModelAPI_ResultBody::DEFAULT_COLOR());
225 Config_PropManager::registerProp("Visualization", "result_group_color", "Group color",
226 Config_Prop::Color, ModelAPI_ResultGroup::DEFAULT_COLOR());
227 Config_PropManager::registerProp("Visualization", "result_construction_color",
228 "Construction color",
230 ModelAPI_ResultConstruction::DEFAULT_COLOR());
231 Config_PropManager::registerProp("Visualization", "result_part_color", "Part color",
232 Config_Prop::Color, ModelAPI_ResultPart::DEFAULT_COLOR());
234 Config_PropManager::registerProp("Visualization", "body_deflection",
235 "Body deflection coefficient",
237 ModelAPI_ResultBody::DEFAULT_DEFLECTION());
239 Config_PropManager::registerProp("Visualization", "construction_deflection",
240 "Construction deflection coefficient",
242 ModelAPI_ResultConstruction::DEFAULT_DEFLECTION());
244 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "face-selection", true))
245 myViewerSelMode.append(TopAbs_FACE);
246 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "edge-selection", true))
247 myViewerSelMode.append(TopAbs_EDGE);
248 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "vertex-selection", true))
249 myViewerSelMode.append(TopAbs_VERTEX);
250 //IMP: an attempt to use result selection with other selection modes
251 myViewerSelMode.append(ModuleBase_ResultPrs::Sel_Result);//TopAbs_VERTEX);
252 myViewerSelMode.append(TopAbs_COMPSOLID);
255 //******************************************************
256 XGUI_Workshop::~XGUI_Workshop(void)
259 #ifdef MISSED_TRANSLATION
260 // Save Missed translations
261 Config_Translator::saveMissedTranslations();
266 delete myDataModelXMLReader;
269 //******************************************************
270 void XGUI_Workshop::startApplication()
272 //Initialize event listening
273 myEventsListener->initializeEventListening();
275 myDataModelXMLReader->readAll();
278 Config_PropManager::registerProp("Plugins", "default_path", "Default Path",
279 Config_Prop::Directory, "");
282 registerValidators();
284 // Calling of loadCustomProps before activating module is required
285 // by Config_PropManger to restore user-defined path to plugins
286 ModuleBase_Preferences::loadCustomProps();
290 myMainWindow->show();
291 updateCommandStatus();
296 myViewerProxy->connectViewProxy();
297 connect(myViewerProxy, SIGNAL(trihedronVisibilityChanged(bool)),
298 SLOT(onTrihedronVisibilityChanged(bool)));
300 emit applicationStarted();
303 void XGUI_Workshop::activateModule()
305 myModule->activateSelectionFilters();
307 connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
308 myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
309 connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
310 myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
312 updateCommandStatus();
314 // TODO: get default selection mode
316 // activate visualized objects in the viewer
317 activateObjectsSelection(displayer()->displayedObjects());
318 myOperationMgr->activate();
321 void XGUI_Workshop::deactivateModule()
323 myModule->deactivateSelectionFilters();
325 // remove internal displayer filter
326 displayer()->deactivateSelectionFilters();
328 disconnect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
329 myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
330 disconnect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
331 myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
333 XGUI_Displayer* aDisplayer = displayer();
334 QObjectPtrList aDisplayed = aDisplayer->displayedObjects();
335 aDisplayer->deactivateObjects(aDisplayed, true);
336 Handle(AIS_InteractiveContext) aContext = viewer()->AISContext();
337 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(aDisplayer->getTrihedron());
338 /// deactivate trihedron in selection modes
339 TColStd_ListOfInteger aTColModes;
340 aContext->ActivatedModes(aTrihedron, aTColModes);
341 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
342 for (; itr.More(); itr.Next() ) {
343 Standard_Integer aMode = itr.Value();
344 aContext->Deactivate(aTrihedron, aMode);
346 /// Trihedron problem: objects stayed in the viewer, should be removed manually
347 /// otherwise in SALOME happens crash by HideAll in the viewer
348 aContext->Remove(aTrihedron->Position(), true);
349 aContext->Remove(aTrihedron->Axis(), true);
350 aContext->Remove(aTrihedron->XAxis(), true);
351 aContext->Remove(aTrihedron->YAxis(), true);
354 myOperationMgr->deactivate();
357 //******************************************************
358 void XGUI_Workshop::initMenu()
360 myContextMenuMgr->createActions();
363 // Create only Undo, Redo commands
364 QAction* aAction = salomeConnector()->addDesktopCommand("UNDO_CMD", tr("Undo"),
365 tr("Undo last command"),
366 QIcon(":pictures/undo.png"),
367 QKeySequence::Undo, false,
369 QString aToolBarTitle = tr( "INF_DESK_TOOLBAR_STANDARD" );
370 salomeConnector()->addActionInToolbar( aAction,aToolBarTitle );
372 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onUndo()));
373 addHistoryMenu(aAction, SIGNAL(updateUndoHistory(const QList<ActionInfo>&)), SLOT(onUndo(int)));
375 aAction = salomeConnector()->addDesktopCommand("REDO_CMD", tr("Redo"), tr("Redo last command"),
376 QIcon(":pictures/redo.png"), QKeySequence::Redo,
377 false, "MEN_DESK_EDIT");
378 salomeConnector()->addActionInToolbar( aAction, aToolBarTitle );
380 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo()));
381 addHistoryMenu(aAction, SIGNAL(updateRedoHistory(const QList<ActionInfo>&)), SLOT(onRedo(int)));
383 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
384 //aAction = salomeConnector()->addDesktopCommand("REBUILD_CMD", tr("Rebuild"),
385 // tr("Rebuild data objects"),
386 // QIcon(":pictures/rebuild.png"), QKeySequence(),
387 // false, "MEN_DESK_EDIT");
388 //salomeConnector()->addActionInToolbar( aAction, aToolBarTitle );
390 //connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRebuild()));
391 //salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
393 aAction = salomeConnector()->addDesktopCommand("SAVEAS_CMD", tr("Export native..."),
394 tr("Export the current document into a native file"),
395 QIcon(), QKeySequence(),
396 false, "MEN_DESK_FILE");
397 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onSaveAs()));
399 aAction = salomeConnector()->addDesktopCommand("OPEN_CMD", tr("Import native..."),
400 tr("Import native file"),
401 QIcon(), QKeySequence(),
402 false, "MEN_DESK_FILE");
403 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onOpen()));
404 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_FILE");
407 // File commands group
408 AppElements_MenuGroupPanel* aGroup = myMainWindow->menuObject()->generalPage();
410 AppElements_Command* aCommand;
412 aCommand = aGroup->addFeature("SAVE_CMD", tr("Save"), tr("Save the document"),
413 QIcon(":pictures/save.png"), QKeySequence::Save);
414 aCommand->connectTo(this, SLOT(onSave()));
415 //aCommand->disable();
417 aCommand = aGroup->addFeature("SAVEAS_CMD", tr("Save as..."), tr("Save the document into a file"),
418 QIcon(":pictures/save.png"), QKeySequence());
419 aCommand->connectTo(this, SLOT(onSaveAs()));
421 QString aUndoId = "UNDO_CMD";
422 aCommand = aGroup->addFeature(aUndoId, tr("Undo"), tr("Undo last command"),
423 QIcon(":pictures/undo.png"), QKeySequence::Undo);
424 aCommand->connectTo(this, SLOT(onUndo()));
425 AppElements_Button* aUndoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aUndoId));
426 addHistoryMenu(aUndoButton,
427 SIGNAL(updateUndoHistory(const QList<ActionInfo>&)),
430 QString aRedoId = "REDO_CMD";
431 aCommand = aGroup->addFeature(aRedoId, tr("Redo"), tr("Redo last command"),
432 QIcon(":pictures/redo.png"), QKeySequence::Redo);
433 aCommand->connectTo(this, SLOT(onRedo()));
434 AppElements_Button* aRedoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aRedoId));
435 addHistoryMenu(aRedoButton,
436 SIGNAL(updateRedoHistory(const QList<ActionInfo>&)),
439 //aCommand = aGroup->addFeature("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
440 // QIcon(":pictures/rebuild.png"), QKeySequence());
441 //aCommand->connectTo(this, SLOT(onRebuild()));
443 //aCommand->disable();
445 aCommand = aGroup->addFeature("OPEN_CMD", tr("Open..."), tr("Open a new document"),
446 QIcon(":pictures/open.png"), QKeySequence::Open);
447 aCommand->connectTo(this, SLOT(onOpen()));
449 aCommand = aGroup->addFeature("PREF_CMD", tr("Preferences"), tr("Edit preferences"),
450 QIcon(":pictures/preferences.png"), QKeySequence::Preferences);
451 aCommand->connectTo(this, SLOT(onPreferences()));
453 aCommand = aGroup->addFeature("EXIT_CMD", tr("Exit"), tr("Exit application"),
454 QIcon(":pictures/close.png"), QKeySequence::Close);
455 aCommand->connectTo(this, SLOT(onExit()));
460 AppElements_Workbench* XGUI_Workshop::addWorkbench(const QString& theName)
462 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
463 return aMenuBar->addWorkbench(theName);
467 //******************************************************
468 QMainWindow* XGUI_Workshop::desktop() const
471 return salomeConnector()->desktop();
477 //******************************************************
478 void XGUI_Workshop::onStartWaiting()
480 if (Events_LongOp::isPerformed()) {
481 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
485 //******************************************************
486 void XGUI_Workshop::onAcceptActionClicked()
488 QAction* anAction = dynamic_cast<QAction*>(sender());
489 XGUI_OperationMgr* anOperationMgr = operationMgr();
490 if (anOperationMgr) {
491 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
492 (anOperationMgr->currentOperation());
494 //if (errorMgr()->canProcessClick(anAction, aFOperation->feature()))
495 myOperationMgr->onCommitOperation();
500 //******************************************************
501 void XGUI_Workshop::onPreviewActionClicked()
503 ModuleBase_IPropertyPanel* aPanel = propertyPanel();
505 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
506 if (anActiveWidget && anActiveWidget->getValueState() == ModuleBase_ModelWidget::ModifiedInPP) {
507 anActiveWidget->storeValue();
510 std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
511 new Events_Message(Events_Loop::eventByName(EVENT_PREVIEW_REQUESTED)));
512 Events_Loop::loop()->send(aMsg);
515 //******************************************************
516 void XGUI_Workshop::deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer)
518 if (!myModule->canActivateSelection(theObject)) {
519 if (myDisplayer->isActive(theObject)) {
520 QObjectPtrList anObjects;
521 anObjects.append(theObject);
522 myDisplayer->deactivateObjects(anObjects, theUpdateViewer);
527 //******************************************************
528 bool XGUI_Workshop::isFeatureOfNested(const FeaturePtr& theFeature)
530 bool aHasNested = false;
531 std::string aFeatureKind = theFeature->getKind();
533 XGUI_SalomeConnector* aSalomeConnector = salomeConnector();
534 if (aSalomeConnector->isFeatureOfNested(actionsMgr()->action(aFeatureKind.c_str())))
537 AppElements_MainMenu* aMenuBar = mainWindow()->menuObject();
538 AppElements_Command* aCommand = aMenuBar->feature(aFeatureKind.c_str());
539 if (aCommand && aCommand->button()->additionalButtonWidget())
545 void XGUI_Workshop::fillPropertyPanel(ModuleBase_Operation* theOperation)
547 ModuleBase_OperationFeature* aFOperation =
548 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
553 myPropertyPanel->cleanContent();
555 QList<ModuleBase_ModelWidget*> aWidgets;
556 if (!module()->createWidgets(theOperation, aWidgets)) {
557 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
558 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), myModuleConnector);
559 aFactory.createWidget(myPropertyPanel->contentWidget());
560 aWidgets = aFactory.getModelWidgets();
563 // check compatibility of feature and widgets
564 FeaturePtr aFeature = aFOperation->feature();
565 std::string aFeatureKind = aFeature->getKind();
566 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
567 if (!aWidget->attributeID().empty() && !aFeature->attribute(aWidget->attributeID()).get()) {
568 std::string anErrorMsg = "The feature '%1' has no attribute '%2' used by widget '%3'.";
569 Events_InfoMessage("XGUI_Workshop", anErrorMsg)
570 .arg(aFeatureKind).arg(aWidget->attributeID())
571 .arg(aWidget->metaObject()->className()).send();
572 myPropertyPanel->cleanContent();
576 // for performance purpose, flush should be done after all controls are filled
577 bool isUpdateFlushed = false;
578 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
579 bool isStoreValue = !aFOperation->isEditOperation() &&
580 !aWidget->getDefaultValue().empty() &&
581 !aWidget->isComputedDefault();
582 aWidget->setFeature(aFeature, isStoreValue, isUpdateFlushed);
584 aWidget->restoreValue();
585 aWidget->enableFocusProcessing();
587 ModuleBase_Tools::flushUpdated(aFeature);
589 // update visible state of Preview button
591 bool anIsAutoPreview =
592 mySalomeConnector->featureInfo(aFeatureKind.c_str())->isAutoPreview();
594 AppElements_MainMenu* aMenuBar = mainWindow()->menuObject();
595 AppElements_Command* aCommand = aMenuBar->feature(aFeatureKind.c_str());
596 bool anIsAutoPreview = aCommand && aCommand->featureMessage()->isAutoPreview();
598 if (!anIsAutoPreview) {
599 myPropertyPanel->findButton(PROP_PANEL_PREVIEW)->setVisible(true);
600 // send signal about preview should not be computed automatically, click on preview
601 // button should initiate it
602 std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
603 new Events_Message(Events_Loop::eventByName(EVENT_PREVIEW_BLOCKED)));
604 Events_Loop::loop()->send(aMsg);
606 myPropertyPanel->setModelWidgets(aWidgets);
607 aFOperation->setPropertyPanel(myPropertyPanel);
609 myModule->propertyPanelDefined(theOperation);
611 #ifndef DEBUG_FEATURE_NAME
612 myPropertyPanel->setWindowTitle(theOperation->getDescription()->description());
614 std::string aFeatureName = aFeature->name();
615 myPropertyPanel->setWindowTitle(QString("%1: %2")
616 .arg(theOperation->getDescription()->description())
617 .arg(aFeatureName.c_str()));
620 myErrorMgr->setPropertyPanel(myPropertyPanel);
623 void XGUI_Workshop::connectToPropertyPanel(const bool isToConnect)
625 XGUI_PropertyPanel* aPropertyPanel = propertyPanel();
626 if (aPropertyPanel) {
627 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
628 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
629 myModule->connectToPropertyPanel(aWidget, isToConnect);
631 connect(aWidget, SIGNAL(valueStateChanged(int)), this, SLOT(onWidgetStateChanged(int)));
632 connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
633 connect(aWidget, SIGNAL(objectUpdated()), this, SLOT(onWidgetObjectUpdated()));
636 disconnect(aWidget, SIGNAL(valueStateChanged(int)), this, SLOT(onWidgetStateChanged(int)));
637 disconnect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
638 disconnect(aWidget, SIGNAL(objectUpdated()), this, SLOT(onWidgetObjectUpdated()));
644 //******************************************************
645 void XGUI_Workshop::onOperationResumed(ModuleBase_Operation* theOperation)
647 setGrantedFeatures(theOperation);
649 if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
650 fillPropertyPanel(theOperation);
651 connectToPropertyPanel(true);
653 updateCommandStatus();
655 myModule->operationResumed(theOperation);
659 //******************************************************
660 void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
662 updateCommandStatus();
664 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
669 ModuleBase_ISelection* aSel = mySelector->selection();
670 QObjectPtrList aObj = aSel->selectedPresentations();
671 //!< No need for property panel
673 myPropertyPanel->cleanContent();
675 connectToPropertyPanel(false);
676 myModule->operationStopped(aFOperation);
678 // the deactivated objects of the current operation should be activated back.
679 // They were deactivated on operation start or an object redisplay
680 QObjectPtrList anObjects;
681 FeaturePtr aFeature = aFOperation->feature();
682 if (aFeature.get()) { // feature may be not created (plugin load fail)
683 if (myDisplayer->isVisible(aFeature) && !myDisplayer->isActive(aFeature))
684 anObjects.append(aFeature);
685 std::list<ResultPtr> aResults;
686 ModelAPI_Tools::allResults(aFeature, aResults);
687 std::list<ResultPtr>::const_iterator aIt;
688 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
689 ResultPtr anObject = *aIt;
690 if (myDisplayer->isVisible(anObject) && !myDisplayer->isActive(anObject)) {
691 anObjects.append(anObject);
695 activateObjectsSelection(anObjects);
699 void XGUI_Workshop::onOperationCommitted(ModuleBase_Operation* theOperation)
701 myModule->operationCommitted(theOperation);
704 void XGUI_Workshop::onOperationAborted(ModuleBase_Operation* theOperation)
706 myModule->operationAborted(theOperation);
709 void XGUI_Workshop::setGrantedFeatures(ModuleBase_Operation* theOperation)
711 ModuleBase_OperationFeature* aFOperation =
712 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
716 QStringList aGrantedIds;
717 if (isSalomeMode()) {
718 const std::shared_ptr<Config_FeatureMessage>& anInfo =
719 mySalomeConnector->featureInfo(theOperation->id());
721 aGrantedIds = QString::fromStdString(anInfo->nestedFeatures())
722 .split(" ", QString::SkipEmptyParts);
725 aGrantedIds = myActionsMgr->nestedCommands(theOperation->id());
727 ModuleBase_IModule* aModule = module();
729 aModule->grantedOperationIds(theOperation, aGrantedIds);
731 aFOperation->setGrantedOperationIds(aGrantedIds);
734 //******************************************************
735 void XGUI_Workshop::saveDocument(const QString& theName, std::list<std::string>& theFileNames)
737 QApplication::restoreOverrideCursor();
738 SessionPtr aMgr = ModelAPI_Session::get();
740 std::list<DocumentPtr> aDocList = aMgr->allOpenedDocuments();
741 std::list<DocumentPtr>::const_iterator aIt;
742 for (aIt = aDocList.cbegin(); aIt != aDocList.cend(); aIt++) {
743 std::list<bool> aState = myObjectBrowser->getStateForDoc(*aIt);
744 (*aIt)->storeNodesState(aState);
747 aMgr->save(theName.toLatin1().constData(), theFileNames);
749 QApplication::restoreOverrideCursor();
752 //******************************************************
753 bool XGUI_Workshop::abortAllOperations()
755 return myOperationMgr->abortAllOperations();
758 //******************************************************
759 void XGUI_Workshop::operationStarted(ModuleBase_Operation* theOperation)
761 setGrantedFeatures(theOperation);
762 if (!theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
763 updateCommandStatus();
766 myModule->operationStarted(theOperation);
770 //******************************************************
771 void XGUI_Workshop::onOpen()
773 if(!abortAllOperations())
775 //save current file before close if modified
776 SessionPtr aSession = ModelAPI_Session::get();
777 if (aSession->isModified()) {
778 //TODO(sbh): re-launch the app?
779 int anAnswer = QMessageBox::question(
780 desktop(), tr("Save current file"),
781 tr("The document is modified, save before opening another?"),
782 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
783 if (anAnswer == QMessageBox::Save) {
785 } else if (anAnswer == QMessageBox::Cancel) {
791 //show file dialog, check if readable and open
792 QString aDirectory = QFileDialog::getExistingDirectory(desktop(), tr("Select directory"));
793 openDirectory(aDirectory);
796 //******************************************************
797 void XGUI_Workshop::openDirectory(const QString& theDirectory)
799 myCurrentDir = theDirectory;
800 if (myCurrentDir.isEmpty())
803 QFileInfo aFileInfo(myCurrentDir);
804 if (!aFileInfo.exists() || !aFileInfo.isReadable()) {
805 QMessageBox::critical(desktop(), tr("Warning"), tr("Unable to open the file."));
810 QApplication::setOverrideCursor(Qt::WaitCursor);
811 module()->closeDocument();
812 SessionPtr aSession = ModelAPI_Session::get();
813 aSession->closeAll();
814 aSession->load(myCurrentDir.toLatin1().constData());
815 myObjectBrowser->rebuildDataTree();
817 // Open first level of data tree
818 DocumentPtr aRootDoc = aSession->moduleDocument();
819 std::list<bool> aStates;
820 aRootDoc->restoreNodesState(aStates);
821 myObjectBrowser->setStateForDoc(aRootDoc, aStates);
823 updateCommandStatus();
825 myMainWindow->setCurrentDir(myCurrentDir, true);
827 QApplication::restoreOverrideCursor();
830 //******************************************************
831 void XGUI_Workshop::onNew()
833 QApplication::setOverrideCursor(Qt::WaitCursor);
834 if (objectBrowser() == 0) {
836 mySelector->connectViewers();
838 myViewerProxy->connectToViewer();
841 myMainWindow->showPythonConsole();
842 QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
843 aWnd->showMaximized();
844 updateCommandStatus();
846 myContextMenuMgr->connectViewer();
847 QApplication::restoreOverrideCursor();
851 //******************************************************
852 void XGUI_Workshop::onExit()
854 SessionPtr aMgr = ModelAPI_Session::get();
855 if (aMgr->isModified()) {
856 int anAnswer = QMessageBox::question(
857 myMainWindow, tr("Save current file"), tr("The document is modified, save before exit?"),
858 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
859 if (anAnswer == QMessageBox::Save) {
860 bool saved = onSave();
864 } else if (anAnswer == QMessageBox::Cancel) {
871 //******************************************************
872 void XGUI_Workshop::onPreferences()
874 ModuleBase_Prefs aModif;
875 ModuleBase_Preferences::editPreferences(aModif);
876 if (aModif.size() > 0) {
878 foreach (ModuleBase_Pref aPref, aModif)
880 aSection = aPref.first;
881 if (aSection == ModuleBase_Preferences::VIEWER_SECTION) {
882 myMainWindow->viewer()->updateFromResources();
883 } else if (aSection == ModuleBase_Preferences::MENU_SECTION) {
884 myMainWindow->menuObject()->updateFromResources();
887 displayer()->redisplayObjects();
892 //******************************************************
893 void XGUI_Workshop::onTrihedronVisibilityChanged(bool theState)
895 XGUI_Displayer* aDisplayer = displayer();
897 aDisplayer->displayTrihedron(theState);
900 //******************************************************
901 bool XGUI_Workshop::onSave()
903 if(!abortAllOperations())
905 if (myCurrentDir.isEmpty()) {
908 std::list<std::string> aFiles;
909 saveDocument(myCurrentDir, aFiles);
910 updateCommandStatus();
912 myMainWindow->setModifiedState(false);
917 //******************************************************
918 bool XGUI_Workshop::onSaveAs()
920 if(!abortAllOperations())
922 QFileDialog dialog(desktop());
923 dialog.setWindowTitle(tr("Select directory to save files..."));
924 dialog.setFileMode(QFileDialog::Directory);
925 dialog.setFilter(QDir::AllDirs);
926 dialog.setOptions(QFileDialog::HideNameFilterDetails | QFileDialog::ShowDirsOnly);
927 dialog.setViewMode(QFileDialog::Detail);
929 if (!dialog.exec()) {
933 QString aTempDir = dialog.selectedFiles().first();
935 if (aDir.exists() && !aDir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries).isEmpty()) {
936 int answer = QMessageBox::question(
938 // Title of the dialog which asks user if he wants to save study
939 // in existing non-empty folder
941 tr("The directory already contains some files, save anyway?"),
942 QMessageBox::Save | QMessageBox::Cancel);
943 if (answer == QMessageBox::Cancel) {
947 myCurrentDir = aTempDir;
949 myMainWindow->setCurrentDir(myCurrentDir, false);
950 myMainWindow->setModifiedState(false);
955 //******************************************************
956 void XGUI_Workshop::onUndo(int theTimes)
958 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
959 SessionPtr aMgr = ModelAPI_Session::get();
960 std::list<std::string> aUndoList = aMgr->undoList();
961 if (aMgr->isOperation()) {
962 /// this is important for nested operations
963 /// when sketch operation is active, this condition is false and
964 /// the sketch operation is not aborted
965 operationMgr()->onAbortOperation();
967 std::list<std::string>::const_iterator aIt = aUndoList.cbegin();
968 for (int i = 0; (i < theTimes) && (aIt != aUndoList.cend()); ++i, ++aIt) {
970 if (QString((*aIt).c_str()) == MOVE_TO_END_COMMAND)
971 myObjectBrowser->rebuildDataTree();
974 operationMgr()->updateApplyOfOperations();
975 updateCommandStatus();
978 //******************************************************
979 void XGUI_Workshop::onRedo(int theTimes)
981 // the viewer update should be blocked in order to avoid the features blinking. For the created
982 // feature a results are created, the flush of the created signal caused the viewer redisplay for
983 // each created result. After a redisplay signal is flushed. So, the viewer update is blocked
984 // until redo of all possible objects happens
985 bool isUpdateEnabled = myDisplayer->enableUpdateViewer(false);
987 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
988 SessionPtr aMgr = ModelAPI_Session::get();
989 std::list<std::string> aRedoList = aMgr->redoList();
990 if (aMgr->isOperation()) {
991 /// this is important for nested operations
992 /// when sketch operation is active, this condition is false and
993 /// the sketch operation is not aborted
994 operationMgr()->onAbortOperation();
996 std::list<std::string>::const_iterator aIt = aRedoList.cbegin();
997 for (int i = 0; (i < theTimes) && (aIt != aRedoList.cend()); ++i, ++aIt) {
999 if (QString((*aIt).c_str()) == MOVE_TO_END_COMMAND)
1000 myObjectBrowser->rebuildDataTree();
1002 operationMgr()->updateApplyOfOperations();
1003 updateCommandStatus();
1005 // unblock the viewer update functionality and make update on purpose
1006 myDisplayer->enableUpdateViewer(isUpdateEnabled);
1007 myDisplayer->updateViewer();
1010 //******************************************************
1011 //void XGUI_Workshop::onRebuild()
1013 // SessionPtr aMgr = ModelAPI_Session::get();
1014 // bool aWasOperation = aMgr->isOperation(); // keep this value
1015 // if (!aWasOperation) {
1016 // aMgr->startOperation("Rebuild");
1018 // static const Events_ID aRebuildEvent = Events_Loop::loop()->eventByName("Rebuild");
1019 // Events_Loop::loop()->send(std::shared_ptr<Events_Message>(
1020 // new Events_Message(aRebuildEvent, this)));
1021 // if (!aWasOperation) {
1022 // aMgr->finishOperation();
1024 // updateCommandStatus();
1027 //******************************************************
1028 void XGUI_Workshop::onWidgetStateChanged(int thePreviousState)
1030 ModuleBase_ModelWidget* anActiveWidget = 0;
1031 ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
1033 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1035 anActiveWidget = aPanel->activeWidget();
1038 operationMgr()->onValidateOperation();
1040 myModule->widgetStateChanged(thePreviousState);
1043 //******************************************************
1044 void XGUI_Workshop::onValuesChanged()
1046 ModuleBase_ModelWidget* aSenderWidget = (ModuleBase_ModelWidget*)(sender());
1047 if (!aSenderWidget || aSenderWidget->canAcceptFocus())
1050 ModuleBase_ModelWidget* anActiveWidget = 0;
1051 ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
1053 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1055 anActiveWidget = aPanel->activeWidget();
1057 if (anActiveWidget) {
1058 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1060 if (aWidgetValidated)
1061 aWidgetValidated->clearValidatedCash();
1065 void XGUI_Workshop::onWidgetObjectUpdated()
1067 operationMgr()->onValidateOperation();
1070 ModuleBase_IModule* XGUI_Workshop::loadModule(const QString& theModule)
1072 QString libName = QString::fromStdString(library(theModule.toStdString()));
1073 if (libName.isEmpty()) {
1074 qWarning(qPrintable(tr("Information about module \"%1\" doesn't exist.").arg(theModule)));
1079 CREATE_FUNC crtInst = 0;
1082 HINSTANCE modLib = ::LoadLibrary((LPTSTR) qPrintable(libName));
1086 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
1087 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
1088 QString aMsg((char*) &lpMsgBuf);
1089 err = QString("Failed to load %1. %2").arg(libName).arg(aMsg);
1090 ::LocalFree(lpMsgBuf);
1092 crtInst = (CREATE_FUNC) ::GetProcAddress(modLib, CREATE_MODULE);
1096 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
1097 | FORMAT_MESSAGE_IGNORE_INSERTS,
1098 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
1099 QString aMsg((char*) &lpMsgBuf);
1100 err = QString("Failed to find %1 function. %2").arg( CREATE_MODULE).arg(aMsg);
1101 ::LocalFree(lpMsgBuf);
1105 void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY | RTLD_GLOBAL );
1107 err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
1109 crtInst = (CREATE_FUNC)dlsym( modLib, CREATE_MODULE );
1111 err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() );
1116 ModuleBase_IModule* aModule = crtInst ? crtInst(myModuleConnector) : 0;
1118 if (!err.isEmpty()) {
1120 Events_InfoMessage("XGUI_Workshop", err.toStdString()).send();
1122 qWarning(qPrintable(err));
1128 //******************************************************
1129 bool XGUI_Workshop::createModule()
1131 Config_ModuleReader aModuleReader;
1132 QString moduleName = QString::fromStdString(aModuleReader.getModuleName());
1133 myModule = loadModule(moduleName);
1137 //connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
1138 // myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
1139 //connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
1140 // myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
1142 myModule->createFeatures();
1144 salomeConnector()->createFeatureActions();
1146 //myActionsMgr->update();
1150 //******************************************************
1151 void XGUI_Workshop::updateCommandStatus()
1153 QList<QAction*> aCommands;
1155 aCommands = salomeConnector()->commandList();
1157 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
1158 foreach (AppElements_Command* aCmd, aMenuBar->features())
1159 aCommands.append(aCmd);
1161 SessionPtr aMgr = ModelAPI_Session::get();
1162 if (aMgr->hasModuleDocument()) {
1163 foreach(QAction* aCmd, aCommands) {
1164 QString aId = aCmd->data().toString();
1165 if (aId == "UNDO_CMD")
1166 aCmd->setEnabled(myModule->canUndo());
1167 else if (aId == "REDO_CMD")
1168 aCmd->setEnabled(myModule->canRedo());
1170 // Enable all commands
1171 aCmd->setEnabled(true);
1175 foreach(QAction* aCmd, aCommands) {
1176 QString aId = aCmd->data().toString();
1177 if (aId == "NEW_CMD")
1178 aCmd->setEnabled(true);
1179 else if (aId == "EXIT_CMD")
1180 aCmd->setEnabled(true);
1182 aCmd->setEnabled(false);
1185 myActionsMgr->updateCommandsStatus();
1186 emit commandStatusUpdated();
1189 void XGUI_Workshop::updateHistory()
1191 std::list<std::string> aUndoList = ModelAPI_Session::get()->undoList();
1192 QList<ActionInfo> aUndoRes = processHistoryList(aUndoList);
1193 emit updateUndoHistory(aUndoRes);
1195 std::list<std::string> aRedoList = ModelAPI_Session::get()->redoList();
1196 QList<ActionInfo> aRedoRes = processHistoryList(aRedoList);
1197 emit updateRedoHistory(aRedoRes);
1200 //******************************************************
1201 QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
1203 QDockWidget* aObjDock = new QDockWidget(theParent);
1204 aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea |
1205 Qt::RightDockWidgetArea |
1206 Qt::BottomDockWidgetArea);
1207 aObjDock->setWindowTitle(tr("Object browser"));
1208 aObjDock->setStyleSheet(
1209 "::title { position: relative; padding-left: 5px; text-align: left center }");
1210 myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock);
1211 myObjectBrowser->setXMLReader(myDataModelXMLReader);
1212 myModule->customizeObjectBrowser(myObjectBrowser);
1213 aObjDock->setWidget(myObjectBrowser);
1215 myContextMenuMgr->connectObjectBrowser();
1219 //******************************************************
1221 * Creates dock widgets, places them in corresponding area
1222 * and tabifies if necessary.
1224 void XGUI_Workshop::createDockWidgets()
1226 QMainWindow* aDesktop = desktop();
1227 QDockWidget* aObjDock = createObjectBrowser(aDesktop);
1228 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
1229 myPropertyPanel = new XGUI_PropertyPanel(aDesktop, myOperationMgr);
1230 myPropertyPanel->setupActions(myActionsMgr);
1231 myPropertyPanel->setAllowedAreas(Qt::LeftDockWidgetArea |
1232 Qt::RightDockWidgetArea |
1233 Qt::BottomDockWidgetArea);
1234 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel);
1235 hidePropertyPanel(); ///<! Invisible by default
1236 hideObjectBrowser();
1237 aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
1238 myPropertyPanel->installEventFilter(myOperationMgr);
1240 QAction* aOkAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept);
1241 connect(aOkAct, SIGNAL(triggered()), this, SLOT(onAcceptActionClicked()));
1243 QAction* aCancelAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Abort);
1244 connect(aCancelAct, SIGNAL(triggered()), myOperationMgr, SLOT(onAbortOperation()));
1246 QAction* aPreviewAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Preview);
1247 connect(aPreviewAct, SIGNAL(triggered()), this, SLOT(onPreviewActionClicked()));
1249 connect(myPropertyPanel, SIGNAL(keyReleased(QObject*, QKeyEvent*)),
1250 myOperationMgr, SLOT(onKeyReleased(QObject*, QKeyEvent*)));
1251 connect(myPropertyPanel, SIGNAL(enterClicked(QObject*)),
1252 myOperationMgr, SLOT(onProcessEnter(QObject*)));
1255 //******************************************************
1256 void XGUI_Workshop::showPropertyPanel()
1258 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1259 ///<! Restore ability to close panel from the window's menu
1260 aViewAct->setEnabled(true);
1261 myPropertyPanel->show();
1262 myPropertyPanel->raise();
1264 // The next code is necessary to made the property panel the active window
1265 // in order to operation manager could process key events of the panel.
1266 // otherwise they are ignored. It happens only if the same(activateWindow) is
1267 // not happened by property panel activation(e.g. resume operation of Sketch)
1268 ModuleBase_Tools::activateWindow(myPropertyPanel, "XGUI_Workshop::showPropertyPanel()");
1269 ModuleBase_Tools::setFocus(myPropertyPanel, "XGUI_Workshop::showPropertyPanel()");
1272 //******************************************************
1273 void XGUI_Workshop::hidePropertyPanel()
1275 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1276 ///<! Do not allow to show empty property panel
1277 aViewAct->setEnabled(false);
1278 myPropertyPanel->hide();
1280 // the property panel is active window of the desktop, when it is
1281 // hidden, it is undefined which window becomes active. By this reason
1282 // it is defined to perform the desktop as the active window.
1283 // in SALOME mode, workstack made the PyConsole the active window,
1284 // set the focus on it. As a result, shortcuts of the application, like
1285 // are processed by this console. For example Undo actions.
1286 // It is possible that this code is to be moved to SHAPER package
1287 QMainWindow* aDesktop = desktop();
1288 ModuleBase_Tools::activateWindow(aDesktop, "XGUI_Workshop::hidePropertyPanel()");
1289 ModuleBase_Tools::setFocus(aDesktop, "XGUI_Workshop::showPropertyPanel()");
1292 //******************************************************
1293 void XGUI_Workshop::showObjectBrowser()
1295 if (!isSalomeMode())
1296 myObjectBrowser->parentWidget()->show();
1299 //******************************************************
1300 void XGUI_Workshop::hideObjectBrowser()
1302 if (!isSalomeMode())
1303 myObjectBrowser->parentWidget()->hide();
1306 //******************************************************
1307 void XGUI_Workshop::salomeViewerSelectionChanged()
1309 emit salomeViewerSelection();
1312 //**************************************************************
1313 ModuleBase_IViewer* XGUI_Workshop::salomeViewer() const
1315 return mySalomeConnector->viewer();
1318 //**************************************************************
1319 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
1321 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1322 if (theId == "DELETE_CMD")
1324 else if (theId == "CLEAN_HISTORY_CMD")
1326 else if (theId == "MOVE_CMD")
1328 else if (theId == "COLOR_CMD")
1329 changeColor(aObjects);
1330 else if (theId == "DEFLECTION_CMD")
1331 changeDeflection(aObjects);
1332 else if (theId == "SHOW_CMD") {
1333 showObjects(aObjects, true);
1334 mySelector->updateSelectionBy(ModuleBase_ISelection::Browser);
1335 updateCommandStatus();
1337 else if (theId == "HIDE_CMD") {
1338 showObjects(aObjects, false);
1339 updateCommandStatus();
1341 else if (theId == "SHOW_ONLY_CMD") {
1342 showOnlyObjects(aObjects);
1343 mySelector->updateSelectionBy(ModuleBase_ISelection::Browser);
1344 updateCommandStatus();
1346 else if (theId == "SHADING_CMD")
1347 setDisplayMode(aObjects, XGUI_Displayer::Shading);
1348 else if (theId == "WIREFRAME_CMD")
1349 setDisplayMode(aObjects, XGUI_Displayer::Wireframe);
1350 else if (theId == "HIDEALL_CMD") {
1351 QObjectPtrList aList = myDisplayer->displayedObjects();
1352 foreach (ObjectPtr aObj, aList) {
1353 if (module()->canEraseObject(aObj))
1354 aObj->setDisplayed(false);
1356 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1357 updateCommandStatus();
1358 } else if (theId == "SELECT_VERTEX_CMD") {
1359 setViewerSelectionMode(TopAbs_VERTEX);
1360 } else if (theId == "SELECT_EDGE_CMD") {
1361 setViewerSelectionMode(TopAbs_EDGE);
1362 } else if (theId == "SELECT_FACE_CMD") {
1363 setViewerSelectionMode(TopAbs_FACE);
1364 } else if (theId == "SELECT_RESULT_CMD") {
1365 //setViewerSelectionMode(-1);
1366 //IMP: an attempt to use result selection with other selection modes
1367 setViewerSelectionMode(ModuleBase_ResultPrs::Sel_Result);
1368 setViewerSelectionMode(TopAbs_COMPSOLID);
1369 } else if (theId == "SHOW_RESULTS_CMD") {
1370 highlightResults(aObjects);
1371 } else if (theId == "SHOW_FEATURE_CMD") {
1372 highlightFeature(aObjects);
1375 else if (theId == "VINSPECTOR_VIEW") {
1376 displayer()->setVInspectorVisible(true);
1380 else if (theId == "DFBROWSER_VIEW") {
1381 if (DFBrowser_FirstCall) {
1382 Handle(CDF_Application) anApplication = CDF_Session::CurrentSession()->CurrentApplication();
1383 DFBrowserAPI_Communicator* aCommunicator =
1384 DFBrowserAPI_Communicator::loadPluginLibrary("TKDFBrowser.dll");
1385 if (aCommunicator) {
1386 aCommunicator->setApplication(anApplication);
1387 Handle(AIS_InteractiveContext) aContext = viewer()->AISContext();
1389 aCommunicator->setContext(aContext);
1391 DFBrowser_FirstCall = false;
1397 //**************************************************************
1398 void XGUI_Workshop::setViewerSelectionMode(int theMode)
1401 myViewerSelMode.clear();
1403 if (myViewerSelMode.contains(theMode))
1404 myViewerSelMode.removeAll(theMode);
1406 myViewerSelMode.append(theMode);
1408 activateObjectsSelection(myDisplayer->displayedObjects());
1411 //**************************************************************
1412 void XGUI_Workshop::activateObjectsSelection(const QObjectPtrList& theList)
1415 module()->activeSelectionModes(aModes);
1416 if (aModes.isEmpty() && (myViewerSelMode.length() > 0))
1417 aModes.append(myViewerSelMode);
1418 myDisplayer->activateObjects(aModes, theList);
1421 //**************************************************************
1422 void XGUI_Workshop::deleteObjects()
1424 ModuleBase_IModule* aModule = module();
1425 // allow the module to delete objects, do nothing if it has succeed
1426 if (aModule->deleteObjects()) {
1427 updateCommandStatus();
1431 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1432 if (!abortAllOperations())
1435 bool hasResult = false;
1436 bool hasFeature = false;
1437 bool hasParameter = false;
1438 bool hasCompositeOwner = false;
1439 ModuleBase_Tools::checkObjects(anObjects, hasResult, hasFeature, hasParameter, hasCompositeOwner);
1440 if (!(hasFeature || hasParameter))
1444 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1445 std::set<FeaturePtr> aFeatures;
1446 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1447 ModelAPI_Tools::findAllReferences(aFeatures, aReferences);
1450 QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text() + " %1";
1451 aDescription = aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
1452 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, module());
1454 operationMgr()->startOperation(anOpAction);
1456 std::set<FeaturePtr> aFeatureRefsToDelete;
1457 if (ModuleBase_Tools::askToDelete(aFeatures, aReferences, desktop(), aFeatureRefsToDelete)) {
1458 // WORKAROUND, should be done before each object remove, if it presents in XGUI_DataModel tree
1459 // It is necessary to clear selection in order to avoid selection changed event during
1460 // deletion and negative consequences connected with processing of already deleted items
1461 mySelector->clearSelection();
1463 if (!aFeatureRefsToDelete.empty())
1464 aFeatures.insert(aFeatureRefsToDelete.begin(), aFeatureRefsToDelete.end());
1465 aDone = ModelAPI_Tools::removeFeatures(aFeatures, false);
1468 operationMgr()->commitOperation();
1470 operationMgr()->abortOperation(operationMgr()->currentOperation());
1473 //**************************************************************
1474 void addRefsToFeature(const FeaturePtr& theFeature,
1475 const std::map<FeaturePtr, std::set<FeaturePtr> >& theMainList,
1476 std::set<FeaturePtr>& theReferences)
1478 //if (theReferences.find(theFeature) != theReferences.end())
1480 if (theMainList.find(theFeature) == theMainList.end())
1481 return; // this feature is not in the selection list, so exists without references to it
1482 std::set<FeaturePtr> aMainReferences = theMainList.at(theFeature);
1484 std::set<FeaturePtr>::const_iterator anIt = aMainReferences.begin(),
1485 aLast = aMainReferences.end();
1486 for (; anIt != aLast; anIt++) {
1487 FeaturePtr aRefFeature = *anIt;
1488 if (theReferences.find(aRefFeature) == theReferences.end())
1489 theReferences.insert(aRefFeature);
1490 addRefsToFeature(aRefFeature, theMainList, theReferences);
1494 //**************************************************************
1495 void XGUI_Workshop::cleanHistory()
1497 if (!abortAllOperations())
1500 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1501 std::set<FeaturePtr> aFeatures;
1502 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1504 #ifdef DEBUG_CLEAN_HISTORY
1506 std::set<FeaturePtr>::const_iterator aFIt;
1507 for (aFIt = aFeatures.begin(); aFIt != aFeatures.end(); ++aFIt) {
1508 FeaturePtr aFeature = ModelAPI_Feature::feature(*aFIt);
1509 anInfo.append(aFeature->name().c_str());
1511 QString anInfoStr = anInfo.join(";\t");
1512 qDebug(QString("cleanHistory for: [%1] - %2").
1513 arg(aFeatures.size()).arg(anInfoStr).toStdString().c_str());
1516 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1517 ModelAPI_Tools::findAllReferences(aFeatures, aReferences, true, false);
1518 // find for each object whether all reference values are in the map as key, that means that there
1519 // is no other reference in the model to this object, so it might be removed by cleaning history
1520 // sk_1(ext_1, vertex_1) + (sk_3, bool_1) - cann't be deleted, dependency to bool_1
1521 // ext_1(bool_1, sk_3) - cann't be deleted, dependency to bool_1
1523 // sk_2(ext_2) + (bool_1) - cann't be deleted, dependency to bool_1
1524 // ext_2(bool_1) - cann't be deleted, dependency to bool_1
1526 // Information: bool_1 is not selected
1527 std::set<FeaturePtr> anUnusedObjects;
1528 std::map<FeaturePtr, std::set<FeaturePtr> >::const_iterator aMainIt = aReferences.begin(),
1529 aMainLast = aReferences.end();
1530 for (; aMainIt != aMainLast; aMainIt++) {
1531 FeaturePtr aMainListFeature = aMainIt->first;
1532 std::set<FeaturePtr> aMainRefList = aMainIt->second;
1533 std::set<FeaturePtr>::const_iterator aRefIt = aMainRefList.begin(),
1534 aRefLast = aMainRefList.end();
1535 bool aFeatureOutOfTheList = false;
1536 for (; aRefIt != aRefLast && !aFeatureOutOfTheList; aRefIt++) {
1537 FeaturePtr aRefFeature = *aRefIt;
1538 aFeatureOutOfTheList = aReferences.find(aRefFeature) == aReferences.end();
1540 if (!aFeatureOutOfTheList)
1541 anUnusedObjects.insert(aMainListFeature);
1544 #ifdef DEBUG_CLEAN_HISTORY
1546 for (aFIt = anUnusedObjects.begin(); aFIt != anUnusedObjects.end(); ++aFIt) {
1547 FeaturePtr aFeature = *aFIt;
1548 anInfo.append(aFeature->name().c_str());
1550 qDebug(QString("unused objects: [%1] - %2").
1551 arg(anInfo.size()).arg(anInfo.join(";\t")).toStdString().c_str());
1554 // warn about the references remove, break the delete operation if the user chose it
1555 if (!anUnusedObjects.empty()) {
1557 foreach (const FeaturePtr& aFeature, anUnusedObjects) {
1558 aNames.append(aFeature->name().c_str());
1561 QString anUnusedNames = aNames.join(", ");
1563 QString anActionId = "CLEAN_HISTORY_CMD";
1564 QString aDescription = contextMenuMgr()->action(anActionId)->text();
1566 QMessageBox aMessageBox(desktop());
1567 aMessageBox.setWindowTitle(aDescription);
1568 aMessageBox.setIcon(QMessageBox::Warning);
1569 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
1570 aMessageBox.setDefaultButton(QMessageBox::No);
1572 const char* aKeyStr = "Unused features are the following: "
1573 "%1.\nThese features will be deleted.\nWould you like to continue?";
1574 QString aText = QString(tr(aKeyStr).arg(anUnusedNames));
1575 aMessageBox.setText(aText);
1576 if (aMessageBox.exec() == QMessageBox::No)
1579 // 1. start operation
1580 aDescription += "by deleting of " +
1581 aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
1582 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, module());
1583 operationMgr()->startOperation(anOpAction);
1585 // WORKAROUND, should be done before each object remove, if it presents in XGUI_DataModel tree
1586 // It is necessary to clear selection in order to avoid selection changed event during
1587 // deletion and negative consequences connected with processing of already deleted items
1588 mySelector->clearSelection();
1590 std::set<FeaturePtr> anIgnoredFeatures;
1591 if (ModelAPI_Tools::removeFeatures(anUnusedObjects, true)) {
1592 operationMgr()->commitOperation();
1595 operationMgr()->abortOperation(operationMgr()->currentOperation());
1599 QString anActionId = "CLEAN_HISTORY_CMD";
1600 QString aDescription = contextMenuMgr()->action(anActionId)->text();
1602 QMessageBox aMessageBox(desktop());
1603 aMessageBox.setWindowTitle(aDescription);
1604 aMessageBox.setIcon(QMessageBox::Warning);
1605 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
1606 aMessageBox.setDefaultButton(QMessageBox::No);
1609 aMessageBox.setStandardButtons(QMessageBox::Ok);
1610 aMessageBox.setDefaultButton(QMessageBox::Ok);
1612 aText = QString(tr("All features are relevant, there is nothing to be deleted"));
1613 aMessageBox.setText(aText);
1615 if (aMessageBox.exec() == QMessageBox::No)
1620 //**************************************************************
1621 void XGUI_Workshop::moveObjects()
1623 if (!abortAllOperations())
1626 SessionPtr aMgr = ModelAPI_Session::get();
1628 QString anActionId = "MOVE_CMD";
1629 QString aDescription = contextMenuMgr()->action(anActionId)->text();
1630 aMgr->startOperation(aDescription.toStdString());
1632 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1633 // It is necessary to clear selection in order to avoid selection changed event during
1634 // moving and negative consequences connected with processing of already moved items
1635 mySelector->clearSelection();
1636 // check whether the object can be moved. There should not be parts which are not loaded
1637 std::set<FeaturePtr> aFeatures;
1638 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1639 if (!XGUI_Tools::canRemoveOrRename(desktop(), aFeatures))
1642 DocumentPtr anActiveDocument = aMgr->activeDocument();
1643 FeaturePtr aCurrentFeature = anActiveDocument->currentFeature(true);
1644 std::set<FeaturePtr>::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
1645 for (; anIt != aLast; anIt++) {
1646 FeaturePtr aFeature = *anIt;
1647 if (!aFeature.get() || !myModule->canApplyAction(aFeature, anActionId))
1650 anActiveDocument->moveFeature(aFeature, aCurrentFeature);
1651 aCurrentFeature = anActiveDocument->currentFeature(true);
1653 aMgr->finishOperation();
1656 //**************************************************************
1657 bool XGUI_Workshop::deleteFeatures(const QObjectPtrList& theObjects)
1659 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1660 std::set<FeaturePtr> aFeatures;
1661 ModuleBase_Tools::convertToFeatures(theObjects, aFeatures);
1663 return ModelAPI_Tools::removeFeaturesAndReferences(aFeatures);
1666 bool hasResults(QObjectPtrList theObjects, const std::set<std::string>& theTypes)
1668 bool isFoundResultType = false;
1669 foreach(ObjectPtr anObj, theObjects)
1671 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
1672 if (aResult.get() == NULL)
1675 isFoundResultType = theTypes.find(aResult->groupName()) != theTypes.end();
1676 if (isFoundResultType)
1679 return isFoundResultType;
1682 //**************************************************************
1683 // Returns the list of all features for theDocument and all features of
1684 // all nested parts.
1685 std::list<FeaturePtr> allFeatures(const DocumentPtr& theDocument)
1687 std::list<FeaturePtr> aResultList;
1688 std::list<FeaturePtr> anAllFeatures = theDocument->allFeatures();
1689 foreach (const FeaturePtr& aFeature, anAllFeatures) {
1690 // The order of appending features of the part and the part itself is important
1692 // Append features from a part feature
1693 std::list<ResultPtr> aResults;
1694 ModelAPI_Tools::allResults(aFeature, aResults);
1695 foreach (const ResultPtr& aResult, aResults) {
1696 ResultPartPtr aResultPart =
1697 std::dynamic_pointer_cast<ModelAPI_ResultPart>(aResult);
1698 if (aResultPart.get() && aResultPart->partDoc().get()) {
1700 std::list<FeaturePtr> anAllFeatures = allFeatures(aResultPart->partDoc());
1701 aResultList.insert(aResultList.end(), anAllFeatures.begin(), anAllFeatures.end());
1705 aResultList.push_back(aFeature);
1710 //**************************************************************
1711 // Returns the list of features placed between theObject and the current feature
1712 // in the same document. Excludes theObject, includes the current feature.
1713 std::list<FeaturePtr> toCurrentFeatures(const ObjectPtr& theObject)
1715 std::list<FeaturePtr> aResult;
1716 DocumentPtr aDocument = theObject->document();
1717 std::list<FeaturePtr> anAllFeatures = allFeatures(aDocument);
1718 // find the object iterator
1719 std::list<FeaturePtr>::iterator aObjectIt =
1720 std::find(anAllFeatures.begin(), anAllFeatures.end(), theObject);
1721 if (aObjectIt == anAllFeatures.end())
1723 // find the current feature iterator
1724 std::list<FeaturePtr>::iterator aCurrentIt =
1725 std::find(anAllFeatures.begin(), anAllFeatures.end(), aDocument->currentFeature(true));
1726 if (aCurrentIt == anAllFeatures.end())
1728 // check the right order
1729 if (std::distance(aObjectIt, anAllFeatures.end()) <=
1730 std::distance(aCurrentIt, anAllFeatures.end()))
1732 // exclude the object
1733 std::advance(aObjectIt, 1);
1734 // include the current feature
1735 std::advance(aCurrentIt, 1);
1736 return std::list<FeaturePtr>(aObjectIt, aCurrentIt);
1739 bool XGUI_Workshop::canMoveFeature()
1741 QString anActionId = "MOVE_CMD";
1743 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1744 QObjectPtrList aValidatedObjects;
1745 foreach (ObjectPtr aObject, aObjects) {
1746 if (!myModule->canApplyAction(aObject, anActionId))
1748 // To be moved feature should be in active document
1749 if (aObject->document() != ModelAPI_Session::get()->activeDocument())
1751 aValidatedObjects.append(aObject);
1753 if (aValidatedObjects.size() != aObjects.size())
1754 aObjects = aValidatedObjects;
1756 bool aCanMove = !aObjects.empty();
1758 QObjectPtrList::const_iterator anIt = aObjects.begin(), aLast = aObjects.end();
1759 for (; anIt != aLast && aCanMove; anIt++) {
1760 ObjectPtr aObject = *anIt;
1761 // 1. Get features placed between selected and current in the document
1762 std::list<FeaturePtr> aFeaturesBetween = toCurrentFeatures(aObject);
1763 // if aFeaturesBetween is empty it means wrong order or aObject is the current feature
1764 if (aFeaturesBetween.empty())
1767 std::set<FeaturePtr> aPlacedFeatures(aFeaturesBetween.begin(), aFeaturesBetween.end());
1768 // 2. Get all reference features to the selected object in the document
1769 std::set<FeaturePtr> aRefFeatures;
1770 ModuleBase_Tools::refsToFeatureInFeatureDocument(aObject, aRefFeatures);
1772 if (aRefFeatures.empty())
1775 // 3. Find any placed features in all reference features
1776 std::set<FeaturePtr> aIntersectionFeatures;
1777 std::set_intersection(aRefFeatures.begin(), aRefFeatures.end(),
1778 aPlacedFeatures.begin(), aPlacedFeatures.end(),
1779 std::inserter(aIntersectionFeatures, aIntersectionFeatures.begin()));
1780 // 4. Return false if any reference feature is placed before current feature
1781 if (!aIntersectionFeatures.empty())
1789 //**************************************************************
1790 bool XGUI_Workshop::canBeShaded(const ObjectPtr& theObject) const
1792 bool aCanBeShaded = myDisplayer->canBeShaded(theObject);
1793 if (!aCanBeShaded) {
1794 ResultCompSolidPtr aCompsolidResult =
1795 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
1796 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
1797 for(int i = 0; i < aCompsolidResult->numberOfSubs() && !aCanBeShaded; i++)
1798 aCanBeShaded = myDisplayer->canBeShaded(aCompsolidResult->subResult(i));
1801 return aCanBeShaded;
1804 //**************************************************************
1805 bool XGUI_Workshop::canChangeColor() const
1807 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1809 std::set<std::string> aTypes;
1810 aTypes.insert(ModelAPI_ResultGroup::group());
1811 aTypes.insert(ModelAPI_ResultConstruction::group());
1812 aTypes.insert(ModelAPI_ResultBody::group());
1813 aTypes.insert(ModelAPI_ResultPart::group());
1815 return hasResults(aObjects, aTypes);
1818 void setColor(ResultPtr theResult, const std::vector<int>& theColor)
1820 if (!theResult.get())
1823 AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
1824 if (aColorAttr.get() != NULL) {
1825 if (!aColorAttr->size()) {
1826 aColorAttr->setSize(3);
1828 aColorAttr->setValue(0, theColor[0]);
1829 aColorAttr->setValue(1, theColor[1]);
1830 aColorAttr->setValue(2, theColor[2]);
1834 //**************************************************************
1835 void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
1838 AttributeIntArrayPtr aColorAttr;
1839 // 1. find the current color of the object. This is a color of AIS presentation
1840 // The objects are iterated until a first valid color is found
1841 std::vector<int> aColor;
1842 foreach(ObjectPtr anObject, theObjects) {
1843 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1844 if (aResult.get()) {
1845 XGUI_CustomPrs::getResultColor(aResult, aColor);
1848 // TODO: remove the obtaining a color from the AIS object
1849 // this does not happen never because:
1850 // 1. The color can be changed only on results
1851 // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
1852 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
1853 if (anAISObj.get()) {
1855 anAISObj->getColor(aColor[0], aColor[1], aColor[2]);
1858 if (!aColor.empty())
1861 if (aColor.size() != 3)
1864 if (!abortAllOperations())
1866 // 2. show the dialog to change the value
1867 XGUI_ColorDialog* aDlg = new XGUI_ColorDialog(desktop());
1868 aDlg->setColor(aColor);
1869 aDlg->move(QCursor::pos());
1870 bool isDone = aDlg->exec() == QDialog::Accepted;
1874 bool isRandomColor = aDlg->isRandomColor();
1876 // 3. abort the previous operation and start a new one
1877 SessionPtr aMgr = ModelAPI_Session::get();
1878 QString aDescription = contextMenuMgr()->action("COLOR_CMD")->text();
1879 aMgr->startOperation(aDescription.toStdString());
1881 // 4. set the value to all results
1882 std::vector<int> aColorResult = aDlg->getColor();
1883 foreach(ObjectPtr anObj, theObjects) {
1884 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
1885 if (aResult.get() != NULL) {
1886 ResultCompSolidPtr aCompsolidResult =
1887 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
1888 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
1889 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
1890 setColor(aCompsolidResult->subResult(i), !isRandomColor ? aColorResult :
1891 aDlg->getRandomColor());
1894 setColor(aResult, !isRandomColor ? aColorResult : aDlg->getRandomColor());
1897 aMgr->finishOperation();
1898 updateCommandStatus();
1901 //**************************************************************
1902 bool XGUI_Workshop::canChangeDeflection() const
1904 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1906 std::set<std::string> aTypes;
1907 aTypes.insert(ModelAPI_ResultGroup::group());
1908 aTypes.insert(ModelAPI_ResultConstruction::group());
1909 aTypes.insert(ModelAPI_ResultBody::group());
1910 aTypes.insert(ModelAPI_ResultPart::group());
1912 return hasResults(aObjects, aTypes);
1915 void setDeflection(ResultPtr theResult, const double theDeflection)
1917 if (!theResult.get())
1920 AttributeDoublePtr aDeflectionAttr = theResult->data()->real(ModelAPI_Result::DEFLECTION_ID());
1921 if (aDeflectionAttr.get() != NULL)
1922 aDeflectionAttr->setValue(theDeflection);
1926 //**************************************************************
1927 void XGUI_Workshop::changeDeflection(const QObjectPtrList& theObjects)
1929 AttributeDoublePtr aDoubleAttr;
1930 // 1. find the current color of the object. This is a color of AIS presentation
1931 // The objects are iterated until a first valid color is found
1932 double aDeflection = -1;
1933 foreach(ObjectPtr anObject, theObjects) {
1934 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1935 if (aResult.get()) {
1936 aDeflection = XGUI_CustomPrs::getResultDeflection(aResult);
1939 // TODO: remove the obtaining a color from the AIS object
1940 // this does not happen never because:
1941 // 1. The color can be changed only on results
1942 // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
1943 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
1944 if (anAISObj.get()) {
1945 aDeflection = anAISObj->getDeflection();
1948 if (aDeflection > 0)
1951 if (aDeflection < 0)
1954 if (!abortAllOperations())
1956 // 2. show the dialog to change the value
1957 XGUI_DeflectionDialog* aDlg = new XGUI_DeflectionDialog(desktop());
1958 aDlg->setDeflection(aDeflection);
1959 aDlg->move(QCursor::pos());
1960 bool isDone = aDlg->exec() == QDialog::Accepted;
1964 // 3. abort the previous operation and start a new one
1965 SessionPtr aMgr = ModelAPI_Session::get();
1966 QString aDescription = contextMenuMgr()->action("DEFLECTION_CMD")->text();
1967 aMgr->startOperation(aDescription.toStdString());
1969 // 4. set the value to all results
1970 aDeflection = aDlg->getDeflection();
1971 foreach(ObjectPtr anObj, theObjects) {
1972 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
1973 if (aResult.get() != NULL) {
1974 ResultCompSolidPtr aCompsolidResult =
1975 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
1976 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
1977 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
1978 setDeflection(aCompsolidResult->subResult(i), aDeflection);
1981 setDeflection(aResult, aDeflection);
1984 aMgr->finishOperation();
1985 updateCommandStatus();
1988 //**************************************************************
1989 #define SET_DISPLAY_GROUP(aGroupName, aDisplay) \
1990 for (int i = 0; i < aDoc->size(aGroupName); i++) { \
1991 aDoc->object(aGroupName, i)->setDisplayed(aDisplay); \
1993 void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible)
1995 foreach (ObjectPtr aObj, theList) {
1996 aObj->setDisplayed(isVisible);
1998 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2001 //**************************************************************
2002 void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList)
2004 // Hide all displayed objects
2005 QObjectPtrList aList = myDisplayer->displayedObjects();
2006 foreach (ObjectPtr aObj, aList) {
2007 if (module()->canEraseObject(aObj))
2008 aObj->setDisplayed(false);
2011 // Show only objects from the list
2012 foreach (ObjectPtr aObj, theList) {
2013 aObj->setDisplayed(true);
2015 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2019 //**************************************************************
2020 void XGUI_Workshop::registerValidators() const
2022 SessionPtr aMgr = ModelAPI_Session::get();
2023 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
2026 //**************************************************************
2027 void XGUI_Workshop::displayDocumentResults(DocumentPtr theDoc)
2031 displayGroupResults(theDoc, ModelAPI_ResultConstruction::group());
2032 displayGroupResults(theDoc, ModelAPI_ResultBody::group());
2035 //**************************************************************
2036 void XGUI_Workshop::displayGroupResults(DocumentPtr theDoc, std::string theGroup)
2038 for (int i = 0; i < theDoc->size(theGroup); i++)
2039 theDoc->object(theGroup, i)->setDisplayed(true);
2040 //displayObject(theDoc->object(theGroup, i));
2041 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2044 //**************************************************************
2045 void XGUI_Workshop::setDisplayMode(const QObjectPtrList& theList, int theMode)
2047 foreach(ObjectPtr aObj, theList) {
2048 myDisplayer->setDisplayMode(aObj, (XGUI_Displayer::DisplayMode)theMode, false);
2050 ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aObj);
2051 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
2052 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
2053 myDisplayer->setDisplayMode(aCompsolidResult->subResult(i),
2054 (XGUI_Displayer::DisplayMode)theMode, false);
2058 if (theList.size() > 0)
2059 myDisplayer->updateViewer();
2062 //**************************************************************
2063 void XGUI_Workshop::closeDocument()
2065 ModuleBase_Operation* anOperation = operationMgr()->currentOperation();
2066 while (anOperation) {
2067 anOperation->abort();
2068 anOperation = operationMgr()->currentOperation();
2070 //myDisplayer->closeLocalContexts();
2071 myDisplayer->eraseAll();
2072 objectBrowser()->clearContent();
2074 module()->closeDocument();
2076 // data model need not process the document's signals about objects modifications as
2077 // the document is closed
2078 //bool isBlocked = objectBrowser()->dataModel()->blockEventsProcessing(true);
2080 SessionPtr aMgr = ModelAPI_Session::get();
2083 //objectBrowser()->dataModel()->blockEventsProcessing(isBlocked);
2086 void XGUI_Workshop::addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot)
2088 XGUI_HistoryMenu* aMenu = NULL;
2089 if (isSalomeMode()) {
2090 QAction* anAction = qobject_cast<QAction*>(theObject);
2093 aMenu = new XGUI_HistoryMenu(anAction);
2095 QToolButton* aButton = qobject_cast<QToolButton*>(theObject);
2096 aMenu = new XGUI_HistoryMenu(aButton);
2098 connect(this, theSignal, aMenu, SLOT(setHistory(const QList<ActionInfo>&)));
2099 connect(aMenu, SIGNAL(actionSelected(int)), this, theSlot);
2102 QList<ActionInfo> XGUI_Workshop::processHistoryList(const std::list<std::string>& theList) const
2104 QList<ActionInfo> aResult;
2105 std::list<std::string>::const_iterator it = theList.cbegin();
2106 for (; it != theList.cend(); it++) {
2107 QString anId = QString::fromStdString(*it);
2108 bool isEditing = anId.endsWith(ModuleBase_OperationFeature::EditSuffix());
2110 anId.chop(ModuleBase_OperationFeature::EditSuffix().size());
2113 QAction* aContextMenuAct = myContextMenuMgr->actionByName(anId);
2114 if (aContextMenuAct) {
2115 anInfo.initFrom(aContextMenuAct);
2117 anInfo = myActionsMgr->actionInfoById(anId);
2120 anInfo.text = anInfo.text.prepend("Modify ");
2127 void XGUI_Workshop::setStatusBarMessage(const QString& theMessage)
2130 salomeConnector()->putInfo(theMessage, -1);
2132 myMainWindow->putInfo(theMessage, -1);
2136 void XGUI_Workshop::synchronizeViewer()
2138 SessionPtr aMgr = ModelAPI_Session::get();
2139 DocumentPtr aDoc = aMgr->activeDocument();
2141 synchronizeGroupInViewer(aDoc, ModelAPI_ResultConstruction::group(), false);
2142 synchronizeGroupInViewer(aDoc, ModelAPI_ResultBody::group(), false);
2143 synchronizeGroupInViewer(aDoc, ModelAPI_ResultPart::group(), false);
2144 synchronizeGroupInViewer(aDoc, ModelAPI_ResultGroup::group(), false);
2147 void XGUI_Workshop::synchronizeGroupInViewer(const DocumentPtr& theDoc,
2148 const std::string& theGroup,
2149 bool theUpdateViewer)
2152 int aSize = theDoc->size(theGroup);
2153 for (int i = 0; i < aSize; i++) {
2154 aObj = theDoc->object(theGroup, i);
2155 if (aObj->isDisplayed()) {
2156 // Hide the presentation with an empty shape. But isDisplayed state of the object should not
2157 // be changed to the object becomes visible when the shape becomes not empty
2158 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
2159 if (aRes.get() && (!aRes->shape().get() || aRes->shape()->isNull()))
2161 myDisplayer->display(aObj, false);
2164 if (theUpdateViewer)
2165 myDisplayer->updateViewer();
2168 void XGUI_Workshop::highlightResults(const QObjectPtrList& theObjects)
2170 FeaturePtr aFeature;
2171 QObjectPtrList aSelList = theObjects;
2172 bool aHasHidden = false;
2173 foreach(ObjectPtr aObj, theObjects) {
2174 aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
2175 if (aFeature.get()) {
2176 std::list<ResultPtr> aResults;
2177 ModelAPI_Tools::allResults(aFeature, aResults);
2178 std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aIt;
2179 for(aIt = aResults.cbegin(); aIt != aResults.cend(); aIt++) {
2180 aHasHidden |= (*aIt)->isConcealed();
2181 aSelList.append(*aIt);
2185 if (aSelList.count() > theObjects.count()) {
2186 // if something was found
2187 bool aBlocked = objectBrowser()->blockSignals(true);
2188 objectBrowser()->setObjectsSelected(aSelList);
2189 objectBrowser()->blockSignals(aBlocked);
2192 QMessageBox::information(desktop(), tr("Find results"),
2193 tr("Results not found"), QMessageBox::Ok);
2196 void XGUI_Workshop::highlightFeature(const QObjectPtrList& theObjects)
2199 QObjectPtrList aSelList = theObjects;
2200 FeaturePtr aFeature;
2201 foreach(ObjectPtr aObj, theObjects) {
2202 aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
2203 if (aResult.get()) {
2204 aFeature = ModelAPI_Feature::feature(aResult);
2205 if (aFeature.get()) {
2206 aSelList.append(aFeature);
2210 if (aSelList.count() > theObjects.count()) {
2211 // if something was found
2212 bool aBlocked = objectBrowser()->blockSignals(true);
2213 objectBrowser()->setObjectsSelected(aSelList);
2214 objectBrowser()->blockSignals(aBlocked);