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_IModule.h>
62 #include <ModuleBase_IViewer.h>
63 #include <ModuleBase_Operation.h>
64 #include <ModuleBase_OperationDescription.h>
65 #include <ModuleBase_PageBase.h>
66 #include <ModuleBase_Preferences.h>
67 #include <ModuleBase_SelectionValidator.h>
68 #include <ModuleBase_Tools.h>
69 #include <ModuleBase_WidgetFactory.h>
70 #include <ModuleBase_OperationFeature.h>
71 #include <ModuleBase_OperationAction.h>
72 #include <ModuleBase_PagedContainer.h>
73 #include <ModuleBase_WidgetValidated.h>
74 #include <ModuleBase_ModelWidget.h>
75 #include <ModuleBase_ResultPrs.h>
77 #include <Config_Common.h>
78 #include <Config_FeatureMessage.h>
79 #include <Config_ModuleReader.h>
80 #include <Config_PointerMessage.h>
81 #include <Config_PropManager.h>
82 #include <Config_DataModelReader.h>
83 #include <Config_Translator.h>
85 #include <SUIT_ResourceMgr.h>
87 #include <AIS_Trihedron.hxx>
88 #include <AIS_Point.hxx>
89 #include <AIS_Axis.hxx>
91 #include <QApplication>
92 #include <QFileDialog>
93 #include <QMessageBox>
94 #include <QMdiSubWindow>
95 #include <QMainWindow>
96 #include <QPushButton>
97 #include <QDockWidget>
102 #include <QToolButton>
104 #include <QDesktopWidget>
109 #include <CDF_Session.hxx>
110 #include <CDF_Application.hxx>
111 #include <DFBrowserAPI_Communicator.hxx>
112 static bool DFBrowser_FirstCall = true;
126 QString XGUI_Workshop::MOVE_TO_END_COMMAND = QObject::tr("Move to the end");
128 //#define DEBUG_DELETE
129 //#define DEBUG_FEATURE_NAME
130 //#define DEBUG_CLEAN_HISTORY
132 XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
134 myCurrentDir(QString()),
136 mySalomeConnector(theConnector),
140 //myViewerSelMode(TopAbs_FACE)
142 mySelector = new XGUI_SelectionMgr(this);
143 myModuleConnector = new XGUI_ModuleConnector(this);
144 myOperationMgr = new XGUI_OperationMgr(this, 0);
145 ModuleBase_IWorkshop* aWorkshop = moduleConnector();
146 // Has to be defined first in order to get errors and messages from other components
147 myEventsListener = new XGUI_WorkshopListener(aWorkshop);
149 SUIT_ResourceMgr* aResMgr = ModuleBase_Preferences::resourceMgr();
151 myMainWindow = new AppElements_MainWindow();
153 bool aCloc = aResMgr->booleanValue("language", "locale", true);
155 QLocale::setDefault( QLocale::c() );
157 QLocale::setDefault( QLocale::system() );
159 QString aPath = Config_XMLReader::pluginConfigFile().c_str();
164 aLangs << "*_en.ts"; // load by default eng translations
165 QString aCurrLang = aResMgr->stringValue("language", "language", "en");
166 if(aCurrLang != "en") {
167 aLangs << "*_" + aCurrLang + ".ts"; // then replace with translated files
170 foreach(QString aLang, aLangs) {
171 QStringList aFilters;
173 QStringList aTsFiles = aDir.entryList(aFilters, QDir::Files);
174 foreach(QString aFileName, aTsFiles) {
175 Config_Translator::load(aFileName.toStdString());
179 myDataModelXMLReader = new Config_DataModelReader();
180 //myDataModelXMLReader->readAll();
182 myDisplayer = new XGUI_Displayer(this);
184 connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(updateCommandStatus()));
186 myActionsMgr = new XGUI_ActionsMgr(this);
187 myMenuMgr = new XGUI_MenuMgr(this);
188 myErrorDlg = new XGUI_ErrorDialog(QApplication::desktop());
189 myContextMenuMgr = new XGUI_ContextMenuMgr(this);
190 connect(myContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), this,
191 SLOT(onContextMenuCommand(const QString&, bool)));
193 myViewerProxy = new XGUI_ViewerProxy(this);
194 //connect(myViewerProxy, SIGNAL(selectionChanged()),
195 // myActionsMgr, SLOT(updateOnViewSelection()));
197 myOperationMgr->setWorkshop(aWorkshop);
199 myErrorMgr = new XGUI_ErrorMgr(this, aWorkshop);
201 connect(myOperationMgr, SIGNAL(operationResumed(ModuleBase_Operation*)),
202 SLOT(onOperationResumed(ModuleBase_Operation*)));
203 connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
204 SLOT(onOperationStopped(ModuleBase_Operation*)));
205 connect(myOperationMgr, SIGNAL(operationCommitted(ModuleBase_Operation*)),
206 SLOT(onOperationCommitted(ModuleBase_Operation*)));
207 connect(myOperationMgr, SIGNAL(operationAborted(ModuleBase_Operation*)),
208 SLOT(onOperationAborted(ModuleBase_Operation*)));
211 connect(myMainWindow, SIGNAL(exitKeySequence()), SLOT(onExit()));
212 onTrihedronVisibilityChanged(true);
215 connect(myEventsListener, SIGNAL(errorOccurred(std::shared_ptr<Events_InfoMessage>)),
216 myErrorDlg, SLOT(addError(std::shared_ptr<Events_InfoMessage>)));
218 //Config_PropManager::registerProp("Visualization", "object_default_color", "Object color",
219 // Config_Prop::Color, "225,225,225");
221 Config_PropManager::registerProp("Visualization", "result_body_color", "Result color",
222 Config_Prop::Color, ModelAPI_ResultBody::DEFAULT_COLOR());
223 Config_PropManager::registerProp("Visualization", "result_group_color", "Group color",
224 Config_Prop::Color, ModelAPI_ResultGroup::DEFAULT_COLOR());
225 Config_PropManager::registerProp("Visualization", "result_construction_color",
226 "Construction color",
228 ModelAPI_ResultConstruction::DEFAULT_COLOR());
229 Config_PropManager::registerProp("Visualization", "result_part_color", "Part color",
230 Config_Prop::Color, ModelAPI_ResultPart::DEFAULT_COLOR());
232 Config_PropManager::registerProp("Visualization", "body_deflection",
233 "Body deflection coefficient",
235 ModelAPI_ResultBody::DEFAULT_DEFLECTION());
237 Config_PropManager::registerProp("Visualization", "construction_deflection",
238 "Construction deflection coefficient",
240 ModelAPI_ResultConstruction::DEFAULT_DEFLECTION());
242 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "face-selection", true))
243 myViewerSelMode.append(TopAbs_FACE);
244 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "edge-selection", true))
245 myViewerSelMode.append(TopAbs_EDGE);
246 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "vertex-selection", true))
247 myViewerSelMode.append(TopAbs_VERTEX);
248 //IMP: an attempt to use result selection with other selection modes
249 myViewerSelMode.append(ModuleBase_ResultPrs::Sel_Result);//TopAbs_VERTEX);
250 myViewerSelMode.append(TopAbs_COMPSOLID);
253 //******************************************************
254 XGUI_Workshop::~XGUI_Workshop(void)
257 #ifdef MISSED_TRANSLATION
258 // Save Missed translations
259 Config_Translator::saveMissedTranslations();
264 delete myDataModelXMLReader;
267 //******************************************************
268 void XGUI_Workshop::startApplication()
270 //Initialize event listening
271 myEventsListener->initializeEventListening();
273 myDataModelXMLReader->readAll();
276 Config_PropManager::registerProp("Plugins", "default_path", "Default Path",
277 Config_Prop::Directory, "");
280 registerValidators();
282 // Calling of loadCustomProps before activating module is required
283 // by Config_PropManger to restore user-defined path to plugins
284 ModuleBase_Preferences::loadCustomProps();
288 myMainWindow->show();
289 updateCommandStatus();
294 myViewerProxy->connectViewProxy();
295 connect(myViewerProxy, SIGNAL(trihedronVisibilityChanged(bool)),
296 SLOT(onTrihedronVisibilityChanged(bool)));
298 emit applicationStarted();
301 void XGUI_Workshop::activateModule()
303 myModule->activateSelectionFilters();
305 connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
306 myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
307 connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
308 myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
310 updateCommandStatus();
312 // TODO: get default selection mode
314 // activate visualized objects in the viewer
315 activateObjectsSelection(displayer()->displayedObjects());
316 myOperationMgr->activate();
319 void XGUI_Workshop::deactivateModule()
321 myModule->deactivateSelectionFilters();
323 // remove internal displayer filter
324 displayer()->deactivateSelectionFilters();
326 disconnect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
327 myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
328 disconnect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
329 myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
331 XGUI_Displayer* aDisplayer = displayer();
332 QObjectPtrList aDisplayed = aDisplayer->displayedObjects();
333 aDisplayer->deactivateObjects(aDisplayed, true);
334 Handle(AIS_InteractiveContext) aContext = viewer()->AISContext();
335 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(aDisplayer->getTrihedron());
336 /// deactivate trihedron in selection modes
337 TColStd_ListOfInteger aTColModes;
338 aContext->ActivatedModes(aTrihedron, aTColModes);
339 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
340 for (; itr.More(); itr.Next() ) {
341 Standard_Integer aMode = itr.Value();
342 aContext->Deactivate(aTrihedron, aMode);
344 /// Trihedron problem: objects stayed in the viewer, should be removed manually
345 /// otherwise in SALOME happens crash by HideAll in the viewer
346 aContext->Remove(aTrihedron->Position(), true);
347 aContext->Remove(aTrihedron->Axis(), true);
348 aContext->Remove(aTrihedron->XAxis(), true);
349 aContext->Remove(aTrihedron->YAxis(), true);
352 myOperationMgr->deactivate();
355 //******************************************************
356 void XGUI_Workshop::initMenu()
358 myContextMenuMgr->createActions();
361 // Create only Undo, Redo commands
362 QAction* aAction = salomeConnector()->addDesktopCommand("UNDO_CMD", tr("Undo"),
363 tr("Undo last command"),
364 QIcon(":pictures/undo.png"),
365 QKeySequence::Undo, false,
367 QString aToolBarTitle = tr( "INF_DESK_TOOLBAR_STANDARD" );
368 salomeConnector()->addActionInToolbar( aAction,aToolBarTitle );
370 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onUndo()));
371 addHistoryMenu(aAction, SIGNAL(updateUndoHistory(const QList<ActionInfo>&)), SLOT(onUndo(int)));
373 aAction = salomeConnector()->addDesktopCommand("REDO_CMD", tr("Redo"), tr("Redo last command"),
374 QIcon(":pictures/redo.png"), QKeySequence::Redo,
375 false, "MEN_DESK_EDIT");
376 salomeConnector()->addActionInToolbar( aAction, aToolBarTitle );
378 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo()));
379 addHistoryMenu(aAction, SIGNAL(updateRedoHistory(const QList<ActionInfo>&)), SLOT(onRedo(int)));
381 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
382 //aAction = salomeConnector()->addDesktopCommand("REBUILD_CMD", tr("Rebuild"),
383 // tr("Rebuild data objects"),
384 // QIcon(":pictures/rebuild.png"), QKeySequence(),
385 // false, "MEN_DESK_EDIT");
386 //salomeConnector()->addActionInToolbar( aAction, aToolBarTitle );
388 //connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRebuild()));
389 //salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
391 aAction = salomeConnector()->addDesktopCommand("SAVEAS_CMD", tr("Export native..."),
392 tr("Export the current document into a native file"),
393 QIcon(), QKeySequence(),
394 false, "MEN_DESK_FILE");
395 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onSaveAs()));
397 aAction = salomeConnector()->addDesktopCommand("OPEN_CMD", tr("Import native..."),
398 tr("Import native file"),
399 QIcon(), QKeySequence(),
400 false, "MEN_DESK_FILE");
401 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onOpen()));
402 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_FILE");
405 // File commands group
406 AppElements_MenuGroupPanel* aGroup = myMainWindow->menuObject()->generalPage();
408 AppElements_Command* aCommand;
410 aCommand = aGroup->addFeature("SAVE_CMD", tr("Save"), tr("Save the document"),
411 QIcon(":pictures/save.png"), QKeySequence::Save);
412 aCommand->connectTo(this, SLOT(onSave()));
413 //aCommand->disable();
415 aCommand = aGroup->addFeature("SAVEAS_CMD", tr("Save as..."), tr("Save the document into a file"),
416 QIcon(":pictures/save.png"), QKeySequence());
417 aCommand->connectTo(this, SLOT(onSaveAs()));
419 QString aUndoId = "UNDO_CMD";
420 aCommand = aGroup->addFeature(aUndoId, tr("Undo"), tr("Undo last command"),
421 QIcon(":pictures/undo.png"), QKeySequence::Undo);
422 aCommand->connectTo(this, SLOT(onUndo()));
423 AppElements_Button* aUndoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aUndoId));
424 addHistoryMenu(aUndoButton,
425 SIGNAL(updateUndoHistory(const QList<ActionInfo>&)),
428 QString aRedoId = "REDO_CMD";
429 aCommand = aGroup->addFeature(aRedoId, tr("Redo"), tr("Redo last command"),
430 QIcon(":pictures/redo.png"), QKeySequence::Redo);
431 aCommand->connectTo(this, SLOT(onRedo()));
432 AppElements_Button* aRedoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aRedoId));
433 addHistoryMenu(aRedoButton,
434 SIGNAL(updateRedoHistory(const QList<ActionInfo>&)),
437 //aCommand = aGroup->addFeature("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
438 // QIcon(":pictures/rebuild.png"), QKeySequence());
439 //aCommand->connectTo(this, SLOT(onRebuild()));
441 //aCommand->disable();
443 aCommand = aGroup->addFeature("OPEN_CMD", tr("Open..."), tr("Open a new document"),
444 QIcon(":pictures/open.png"), QKeySequence::Open);
445 aCommand->connectTo(this, SLOT(onOpen()));
447 aCommand = aGroup->addFeature("PREF_CMD", tr("Preferences"), tr("Edit preferences"),
448 QIcon(":pictures/preferences.png"), QKeySequence::Preferences);
449 aCommand->connectTo(this, SLOT(onPreferences()));
451 aCommand = aGroup->addFeature("EXIT_CMD", tr("Exit"), tr("Exit application"),
452 QIcon(":pictures/close.png"), QKeySequence::Close);
453 aCommand->connectTo(this, SLOT(onExit()));
458 AppElements_Workbench* XGUI_Workshop::addWorkbench(const QString& theName)
460 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
461 return aMenuBar->addWorkbench(theName);
465 //******************************************************
466 QMainWindow* XGUI_Workshop::desktop() const
469 return salomeConnector()->desktop();
475 //******************************************************
476 void XGUI_Workshop::onStartWaiting()
478 if (Events_LongOp::isPerformed()) {
479 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
483 //******************************************************
484 void XGUI_Workshop::onAcceptActionClicked()
486 QAction* anAction = dynamic_cast<QAction*>(sender());
487 XGUI_OperationMgr* anOperationMgr = operationMgr();
488 if (anOperationMgr) {
489 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
490 (anOperationMgr->currentOperation());
492 //if (errorMgr()->canProcessClick(anAction, aFOperation->feature()))
493 myOperationMgr->onCommitOperation();
498 //******************************************************
499 void XGUI_Workshop::onPreviewActionClicked()
501 ModuleBase_IPropertyPanel* aPanel = propertyPanel();
503 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
504 if (anActiveWidget && anActiveWidget->getValueState() == ModuleBase_ModelWidget::ModifiedInPP) {
505 anActiveWidget->storeValue();
508 std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
509 new Events_Message(Events_Loop::eventByName(EVENT_PREVIEW_REQUESTED)));
510 Events_Loop::loop()->send(aMsg);
513 //******************************************************
514 void XGUI_Workshop::deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer)
516 if (!myModule->canActivateSelection(theObject)) {
517 if (myDisplayer->isActive(theObject)) {
518 QObjectPtrList anObjects;
519 anObjects.append(theObject);
520 myDisplayer->deactivateObjects(anObjects, theUpdateViewer);
525 //******************************************************
526 bool XGUI_Workshop::isFeatureOfNested(const FeaturePtr& theFeature)
528 bool aHasNested = false;
529 std::string aFeatureKind = theFeature->getKind();
531 XGUI_SalomeConnector* aSalomeConnector = salomeConnector();
532 if (aSalomeConnector->isFeatureOfNested(actionsMgr()->action(aFeatureKind.c_str())))
535 AppElements_MainMenu* aMenuBar = mainWindow()->menuObject();
536 AppElements_Command* aCommand = aMenuBar->feature(aFeatureKind.c_str());
537 if (aCommand && aCommand->button()->additionalButtonWidget())
543 void XGUI_Workshop::fillPropertyPanel(ModuleBase_Operation* theOperation)
545 ModuleBase_OperationFeature* aFOperation =
546 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
551 myPropertyPanel->cleanContent();
553 QList<ModuleBase_ModelWidget*> aWidgets;
554 if (!module()->createWidgets(theOperation, aWidgets)) {
555 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
556 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), myModuleConnector);
557 aFactory.createWidget(myPropertyPanel->contentWidget());
558 aWidgets = aFactory.getModelWidgets();
561 // check compatibility of feature and widgets
562 FeaturePtr aFeature = aFOperation->feature();
563 std::string aFeatureKind = aFeature->getKind();
564 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
565 if (!aWidget->attributeID().empty() && !aFeature->attribute(aWidget->attributeID()).get()) {
566 std::string anErrorMsg = "The feature '%1' has no attribute '%2' used by widget '%3'.";
567 Events_InfoMessage("XGUI_Workshop", anErrorMsg)
568 .arg(aFeatureKind).arg(aWidget->attributeID())
569 .arg(aWidget->metaObject()->className()).send();
570 myPropertyPanel->cleanContent();
574 // for performance purpose, flush should be done after all controls are filled
575 bool isUpdateFlushed = false;
576 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
577 bool isStoreValue = !aFOperation->isEditOperation() &&
578 !aWidget->getDefaultValue().empty() &&
579 !aWidget->isComputedDefault();
580 aWidget->setFeature(aFeature, isStoreValue, isUpdateFlushed);
582 aWidget->restoreValue();
583 aWidget->enableFocusProcessing();
585 ModuleBase_Tools::flushUpdated(aFeature);
587 // update visible state of Preview button
589 bool anIsAutoPreview =
590 mySalomeConnector->featureInfo(aFeatureKind.c_str())->isAutoPreview();
592 AppElements_MainMenu* aMenuBar = mainWindow()->menuObject();
593 AppElements_Command* aCommand = aMenuBar->feature(aFeatureKind.c_str());
594 bool anIsAutoPreview = aCommand && aCommand->featureMessage()->isAutoPreview();
596 if (!anIsAutoPreview) {
597 myPropertyPanel->findButton(PROP_PANEL_PREVIEW)->setVisible(true);
598 // send signal about preview should not be computed automatically, click on preview
599 // button should initiate it
600 std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
601 new Events_Message(Events_Loop::eventByName(EVENT_PREVIEW_BLOCKED)));
602 Events_Loop::loop()->send(aMsg);
604 myPropertyPanel->setModelWidgets(aWidgets);
605 aFOperation->setPropertyPanel(myPropertyPanel);
607 myModule->propertyPanelDefined(theOperation);
609 #ifndef DEBUG_FEATURE_NAME
610 myPropertyPanel->setWindowTitle(theOperation->getDescription()->description());
612 std::string aFeatureName = aFeature->name();
613 myPropertyPanel->setWindowTitle(QString("%1: %2")
614 .arg(theOperation->getDescription()->description())
615 .arg(aFeatureName.c_str()));
618 myErrorMgr->setPropertyPanel(myPropertyPanel);
621 void XGUI_Workshop::connectToPropertyPanel(const bool isToConnect)
623 XGUI_PropertyPanel* aPropertyPanel = propertyPanel();
624 if (aPropertyPanel) {
625 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
626 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
627 myModule->connectToPropertyPanel(aWidget, isToConnect);
629 connect(aWidget, SIGNAL(valueStateChanged(int)), this, SLOT(onWidgetStateChanged(int)));
630 connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
631 connect(aWidget, SIGNAL(objectUpdated()), this, SLOT(onWidgetObjectUpdated()));
634 disconnect(aWidget, SIGNAL(valueStateChanged(int)), this, SLOT(onWidgetStateChanged(int)));
635 disconnect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
636 disconnect(aWidget, SIGNAL(objectUpdated()), this, SLOT(onWidgetObjectUpdated()));
642 //******************************************************
643 void XGUI_Workshop::onOperationResumed(ModuleBase_Operation* theOperation)
645 setGrantedFeatures(theOperation);
647 if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
648 fillPropertyPanel(theOperation);
649 connectToPropertyPanel(true);
651 updateCommandStatus();
653 myModule->operationResumed(theOperation);
657 //******************************************************
658 void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
660 updateCommandStatus();
662 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
667 ModuleBase_ISelection* aSel = mySelector->selection();
668 QObjectPtrList aObj = aSel->selectedPresentations();
669 //!< No need for property panel
671 myPropertyPanel->cleanContent();
673 connectToPropertyPanel(false);
674 myModule->operationStopped(aFOperation);
676 // the deactivated objects of the current operation should be activated back.
677 // They were deactivated on operation start or an object redisplay
678 QObjectPtrList anObjects;
679 FeaturePtr aFeature = aFOperation->feature();
680 if (aFeature.get()) { // feature may be not created (plugin load fail)
681 if (myDisplayer->isVisible(aFeature) && !myDisplayer->isActive(aFeature))
682 anObjects.append(aFeature);
683 std::list<ResultPtr> aResults;
684 ModelAPI_Tools::allResults(aFeature, aResults);
685 std::list<ResultPtr>::const_iterator aIt;
686 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
687 ResultPtr anObject = *aIt;
688 if (myDisplayer->isVisible(anObject) && !myDisplayer->isActive(anObject)) {
689 anObjects.append(anObject);
693 activateObjectsSelection(anObjects);
697 void XGUI_Workshop::onOperationCommitted(ModuleBase_Operation* theOperation)
699 myModule->operationCommitted(theOperation);
702 void XGUI_Workshop::onOperationAborted(ModuleBase_Operation* theOperation)
704 myModule->operationAborted(theOperation);
707 void XGUI_Workshop::setGrantedFeatures(ModuleBase_Operation* theOperation)
709 ModuleBase_OperationFeature* aFOperation =
710 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
714 QStringList aGrantedIds;
715 if (isSalomeMode()) {
716 const std::shared_ptr<Config_FeatureMessage>& anInfo =
717 mySalomeConnector->featureInfo(theOperation->id());
719 aGrantedIds = QString::fromStdString(anInfo->nestedFeatures())
720 .split(" ", QString::SkipEmptyParts);
723 aGrantedIds = myActionsMgr->nestedCommands(theOperation->id());
725 ModuleBase_IModule* aModule = module();
727 aModule->grantedOperationIds(theOperation, aGrantedIds);
729 aFOperation->setGrantedOperationIds(aGrantedIds);
732 //******************************************************
733 void XGUI_Workshop::saveDocument(const QString& theName, std::list<std::string>& theFileNames)
735 QApplication::restoreOverrideCursor();
736 SessionPtr aMgr = ModelAPI_Session::get();
738 std::list<DocumentPtr> aDocList = aMgr->allOpenedDocuments();
739 std::list<DocumentPtr>::const_iterator aIt;
740 for (aIt = aDocList.cbegin(); aIt != aDocList.cend(); aIt++) {
741 std::list<bool> aState = myObjectBrowser->getStateForDoc(*aIt);
742 (*aIt)->storeNodesState(aState);
745 aMgr->save(theName.toLatin1().constData(), theFileNames);
747 QApplication::restoreOverrideCursor();
750 //******************************************************
751 bool XGUI_Workshop::abortAllOperations()
753 return myOperationMgr->abortAllOperations();
756 //******************************************************
757 void XGUI_Workshop::operationStarted(ModuleBase_Operation* theOperation)
759 setGrantedFeatures(theOperation);
760 if (!theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
761 updateCommandStatus();
764 myModule->operationStarted(theOperation);
768 //******************************************************
769 void XGUI_Workshop::onOpen()
771 if(!abortAllOperations())
773 //save current file before close if modified
774 SessionPtr aSession = ModelAPI_Session::get();
775 if (aSession->isModified()) {
776 //TODO(sbh): re-launch the app?
777 int anAnswer = QMessageBox::question(
778 desktop(), tr("Save current file"),
779 tr("The document is modified, save before opening another?"),
780 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
781 if (anAnswer == QMessageBox::Save) {
783 } else if (anAnswer == QMessageBox::Cancel) {
789 //show file dialog, check if readable and open
790 QString aDirectory = QFileDialog::getExistingDirectory(desktop(), tr("Select directory"));
791 openDirectory(aDirectory);
794 //******************************************************
795 void XGUI_Workshop::openDirectory(const QString& theDirectory)
797 myCurrentDir = theDirectory;
798 if (myCurrentDir.isEmpty())
801 QFileInfo aFileInfo(myCurrentDir);
802 if (!aFileInfo.exists() || !aFileInfo.isReadable()) {
803 QMessageBox::critical(desktop(), tr("Warning"), tr("Unable to open the file."));
808 QApplication::setOverrideCursor(Qt::WaitCursor);
809 module()->closeDocument();
810 SessionPtr aSession = ModelAPI_Session::get();
811 aSession->closeAll();
812 aSession->load(myCurrentDir.toLatin1().constData());
813 myObjectBrowser->rebuildDataTree();
815 // Open first level of data tree
816 DocumentPtr aRootDoc = aSession->moduleDocument();
817 std::list<bool> aStates;
818 aRootDoc->restoreNodesState(aStates);
819 myObjectBrowser->setStateForDoc(aRootDoc, aStates);
821 updateCommandStatus();
823 myMainWindow->setCurrentDir(myCurrentDir, true);
825 QApplication::restoreOverrideCursor();
828 //******************************************************
829 void XGUI_Workshop::onNew()
831 QApplication::setOverrideCursor(Qt::WaitCursor);
832 if (objectBrowser() == 0) {
834 mySelector->connectViewers();
836 myViewerProxy->connectToViewer();
839 myMainWindow->showPythonConsole();
840 QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
841 aWnd->showMaximized();
842 updateCommandStatus();
844 myContextMenuMgr->connectViewer();
845 QApplication::restoreOverrideCursor();
849 //******************************************************
850 void XGUI_Workshop::onExit()
852 SessionPtr aMgr = ModelAPI_Session::get();
853 if (aMgr->isModified()) {
854 int anAnswer = QMessageBox::question(
855 myMainWindow, tr("Save current file"), tr("The document is modified, save before exit?"),
856 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
857 if (anAnswer == QMessageBox::Save) {
858 bool saved = onSave();
862 } else if (anAnswer == QMessageBox::Cancel) {
869 //******************************************************
870 void XGUI_Workshop::onPreferences()
872 ModuleBase_Prefs aModif;
873 ModuleBase_Preferences::editPreferences(aModif);
874 if (aModif.size() > 0) {
876 foreach (ModuleBase_Pref aPref, aModif)
878 aSection = aPref.first;
879 if (aSection == ModuleBase_Preferences::VIEWER_SECTION) {
880 myMainWindow->viewer()->updateFromResources();
881 } else if (aSection == ModuleBase_Preferences::MENU_SECTION) {
882 myMainWindow->menuObject()->updateFromResources();
885 displayer()->redisplayObjects();
890 //******************************************************
891 void XGUI_Workshop::onTrihedronVisibilityChanged(bool theState)
893 XGUI_Displayer* aDisplayer = displayer();
895 aDisplayer->displayTrihedron(theState);
898 //******************************************************
899 bool XGUI_Workshop::onSave()
901 if(!abortAllOperations())
903 if (myCurrentDir.isEmpty()) {
906 std::list<std::string> aFiles;
907 saveDocument(myCurrentDir, aFiles);
908 updateCommandStatus();
910 myMainWindow->setModifiedState(false);
915 //******************************************************
916 bool XGUI_Workshop::onSaveAs()
918 if(!abortAllOperations())
920 QFileDialog dialog(desktop());
921 dialog.setWindowTitle(tr("Select directory to save files..."));
922 dialog.setFileMode(QFileDialog::Directory);
923 dialog.setFilter(QDir::AllDirs);
924 dialog.setOptions(QFileDialog::HideNameFilterDetails | QFileDialog::ShowDirsOnly);
925 dialog.setViewMode(QFileDialog::Detail);
927 if (!dialog.exec()) {
931 QString aTempDir = dialog.selectedFiles().first();
933 if (aDir.exists() && !aDir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries).isEmpty()) {
934 int answer = QMessageBox::question(
936 // Title of the dialog which asks user if he wants to save study
937 // in existing non-empty folder
939 tr("The directory already contains some files, save anyway?"),
940 QMessageBox::Save | QMessageBox::Cancel);
941 if (answer == QMessageBox::Cancel) {
945 myCurrentDir = aTempDir;
947 myMainWindow->setCurrentDir(myCurrentDir, false);
948 myMainWindow->setModifiedState(false);
953 //******************************************************
954 void XGUI_Workshop::onUndo(int theTimes)
956 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
957 SessionPtr aMgr = ModelAPI_Session::get();
958 std::list<std::string> aUndoList = aMgr->undoList();
959 if (aMgr->isOperation()) {
960 /// this is important for nested operations
961 /// when sketch operation is active, this condition is false and
962 /// the sketch operation is not aborted
963 operationMgr()->onAbortOperation();
965 std::list<std::string>::const_iterator aIt = aUndoList.cbegin();
966 for (int i = 0; (i < theTimes) && (aIt != aUndoList.cend()); ++i, ++aIt) {
968 if (QString((*aIt).c_str()) == MOVE_TO_END_COMMAND)
969 myObjectBrowser->rebuildDataTree();
972 operationMgr()->updateApplyOfOperations();
973 updateCommandStatus();
976 //******************************************************
977 void XGUI_Workshop::onRedo(int theTimes)
979 // the viewer update should be blocked in order to avoid the features blinking. For the created
980 // feature a results are created, the flush of the created signal caused the viewer redisplay for
981 // each created result. After a redisplay signal is flushed. So, the viewer update is blocked
982 // until redo of all possible objects happens
983 bool isUpdateEnabled = myDisplayer->enableUpdateViewer(false);
985 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
986 SessionPtr aMgr = ModelAPI_Session::get();
987 std::list<std::string> aRedoList = aMgr->redoList();
988 if (aMgr->isOperation()) {
989 /// this is important for nested operations
990 /// when sketch operation is active, this condition is false and
991 /// the sketch operation is not aborted
992 operationMgr()->onAbortOperation();
994 std::list<std::string>::const_iterator aIt = aRedoList.cbegin();
995 for (int i = 0; (i < theTimes) && (aIt != aRedoList.cend()); ++i, ++aIt) {
997 if (QString((*aIt).c_str()) == MOVE_TO_END_COMMAND)
998 myObjectBrowser->rebuildDataTree();
1000 operationMgr()->updateApplyOfOperations();
1001 updateCommandStatus();
1003 // unblock the viewer update functionality and make update on purpose
1004 myDisplayer->enableUpdateViewer(isUpdateEnabled);
1005 myDisplayer->updateViewer();
1008 //******************************************************
1009 //void XGUI_Workshop::onRebuild()
1011 // SessionPtr aMgr = ModelAPI_Session::get();
1012 // bool aWasOperation = aMgr->isOperation(); // keep this value
1013 // if (!aWasOperation) {
1014 // aMgr->startOperation("Rebuild");
1016 // static const Events_ID aRebuildEvent = Events_Loop::loop()->eventByName("Rebuild");
1017 // Events_Loop::loop()->send(std::shared_ptr<Events_Message>(
1018 // new Events_Message(aRebuildEvent, this)));
1019 // if (!aWasOperation) {
1020 // aMgr->finishOperation();
1022 // updateCommandStatus();
1025 //******************************************************
1026 void XGUI_Workshop::onWidgetStateChanged(int thePreviousState)
1028 ModuleBase_ModelWidget* anActiveWidget = 0;
1029 ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
1031 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1033 anActiveWidget = aPanel->activeWidget();
1036 operationMgr()->onValidateOperation();
1038 myModule->widgetStateChanged(thePreviousState);
1041 //******************************************************
1042 void XGUI_Workshop::onValuesChanged()
1044 ModuleBase_ModelWidget* aSenderWidget = (ModuleBase_ModelWidget*)(sender());
1045 if (!aSenderWidget || aSenderWidget->canAcceptFocus())
1048 ModuleBase_ModelWidget* anActiveWidget = 0;
1049 ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
1051 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1053 anActiveWidget = aPanel->activeWidget();
1055 if (anActiveWidget) {
1056 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1058 if (aWidgetValidated)
1059 aWidgetValidated->clearValidatedCash();
1063 void XGUI_Workshop::onWidgetObjectUpdated()
1065 operationMgr()->onValidateOperation();
1068 ModuleBase_IModule* XGUI_Workshop::loadModule(const QString& theModule)
1070 QString libName = QString::fromStdString(library(theModule.toStdString()));
1071 if (libName.isEmpty()) {
1072 qWarning(qPrintable(tr("Information about module \"%1\" doesn't exist.").arg(theModule)));
1077 CREATE_FUNC crtInst = 0;
1080 HINSTANCE modLib = ::LoadLibrary((LPTSTR) qPrintable(libName));
1084 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
1085 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
1086 QString aMsg((char*) &lpMsgBuf);
1087 err = QString("Failed to load %1. %2").arg(libName).arg(aMsg);
1088 ::LocalFree(lpMsgBuf);
1090 crtInst = (CREATE_FUNC) ::GetProcAddress(modLib, CREATE_MODULE);
1094 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
1095 | FORMAT_MESSAGE_IGNORE_INSERTS,
1096 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
1097 QString aMsg((char*) &lpMsgBuf);
1098 err = QString("Failed to find %1 function. %2").arg( CREATE_MODULE).arg(aMsg);
1099 ::LocalFree(lpMsgBuf);
1103 void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY | RTLD_GLOBAL );
1105 err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
1107 crtInst = (CREATE_FUNC)dlsym( modLib, CREATE_MODULE );
1109 err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() );
1114 ModuleBase_IModule* aModule = crtInst ? crtInst(myModuleConnector) : 0;
1116 if (!err.isEmpty()) {
1118 Events_InfoMessage("XGUI_Workshop", err.toStdString()).send();
1120 qWarning(qPrintable(err));
1126 //******************************************************
1127 bool XGUI_Workshop::createModule()
1129 Config_ModuleReader aModuleReader;
1130 QString moduleName = QString::fromStdString(aModuleReader.getModuleName());
1131 myModule = loadModule(moduleName);
1135 //connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
1136 // myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
1137 //connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
1138 // myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
1140 myModule->createFeatures();
1142 salomeConnector()->createFeatureActions();
1144 //myActionsMgr->update();
1148 //******************************************************
1149 void XGUI_Workshop::updateCommandStatus()
1151 QList<QAction*> aCommands;
1153 aCommands = salomeConnector()->commandList();
1155 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
1156 foreach (AppElements_Command* aCmd, aMenuBar->features())
1157 aCommands.append(aCmd);
1159 SessionPtr aMgr = ModelAPI_Session::get();
1160 if (aMgr->hasModuleDocument()) {
1161 foreach(QAction* aCmd, aCommands) {
1162 QString aId = aCmd->data().toString();
1163 if (aId == "UNDO_CMD")
1164 aCmd->setEnabled(myModule->canUndo());
1165 else if (aId == "REDO_CMD")
1166 aCmd->setEnabled(myModule->canRedo());
1168 // Enable all commands
1169 aCmd->setEnabled(true);
1173 foreach(QAction* aCmd, aCommands) {
1174 QString aId = aCmd->data().toString();
1175 if (aId == "NEW_CMD")
1176 aCmd->setEnabled(true);
1177 else if (aId == "EXIT_CMD")
1178 aCmd->setEnabled(true);
1180 aCmd->setEnabled(false);
1183 myActionsMgr->updateCommandsStatus();
1184 emit commandStatusUpdated();
1187 void XGUI_Workshop::updateHistory()
1189 std::list<std::string> aUndoList = ModelAPI_Session::get()->undoList();
1190 QList<ActionInfo> aUndoRes = processHistoryList(aUndoList);
1191 emit updateUndoHistory(aUndoRes);
1193 std::list<std::string> aRedoList = ModelAPI_Session::get()->redoList();
1194 QList<ActionInfo> aRedoRes = processHistoryList(aRedoList);
1195 emit updateRedoHistory(aRedoRes);
1198 //******************************************************
1199 QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
1201 QDockWidget* aObjDock = new QDockWidget(theParent);
1202 aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea |
1203 Qt::RightDockWidgetArea |
1204 Qt::BottomDockWidgetArea);
1205 aObjDock->setWindowTitle(tr("Object browser"));
1206 aObjDock->setStyleSheet(
1207 "::title { position: relative; padding-left: 5px; text-align: left center }");
1208 myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock);
1209 myObjectBrowser->setXMLReader(myDataModelXMLReader);
1210 myModule->customizeObjectBrowser(myObjectBrowser);
1211 aObjDock->setWidget(myObjectBrowser);
1213 myContextMenuMgr->connectObjectBrowser();
1217 //******************************************************
1219 * Creates dock widgets, places them in corresponding area
1220 * and tabifies if necessary.
1222 void XGUI_Workshop::createDockWidgets()
1224 QMainWindow* aDesktop = desktop();
1225 QDockWidget* aObjDock = createObjectBrowser(aDesktop);
1226 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
1227 myPropertyPanel = new XGUI_PropertyPanel(aDesktop, myOperationMgr);
1228 myPropertyPanel->setupActions(myActionsMgr);
1229 myPropertyPanel->setAllowedAreas(Qt::LeftDockWidgetArea |
1230 Qt::RightDockWidgetArea |
1231 Qt::BottomDockWidgetArea);
1232 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel);
1233 hidePropertyPanel(); ///<! Invisible by default
1234 hideObjectBrowser();
1235 aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
1236 myPropertyPanel->installEventFilter(myOperationMgr);
1238 QAction* aOkAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept);
1239 connect(aOkAct, SIGNAL(triggered()), this, SLOT(onAcceptActionClicked()));
1241 QAction* aCancelAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Abort);
1242 connect(aCancelAct, SIGNAL(triggered()), myOperationMgr, SLOT(onAbortOperation()));
1244 QAction* aPreviewAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Preview);
1245 connect(aPreviewAct, SIGNAL(triggered()), this, SLOT(onPreviewActionClicked()));
1247 connect(myPropertyPanel, SIGNAL(keyReleased(QObject*, QKeyEvent*)),
1248 myOperationMgr, SLOT(onKeyReleased(QObject*, QKeyEvent*)));
1249 connect(myPropertyPanel, SIGNAL(enterClicked(QObject*)),
1250 myOperationMgr, SLOT(onProcessEnter(QObject*)));
1253 //******************************************************
1254 void XGUI_Workshop::showPropertyPanel()
1256 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1257 ///<! Restore ability to close panel from the window's menu
1258 aViewAct->setEnabled(true);
1259 myPropertyPanel->show();
1260 myPropertyPanel->raise();
1262 // The next code is necessary to made the property panel the active window
1263 // in order to operation manager could process key events of the panel.
1264 // otherwise they are ignored. It happens only if the same(activateWindow) is
1265 // not happened by property panel activation(e.g. resume operation of Sketch)
1266 ModuleBase_Tools::activateWindow(myPropertyPanel, "XGUI_Workshop::showPropertyPanel()");
1267 ModuleBase_Tools::setFocus(myPropertyPanel, "XGUI_Workshop::showPropertyPanel()");
1270 //******************************************************
1271 void XGUI_Workshop::hidePropertyPanel()
1273 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1274 ///<! Do not allow to show empty property panel
1275 aViewAct->setEnabled(false);
1276 myPropertyPanel->hide();
1278 // the property panel is active window of the desktop, when it is
1279 // hidden, it is undefined which window becomes active. By this reason
1280 // it is defined to perform the desktop as the active window.
1281 // in SALOME mode, workstack made the PyConsole the active window,
1282 // set the focus on it. As a result, shortcuts of the application, like
1283 // are processed by this console. For example Undo actions.
1284 // It is possible that this code is to be moved to SHAPER package
1285 QMainWindow* aDesktop = desktop();
1286 ModuleBase_Tools::activateWindow(aDesktop, "XGUI_Workshop::hidePropertyPanel()");
1287 ModuleBase_Tools::setFocus(aDesktop, "XGUI_Workshop::showPropertyPanel()");
1290 //******************************************************
1291 void XGUI_Workshop::showObjectBrowser()
1293 if (!isSalomeMode())
1294 myObjectBrowser->parentWidget()->show();
1297 //******************************************************
1298 void XGUI_Workshop::hideObjectBrowser()
1300 if (!isSalomeMode())
1301 myObjectBrowser->parentWidget()->hide();
1304 //******************************************************
1305 void XGUI_Workshop::salomeViewerSelectionChanged()
1307 emit salomeViewerSelection();
1310 //**************************************************************
1311 ModuleBase_IViewer* XGUI_Workshop::salomeViewer() const
1313 return mySalomeConnector->viewer();
1316 //**************************************************************
1317 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
1319 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1320 if (theId == "DELETE_CMD")
1322 else if (theId == "CLEAN_HISTORY_CMD")
1324 else if (theId == "MOVE_CMD")
1326 else if (theId == "COLOR_CMD")
1327 changeColor(aObjects);
1328 else if (theId == "DEFLECTION_CMD")
1329 changeDeflection(aObjects);
1330 else if (theId == "SHOW_CMD") {
1331 showObjects(aObjects, true);
1332 mySelector->updateSelectionBy(ModuleBase_ISelection::Browser);
1333 updateCommandStatus();
1335 else if (theId == "HIDE_CMD") {
1336 showObjects(aObjects, false);
1337 updateCommandStatus();
1339 else if (theId == "SHOW_ONLY_CMD") {
1340 showOnlyObjects(aObjects);
1341 mySelector->updateSelectionBy(ModuleBase_ISelection::Browser);
1342 updateCommandStatus();
1344 else if (theId == "SHADING_CMD")
1345 setDisplayMode(aObjects, XGUI_Displayer::Shading);
1346 else if (theId == "WIREFRAME_CMD")
1347 setDisplayMode(aObjects, XGUI_Displayer::Wireframe);
1348 else if (theId == "HIDEALL_CMD") {
1349 QObjectPtrList aList = myDisplayer->displayedObjects();
1350 foreach (ObjectPtr aObj, aList) {
1351 if (module()->canEraseObject(aObj))
1352 aObj->setDisplayed(false);
1354 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1355 updateCommandStatus();
1356 } else if (theId == "SELECT_VERTEX_CMD") {
1357 setViewerSelectionMode(TopAbs_VERTEX);
1358 } else if (theId == "SELECT_EDGE_CMD") {
1359 setViewerSelectionMode(TopAbs_EDGE);
1360 } else if (theId == "SELECT_FACE_CMD") {
1361 setViewerSelectionMode(TopAbs_FACE);
1362 } else if (theId == "SELECT_RESULT_CMD") {
1363 //setViewerSelectionMode(-1);
1364 //IMP: an attempt to use result selection with other selection modes
1365 setViewerSelectionMode(ModuleBase_ResultPrs::Sel_Result);
1366 setViewerSelectionMode(TopAbs_COMPSOLID);
1367 } else if (theId == "SHOW_RESULTS_CMD") {
1368 highlightResults(aObjects);
1369 } else if (theId == "SHOW_FEATURE_CMD") {
1370 highlightFeature(aObjects);
1373 else if (theId == "VINSPECTOR_VIEW") {
1374 displayer()->setVInspectorVisible(true);
1378 else if (theId == "DFBROWSER_VIEW") {
1379 if (DFBrowser_FirstCall) {
1380 Handle(CDF_Application) anApplication = CDF_Session::CurrentSession()->CurrentApplication();
1381 DFBrowserAPI_Communicator* aCommunicator =
1382 DFBrowserAPI_Communicator::loadPluginLibrary("TKDFBrowser.dll");
1383 if (aCommunicator) {
1384 aCommunicator->setApplication(anApplication);
1385 Handle(AIS_InteractiveContext) aContext = viewer()->AISContext();
1387 aCommunicator->setContext(aContext);
1389 DFBrowser_FirstCall = false;
1395 //**************************************************************
1396 void XGUI_Workshop::setViewerSelectionMode(int theMode)
1399 myViewerSelMode.clear();
1401 if (myViewerSelMode.contains(theMode))
1402 myViewerSelMode.removeAll(theMode);
1404 myViewerSelMode.append(theMode);
1406 activateObjectsSelection(myDisplayer->displayedObjects());
1409 //**************************************************************
1410 void XGUI_Workshop::activateObjectsSelection(const QObjectPtrList& theList)
1413 module()->activeSelectionModes(aModes);
1414 if (aModes.isEmpty() && (myViewerSelMode.length() > 0))
1415 aModes.append(myViewerSelMode);
1416 myDisplayer->activateObjects(aModes, theList);
1419 //**************************************************************
1420 void XGUI_Workshop::deleteObjects()
1422 ModuleBase_IModule* aModule = module();
1423 // allow the module to delete objects, do nothing if it has succeed
1424 if (aModule->deleteObjects()) {
1425 updateCommandStatus();
1429 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1430 if (!abortAllOperations())
1433 bool hasResult = false;
1434 bool hasFeature = false;
1435 bool hasParameter = false;
1436 bool hasCompositeOwner = false;
1437 ModuleBase_Tools::checkObjects(anObjects, hasResult, hasFeature, hasParameter, hasCompositeOwner);
1438 if (!(hasFeature || hasParameter))
1442 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1443 std::set<FeaturePtr> aFeatures;
1444 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1445 ModelAPI_Tools::findAllReferences(aFeatures, aReferences);
1448 QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text() + " %1";
1449 aDescription = aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
1450 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, module());
1452 operationMgr()->startOperation(anOpAction);
1454 std::set<FeaturePtr> aFeatureRefsToDelete;
1455 if (ModuleBase_Tools::askToDelete(aFeatures, aReferences, desktop(), aFeatureRefsToDelete)) {
1456 // WORKAROUND, should be done before each object remove, if it presents in XGUI_DataModel tree
1457 // It is necessary to clear selection in order to avoid selection changed event during
1458 // deletion and negative consequences connected with processing of already deleted items
1459 mySelector->clearSelection();
1461 if (!aFeatureRefsToDelete.empty())
1462 aFeatures.insert(aFeatureRefsToDelete.begin(), aFeatureRefsToDelete.end());
1463 aDone = ModelAPI_Tools::removeFeatures(aFeatures, false);
1466 operationMgr()->commitOperation();
1468 operationMgr()->abortOperation(operationMgr()->currentOperation());
1471 //**************************************************************
1472 void addRefsToFeature(const FeaturePtr& theFeature,
1473 const std::map<FeaturePtr, std::set<FeaturePtr> >& theMainList,
1474 std::set<FeaturePtr>& theReferences)
1476 //if (theReferences.find(theFeature) != theReferences.end())
1478 if (theMainList.find(theFeature) == theMainList.end())
1479 return; // this feature is not in the selection list, so exists without references to it
1480 std::set<FeaturePtr> aMainReferences = theMainList.at(theFeature);
1482 std::set<FeaturePtr>::const_iterator anIt = aMainReferences.begin(),
1483 aLast = aMainReferences.end();
1484 for (; anIt != aLast; anIt++) {
1485 FeaturePtr aRefFeature = *anIt;
1486 if (theReferences.find(aRefFeature) == theReferences.end())
1487 theReferences.insert(aRefFeature);
1488 addRefsToFeature(aRefFeature, theMainList, theReferences);
1492 //**************************************************************
1493 void XGUI_Workshop::cleanHistory()
1495 if (!abortAllOperations())
1498 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1499 std::set<FeaturePtr> aFeatures;
1500 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1502 #ifdef DEBUG_CLEAN_HISTORY
1504 std::set<FeaturePtr>::const_iterator aFIt;
1505 for (aFIt = aFeatures.begin(); aFIt != aFeatures.end(); ++aFIt) {
1506 FeaturePtr aFeature = ModelAPI_Feature::feature(*aFIt);
1507 anInfo.append(aFeature->name().c_str());
1509 QString anInfoStr = anInfo.join(";\t");
1510 qDebug(QString("cleanHistory for: [%1] - %2").
1511 arg(aFeatures.size()).arg(anInfoStr).toStdString().c_str());
1514 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1515 ModelAPI_Tools::findAllReferences(aFeatures, aReferences, true, false);
1516 // find for each object whether all reference values are in the map as key, that means that there
1517 // is no other reference in the model to this object, so it might be removed by cleaning history
1518 // sk_1(ext_1, vertex_1) + (sk_3, bool_1) - cann't be deleted, dependency to bool_1
1519 // ext_1(bool_1, sk_3) - cann't be deleted, dependency to bool_1
1521 // sk_2(ext_2) + (bool_1) - cann't be deleted, dependency to bool_1
1522 // ext_2(bool_1) - cann't be deleted, dependency to bool_1
1524 // Information: bool_1 is not selected
1525 std::set<FeaturePtr> anUnusedObjects;
1526 std::map<FeaturePtr, std::set<FeaturePtr> >::const_iterator aMainIt = aReferences.begin(),
1527 aMainLast = aReferences.end();
1528 for (; aMainIt != aMainLast; aMainIt++) {
1529 FeaturePtr aMainListFeature = aMainIt->first;
1530 std::set<FeaturePtr> aMainRefList = aMainIt->second;
1531 std::set<FeaturePtr>::const_iterator aRefIt = aMainRefList.begin(),
1532 aRefLast = aMainRefList.end();
1533 bool aFeatureOutOfTheList = false;
1534 for (; aRefIt != aRefLast && !aFeatureOutOfTheList; aRefIt++) {
1535 FeaturePtr aRefFeature = *aRefIt;
1536 aFeatureOutOfTheList = aReferences.find(aRefFeature) == aReferences.end();
1538 if (!aFeatureOutOfTheList)
1539 anUnusedObjects.insert(aMainListFeature);
1542 #ifdef DEBUG_CLEAN_HISTORY
1544 for (aFIt = anUnusedObjects.begin(); aFIt != anUnusedObjects.end(); ++aFIt) {
1545 FeaturePtr aFeature = *aFIt;
1546 anInfo.append(aFeature->name().c_str());
1548 qDebug(QString("unused objects: [%1] - %2").
1549 arg(anInfo.size()).arg(anInfo.join(";\t")).toStdString().c_str());
1552 // warn about the references remove, break the delete operation if the user chose it
1553 if (!anUnusedObjects.empty()) {
1555 foreach (const FeaturePtr& aFeature, anUnusedObjects) {
1556 aNames.append(aFeature->name().c_str());
1559 QString anUnusedNames = aNames.join(", ");
1561 QString anActionId = "CLEAN_HISTORY_CMD";
1562 QString aDescription = contextMenuMgr()->action(anActionId)->text();
1564 QMessageBox aMessageBox(desktop());
1565 aMessageBox.setWindowTitle(aDescription);
1566 aMessageBox.setIcon(QMessageBox::Warning);
1567 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
1568 aMessageBox.setDefaultButton(QMessageBox::No);
1570 const char* aKeyStr = "Unused features are the following: "
1571 "%1.\nThese features will be deleted.\nWould you like to continue?";
1572 QString aText = QString(tr(aKeyStr).arg(anUnusedNames));
1573 aMessageBox.setText(aText);
1574 if (aMessageBox.exec() == QMessageBox::No)
1577 // 1. start operation
1578 aDescription += "by deleting of " +
1579 aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
1580 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, module());
1581 operationMgr()->startOperation(anOpAction);
1583 // WORKAROUND, should be done before each object remove, if it presents in XGUI_DataModel tree
1584 // It is necessary to clear selection in order to avoid selection changed event during
1585 // deletion and negative consequences connected with processing of already deleted items
1586 mySelector->clearSelection();
1588 std::set<FeaturePtr> anIgnoredFeatures;
1589 if (ModelAPI_Tools::removeFeatures(anUnusedObjects, true)) {
1590 operationMgr()->commitOperation();
1593 operationMgr()->abortOperation(operationMgr()->currentOperation());
1597 QString anActionId = "CLEAN_HISTORY_CMD";
1598 QString aDescription = contextMenuMgr()->action(anActionId)->text();
1600 QMessageBox aMessageBox(desktop());
1601 aMessageBox.setWindowTitle(aDescription);
1602 aMessageBox.setIcon(QMessageBox::Warning);
1603 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
1604 aMessageBox.setDefaultButton(QMessageBox::No);
1607 aMessageBox.setStandardButtons(QMessageBox::Ok);
1608 aMessageBox.setDefaultButton(QMessageBox::Ok);
1610 aText = QString(tr("All features are relevant, there is nothing to be deleted"));
1611 aMessageBox.setText(aText);
1613 if (aMessageBox.exec() == QMessageBox::No)
1618 //**************************************************************
1619 void XGUI_Workshop::moveObjects()
1621 if (!abortAllOperations())
1624 SessionPtr aMgr = ModelAPI_Session::get();
1626 QString anActionId = "MOVE_CMD";
1627 QString aDescription = contextMenuMgr()->action(anActionId)->text();
1628 aMgr->startOperation(aDescription.toStdString());
1630 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1631 // It is necessary to clear selection in order to avoid selection changed event during
1632 // moving and negative consequences connected with processing of already moved items
1633 mySelector->clearSelection();
1634 // check whether the object can be moved. There should not be parts which are not loaded
1635 std::set<FeaturePtr> aFeatures;
1636 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1637 if (!XGUI_Tools::canRemoveOrRename(desktop(), aFeatures))
1640 DocumentPtr anActiveDocument = aMgr->activeDocument();
1641 FeaturePtr aCurrentFeature = anActiveDocument->currentFeature(true);
1642 std::set<FeaturePtr>::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
1643 for (; anIt != aLast; anIt++) {
1644 FeaturePtr aFeature = *anIt;
1645 if (!aFeature.get() || !myModule->canApplyAction(aFeature, anActionId))
1648 anActiveDocument->moveFeature(aFeature, aCurrentFeature);
1649 aCurrentFeature = anActiveDocument->currentFeature(true);
1651 aMgr->finishOperation();
1654 //**************************************************************
1655 bool XGUI_Workshop::deleteFeatures(const QObjectPtrList& theObjects)
1657 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1658 std::set<FeaturePtr> aFeatures;
1659 ModuleBase_Tools::convertToFeatures(theObjects, aFeatures);
1661 return ModelAPI_Tools::removeFeaturesAndReferences(aFeatures);
1664 bool hasResults(QObjectPtrList theObjects, const std::set<std::string>& theTypes)
1666 bool isFoundResultType = false;
1667 foreach(ObjectPtr anObj, theObjects)
1669 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
1670 if (aResult.get() == NULL)
1673 isFoundResultType = theTypes.find(aResult->groupName()) != theTypes.end();
1674 if (isFoundResultType)
1677 return isFoundResultType;
1680 //**************************************************************
1681 // Returns the list of all features for theDocument and all features of
1682 // all nested parts.
1683 std::list<FeaturePtr> allFeatures(const DocumentPtr& theDocument)
1685 std::list<FeaturePtr> aResultList;
1686 std::list<FeaturePtr> anAllFeatures = theDocument->allFeatures();
1687 foreach (const FeaturePtr& aFeature, anAllFeatures) {
1688 // The order of appending features of the part and the part itself is important
1690 // Append features from a part feature
1691 std::list<ResultPtr> aResults;
1692 ModelAPI_Tools::allResults(aFeature, aResults);
1693 foreach (const ResultPtr& aResult, aResults) {
1694 ResultPartPtr aResultPart =
1695 std::dynamic_pointer_cast<ModelAPI_ResultPart>(aResult);
1696 if (aResultPart.get() && aResultPart->partDoc().get()) {
1698 std::list<FeaturePtr> anAllFeatures = allFeatures(aResultPart->partDoc());
1699 aResultList.insert(aResultList.end(), anAllFeatures.begin(), anAllFeatures.end());
1703 aResultList.push_back(aFeature);
1708 //**************************************************************
1709 // Returns the list of features placed between theObject and the current feature
1710 // in the same document. Excludes theObject, includes the current feature.
1711 std::list<FeaturePtr> toCurrentFeatures(const ObjectPtr& theObject)
1713 std::list<FeaturePtr> aResult;
1714 DocumentPtr aDocument = theObject->document();
1715 std::list<FeaturePtr> anAllFeatures = allFeatures(aDocument);
1716 // find the object iterator
1717 std::list<FeaturePtr>::iterator aObjectIt =
1718 std::find(anAllFeatures.begin(), anAllFeatures.end(), theObject);
1719 if (aObjectIt == anAllFeatures.end())
1721 // find the current feature iterator
1722 std::list<FeaturePtr>::iterator aCurrentIt =
1723 std::find(anAllFeatures.begin(), anAllFeatures.end(), aDocument->currentFeature(true));
1724 if (aCurrentIt == anAllFeatures.end())
1726 // check the right order
1727 if (std::distance(aObjectIt, anAllFeatures.end()) <=
1728 std::distance(aCurrentIt, anAllFeatures.end()))
1730 // exclude the object
1731 std::advance(aObjectIt, 1);
1732 // include the current feature
1733 std::advance(aCurrentIt, 1);
1734 return std::list<FeaturePtr>(aObjectIt, aCurrentIt);
1737 bool XGUI_Workshop::canMoveFeature()
1739 QString anActionId = "MOVE_CMD";
1741 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1742 QObjectPtrList aValidatedObjects;
1743 foreach (ObjectPtr aObject, aObjects) {
1744 if (!myModule->canApplyAction(aObject, anActionId))
1746 // To be moved feature should be in active document
1747 if (aObject->document() != ModelAPI_Session::get()->activeDocument())
1749 aValidatedObjects.append(aObject);
1751 if (aValidatedObjects.size() != aObjects.size())
1752 aObjects = aValidatedObjects;
1754 bool aCanMove = !aObjects.empty();
1756 QObjectPtrList::const_iterator anIt = aObjects.begin(), aLast = aObjects.end();
1757 for (; anIt != aLast && aCanMove; anIt++) {
1758 ObjectPtr aObject = *anIt;
1759 // 1. Get features placed between selected and current in the document
1760 std::list<FeaturePtr> aFeaturesBetween = toCurrentFeatures(aObject);
1761 // if aFeaturesBetween is empty it means wrong order or aObject is the current feature
1762 if (aFeaturesBetween.empty())
1765 std::set<FeaturePtr> aPlacedFeatures(aFeaturesBetween.begin(), aFeaturesBetween.end());
1766 // 2. Get all reference features to the selected object in the document
1767 std::set<FeaturePtr> aRefFeatures;
1768 ModuleBase_Tools::refsToFeatureInFeatureDocument(aObject, aRefFeatures);
1770 if (aRefFeatures.empty())
1773 // 3. Find any placed features in all reference features
1774 std::set<FeaturePtr> aIntersectionFeatures;
1775 std::set_intersection(aRefFeatures.begin(), aRefFeatures.end(),
1776 aPlacedFeatures.begin(), aPlacedFeatures.end(),
1777 std::inserter(aIntersectionFeatures, aIntersectionFeatures.begin()));
1778 // 4. Return false if any reference feature is placed before current feature
1779 if (!aIntersectionFeatures.empty())
1787 //**************************************************************
1788 bool XGUI_Workshop::canBeShaded(const ObjectPtr& theObject) const
1790 bool aCanBeShaded = myDisplayer->canBeShaded(theObject);
1791 if (!aCanBeShaded) {
1792 ResultCompSolidPtr aCompsolidResult =
1793 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
1794 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
1795 for(int i = 0; i < aCompsolidResult->numberOfSubs() && !aCanBeShaded; i++)
1796 aCanBeShaded = myDisplayer->canBeShaded(aCompsolidResult->subResult(i));
1799 return aCanBeShaded;
1802 //**************************************************************
1803 bool XGUI_Workshop::canChangeColor() const
1805 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1807 std::set<std::string> aTypes;
1808 aTypes.insert(ModelAPI_ResultGroup::group());
1809 aTypes.insert(ModelAPI_ResultConstruction::group());
1810 aTypes.insert(ModelAPI_ResultBody::group());
1811 aTypes.insert(ModelAPI_ResultPart::group());
1813 return hasResults(aObjects, aTypes);
1816 void setColor(ResultPtr theResult, const std::vector<int>& theColor)
1818 if (!theResult.get())
1821 AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
1822 if (aColorAttr.get() != NULL) {
1823 if (!aColorAttr->size()) {
1824 aColorAttr->setSize(3);
1826 aColorAttr->setValue(0, theColor[0]);
1827 aColorAttr->setValue(1, theColor[1]);
1828 aColorAttr->setValue(2, theColor[2]);
1832 //**************************************************************
1833 void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
1836 AttributeIntArrayPtr aColorAttr;
1837 // 1. find the current color of the object. This is a color of AIS presentation
1838 // The objects are iterated until a first valid color is found
1839 std::vector<int> aColor;
1840 foreach(ObjectPtr anObject, theObjects) {
1841 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1842 if (aResult.get()) {
1843 XGUI_CustomPrs::getResultColor(aResult, aColor);
1846 // TODO: remove the obtaining a color from the AIS object
1847 // this does not happen never because:
1848 // 1. The color can be changed only on results
1849 // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
1850 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
1851 if (anAISObj.get()) {
1853 anAISObj->getColor(aColor[0], aColor[1], aColor[2]);
1856 if (!aColor.empty())
1859 if (aColor.size() != 3)
1862 if (!abortAllOperations())
1864 // 2. show the dialog to change the value
1865 XGUI_ColorDialog* aDlg = new XGUI_ColorDialog(desktop());
1866 aDlg->setColor(aColor);
1867 aDlg->move(QCursor::pos());
1868 bool isDone = aDlg->exec() == QDialog::Accepted;
1872 bool isRandomColor = aDlg->isRandomColor();
1874 // 3. abort the previous operation and start a new one
1875 SessionPtr aMgr = ModelAPI_Session::get();
1876 QString aDescription = contextMenuMgr()->action("COLOR_CMD")->text();
1877 aMgr->startOperation(aDescription.toStdString());
1879 // 4. set the value to all results
1880 std::vector<int> aColorResult = aDlg->getColor();
1881 foreach(ObjectPtr anObj, theObjects) {
1882 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
1883 if (aResult.get() != NULL) {
1884 ResultCompSolidPtr aCompsolidResult =
1885 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
1886 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
1887 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
1888 setColor(aCompsolidResult->subResult(i), !isRandomColor ? aColorResult :
1889 aDlg->getRandomColor());
1892 setColor(aResult, !isRandomColor ? aColorResult : aDlg->getRandomColor());
1895 aMgr->finishOperation();
1896 updateCommandStatus();
1899 //**************************************************************
1900 bool XGUI_Workshop::canChangeDeflection() const
1902 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1904 std::set<std::string> aTypes;
1905 aTypes.insert(ModelAPI_ResultGroup::group());
1906 aTypes.insert(ModelAPI_ResultConstruction::group());
1907 aTypes.insert(ModelAPI_ResultBody::group());
1908 aTypes.insert(ModelAPI_ResultPart::group());
1910 return hasResults(aObjects, aTypes);
1913 void setDeflection(ResultPtr theResult, const double theDeflection)
1915 if (!theResult.get())
1918 AttributeDoublePtr aDeflectionAttr = theResult->data()->real(ModelAPI_Result::DEFLECTION_ID());
1919 if (aDeflectionAttr.get() != NULL)
1920 aDeflectionAttr->setValue(theDeflection);
1924 //**************************************************************
1925 void XGUI_Workshop::changeDeflection(const QObjectPtrList& theObjects)
1927 AttributeDoublePtr aDoubleAttr;
1928 // 1. find the current color of the object. This is a color of AIS presentation
1929 // The objects are iterated until a first valid color is found
1930 double aDeflection = -1;
1931 foreach(ObjectPtr anObject, theObjects) {
1932 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1933 if (aResult.get()) {
1934 aDeflection = XGUI_CustomPrs::getResultDeflection(aResult);
1937 // TODO: remove the obtaining a color from the AIS object
1938 // this does not happen never because:
1939 // 1. The color can be changed only on results
1940 // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
1941 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
1942 if (anAISObj.get()) {
1943 aDeflection = anAISObj->getDeflection();
1946 if (aDeflection > 0)
1949 if (aDeflection < 0)
1952 if (!abortAllOperations())
1954 // 2. show the dialog to change the value
1955 XGUI_DeflectionDialog* aDlg = new XGUI_DeflectionDialog(desktop());
1956 aDlg->setDeflection(aDeflection);
1957 aDlg->move(QCursor::pos());
1958 bool isDone = aDlg->exec() == QDialog::Accepted;
1962 // 3. abort the previous operation and start a new one
1963 SessionPtr aMgr = ModelAPI_Session::get();
1964 QString aDescription = contextMenuMgr()->action("DEFLECTION_CMD")->text();
1965 aMgr->startOperation(aDescription.toStdString());
1967 // 4. set the value to all results
1968 aDeflection = aDlg->getDeflection();
1969 foreach(ObjectPtr anObj, theObjects) {
1970 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
1971 if (aResult.get() != NULL) {
1972 ResultCompSolidPtr aCompsolidResult =
1973 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
1974 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
1975 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
1976 setDeflection(aCompsolidResult->subResult(i), aDeflection);
1979 setDeflection(aResult, aDeflection);
1982 aMgr->finishOperation();
1983 updateCommandStatus();
1986 //**************************************************************
1987 #define SET_DISPLAY_GROUP(aGroupName, aDisplay) \
1988 for (int i = 0; i < aDoc->size(aGroupName); i++) { \
1989 aDoc->object(aGroupName, i)->setDisplayed(aDisplay); \
1991 void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible)
1993 foreach (ObjectPtr aObj, theList) {
1994 aObj->setDisplayed(isVisible);
1996 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1999 //**************************************************************
2000 void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList)
2002 // Hide all displayed objects
2003 QObjectPtrList aList = myDisplayer->displayedObjects();
2004 foreach (ObjectPtr aObj, aList) {
2005 if (module()->canEraseObject(aObj))
2006 aObj->setDisplayed(false);
2009 // Show only objects from the list
2010 foreach (ObjectPtr aObj, theList) {
2011 aObj->setDisplayed(true);
2013 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2017 //**************************************************************
2018 void XGUI_Workshop::registerValidators() const
2020 SessionPtr aMgr = ModelAPI_Session::get();
2021 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
2024 //**************************************************************
2025 void XGUI_Workshop::displayDocumentResults(DocumentPtr theDoc)
2029 displayGroupResults(theDoc, ModelAPI_ResultConstruction::group());
2030 displayGroupResults(theDoc, ModelAPI_ResultBody::group());
2033 //**************************************************************
2034 void XGUI_Workshop::displayGroupResults(DocumentPtr theDoc, std::string theGroup)
2036 for (int i = 0; i < theDoc->size(theGroup); i++)
2037 theDoc->object(theGroup, i)->setDisplayed(true);
2038 //displayObject(theDoc->object(theGroup, i));
2039 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2042 //**************************************************************
2043 void XGUI_Workshop::setDisplayMode(const QObjectPtrList& theList, int theMode)
2045 foreach(ObjectPtr aObj, theList) {
2046 myDisplayer->setDisplayMode(aObj, (XGUI_Displayer::DisplayMode)theMode, false);
2048 ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aObj);
2049 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
2050 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
2051 myDisplayer->setDisplayMode(aCompsolidResult->subResult(i),
2052 (XGUI_Displayer::DisplayMode)theMode, false);
2056 if (theList.size() > 0)
2057 myDisplayer->updateViewer();
2060 //**************************************************************
2061 void XGUI_Workshop::closeDocument()
2063 ModuleBase_Operation* anOperation = operationMgr()->currentOperation();
2064 while (anOperation) {
2065 anOperation->abort();
2066 anOperation = operationMgr()->currentOperation();
2068 //myDisplayer->closeLocalContexts();
2069 myDisplayer->eraseAll();
2070 objectBrowser()->clearContent();
2072 module()->closeDocument();
2074 // data model need not process the document's signals about objects modifications as
2075 // the document is closed
2076 //bool isBlocked = objectBrowser()->dataModel()->blockEventsProcessing(true);
2078 SessionPtr aMgr = ModelAPI_Session::get();
2081 //objectBrowser()->dataModel()->blockEventsProcessing(isBlocked);
2084 void XGUI_Workshop::addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot)
2086 XGUI_HistoryMenu* aMenu = NULL;
2087 if (isSalomeMode()) {
2088 QAction* anAction = qobject_cast<QAction*>(theObject);
2091 aMenu = new XGUI_HistoryMenu(anAction);
2093 QToolButton* aButton = qobject_cast<QToolButton*>(theObject);
2094 aMenu = new XGUI_HistoryMenu(aButton);
2096 connect(this, theSignal, aMenu, SLOT(setHistory(const QList<ActionInfo>&)));
2097 connect(aMenu, SIGNAL(actionSelected(int)), this, theSlot);
2100 QList<ActionInfo> XGUI_Workshop::processHistoryList(const std::list<std::string>& theList) const
2102 QList<ActionInfo> aResult;
2103 std::list<std::string>::const_iterator it = theList.cbegin();
2104 for (; it != theList.cend(); it++) {
2105 QString anId = QString::fromStdString(*it);
2106 bool isEditing = anId.endsWith(ModuleBase_OperationFeature::EditSuffix());
2108 anId.chop(ModuleBase_OperationFeature::EditSuffix().size());
2111 QAction* aContextMenuAct = myContextMenuMgr->actionByName(anId);
2112 if (aContextMenuAct) {
2113 anInfo.initFrom(aContextMenuAct);
2115 anInfo = myActionsMgr->actionInfoById(anId);
2118 anInfo.text = anInfo.text.prepend("Modify ");
2125 void XGUI_Workshop::setStatusBarMessage(const QString& theMessage)
2128 salomeConnector()->putInfo(theMessage, -1);
2130 myMainWindow->putInfo(theMessage, -1);
2134 void XGUI_Workshop::synchronizeViewer()
2136 SessionPtr aMgr = ModelAPI_Session::get();
2137 DocumentPtr aDoc = aMgr->activeDocument();
2139 synchronizeGroupInViewer(aDoc, ModelAPI_ResultConstruction::group(), false);
2140 synchronizeGroupInViewer(aDoc, ModelAPI_ResultBody::group(), false);
2141 synchronizeGroupInViewer(aDoc, ModelAPI_ResultPart::group(), false);
2142 synchronizeGroupInViewer(aDoc, ModelAPI_ResultGroup::group(), false);
2145 void XGUI_Workshop::synchronizeGroupInViewer(const DocumentPtr& theDoc,
2146 const std::string& theGroup,
2147 bool theUpdateViewer)
2150 int aSize = theDoc->size(theGroup);
2151 for (int i = 0; i < aSize; i++) {
2152 aObj = theDoc->object(theGroup, i);
2153 if (aObj->isDisplayed()) {
2154 // Hide the presentation with an empty shape. But isDisplayed state of the object should not
2155 // be changed to the object becomes visible when the shape becomes not empty
2156 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
2157 if (aRes.get() && (!aRes->shape().get() || aRes->shape()->isNull()))
2159 myDisplayer->display(aObj, false);
2162 if (theUpdateViewer)
2163 myDisplayer->updateViewer();
2166 void XGUI_Workshop::highlightResults(const QObjectPtrList& theObjects)
2168 FeaturePtr aFeature;
2169 QObjectPtrList aSelList = theObjects;
2170 bool aHasHidden = false;
2171 foreach(ObjectPtr aObj, theObjects) {
2172 aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
2173 if (aFeature.get()) {
2174 std::list<ResultPtr> aResults;
2175 ModelAPI_Tools::allResults(aFeature, aResults);
2176 std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aIt;
2177 for(aIt = aResults.cbegin(); aIt != aResults.cend(); aIt++) {
2178 aHasHidden |= (*aIt)->isConcealed();
2179 aSelList.append(*aIt);
2183 if (aSelList.count() > theObjects.count()) {
2184 // if something was found
2185 bool aBlocked = objectBrowser()->blockSignals(true);
2186 objectBrowser()->setObjectsSelected(aSelList);
2187 objectBrowser()->blockSignals(aBlocked);
2190 QMessageBox::information(desktop(), tr("Find results"),
2191 tr("Results not found"), QMessageBox::Ok);
2194 void XGUI_Workshop::highlightFeature(const QObjectPtrList& theObjects)
2197 QObjectPtrList aSelList = theObjects;
2198 FeaturePtr aFeature;
2199 foreach(ObjectPtr aObj, theObjects) {
2200 aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
2201 if (aResult.get()) {
2202 aFeature = ModelAPI_Feature::feature(aResult);
2203 if (aFeature.get()) {
2204 aSelList.append(aFeature);
2208 if (aSelList.count() > theObjects.count()) {
2209 // if something was found
2210 bool aBlocked = objectBrowser()->blockSignals(true);
2211 objectBrowser()->setObjectsSelected(aSelList);
2212 objectBrowser()->blockSignals(aBlocked);