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 #ifdef BEFORE_TRIHEDRON_PATCH
89 #include <AIS_Point.hxx>
90 #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 <TInspector_Communicator.hxx>
114 #include <VInspector_CallBack.hxx>
115 static TInspector_Communicator* MyTCommunicator;
116 static Handle(VInspector_CallBack) MyVCallBack;
131 QString XGUI_Workshop::MOVE_TO_END_COMMAND = QObject::tr("Move to the end");
133 //#define DEBUG_DELETE
134 //#define DEBUG_FEATURE_NAME
135 //#define DEBUG_CLEAN_HISTORY
137 XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
139 myCurrentDir(QString()),
141 mySalomeConnector(theConnector),
145 //myViewerSelMode(TopAbs_FACE)
147 mySelector = new XGUI_SelectionMgr(this);
148 myModuleConnector = new XGUI_ModuleConnector(this);
149 myOperationMgr = new XGUI_OperationMgr(this, 0);
150 ModuleBase_IWorkshop* aWorkshop = moduleConnector();
151 // Has to be defined first in order to get errors and messages from other components
152 myEventsListener = new XGUI_WorkshopListener(aWorkshop);
154 SUIT_ResourceMgr* aResMgr = ModuleBase_Preferences::resourceMgr();
156 myMainWindow = new AppElements_MainWindow();
158 bool aCloc = aResMgr->booleanValue("language", "locale", true);
160 QLocale::setDefault( QLocale::c() );
162 QLocale::setDefault( QLocale::system() );
164 QString aPath = Config_XMLReader::pluginConfigFile().c_str();
169 aLangs << "*_en.ts"; // load by default eng translations
170 QString aCurrLang = aResMgr->stringValue("language", "language", "en");
171 if(aCurrLang != "en") {
172 aLangs << "*_" + aCurrLang + ".ts"; // then replace with translated files
175 foreach(QString aLang, aLangs) {
176 QStringList aFilters;
178 QStringList aTsFiles = aDir.entryList(aFilters, QDir::Files);
179 foreach(QString aFileName, aTsFiles) {
180 Config_Translator::load(aFileName.toStdString());
184 myDataModelXMLReader = new Config_DataModelReader();
185 //myDataModelXMLReader->readAll();
187 myDisplayer = new XGUI_Displayer(this);
189 connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(updateCommandStatus()));
191 myActionsMgr = new XGUI_ActionsMgr(this);
192 myMenuMgr = new XGUI_MenuMgr(this);
193 myErrorDlg = new XGUI_ErrorDialog(QApplication::desktop());
194 myContextMenuMgr = new XGUI_ContextMenuMgr(this);
195 connect(myContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), this,
196 SLOT(onContextMenuCommand(const QString&, bool)));
198 myViewerProxy = new XGUI_ViewerProxy(this);
199 //connect(myViewerProxy, SIGNAL(selectionChanged()),
200 // myActionsMgr, SLOT(updateOnViewSelection()));
202 myOperationMgr->setWorkshop(aWorkshop);
204 myErrorMgr = new XGUI_ErrorMgr(this, aWorkshop);
206 connect(myOperationMgr, SIGNAL(operationResumed(ModuleBase_Operation*)),
207 SLOT(onOperationResumed(ModuleBase_Operation*)));
208 connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
209 SLOT(onOperationStopped(ModuleBase_Operation*)));
210 connect(myOperationMgr, SIGNAL(operationCommitted(ModuleBase_Operation*)),
211 SLOT(onOperationCommitted(ModuleBase_Operation*)));
212 connect(myOperationMgr, SIGNAL(operationAborted(ModuleBase_Operation*)),
213 SLOT(onOperationAborted(ModuleBase_Operation*)));
216 connect(myMainWindow, SIGNAL(exitKeySequence()), SLOT(onExit()));
217 onTrihedronVisibilityChanged(true);
220 connect(myEventsListener, SIGNAL(errorOccurred(std::shared_ptr<Events_InfoMessage>)),
221 myErrorDlg, SLOT(addError(std::shared_ptr<Events_InfoMessage>)));
223 //Config_PropManager::registerProp("Visualization", "object_default_color", "Object color",
224 // Config_Prop::Color, "225,225,225");
226 Config_PropManager::registerProp("Visualization", "result_body_color", "Result color",
227 Config_Prop::Color, ModelAPI_ResultBody::DEFAULT_COLOR());
228 Config_PropManager::registerProp("Visualization", "result_group_color", "Group color",
229 Config_Prop::Color, ModelAPI_ResultGroup::DEFAULT_COLOR());
230 Config_PropManager::registerProp("Visualization", "result_construction_color",
231 "Construction color",
233 ModelAPI_ResultConstruction::DEFAULT_COLOR());
234 Config_PropManager::registerProp("Visualization", "result_part_color", "Part color",
235 Config_Prop::Color, ModelAPI_ResultPart::DEFAULT_COLOR());
237 Config_PropManager::registerProp("Visualization", "body_deflection",
238 "Body deflection coefficient",
240 ModelAPI_ResultBody::DEFAULT_DEFLECTION());
242 Config_PropManager::registerProp("Visualization", "construction_deflection",
243 "Construction deflection coefficient",
245 ModelAPI_ResultConstruction::DEFAULT_DEFLECTION());
247 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "face-selection", true))
248 myViewerSelMode.append(TopAbs_FACE);
249 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "edge-selection", true))
250 myViewerSelMode.append(TopAbs_EDGE);
251 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "vertex-selection", true))
252 myViewerSelMode.append(TopAbs_VERTEX);
253 //IMP: an attempt to use result selection with other selection modes
254 myViewerSelMode.append(ModuleBase_ResultPrs::Sel_Result);//TopAbs_VERTEX);
255 myViewerSelMode.append(TopAbs_COMPSOLID);
258 //******************************************************
259 XGUI_Workshop::~XGUI_Workshop(void)
262 #ifdef MISSED_TRANSLATION
263 // Save Missed translations
264 Config_Translator::saveMissedTranslations();
269 delete myDataModelXMLReader;
272 //******************************************************
273 void XGUI_Workshop::startApplication()
275 //Initialize event listening
276 myEventsListener->initializeEventListening();
278 myDataModelXMLReader->readAll();
281 Config_PropManager::registerProp("Plugins", "default_path", "Default Path",
282 Config_Prop::Directory, "");
285 registerValidators();
287 // Calling of loadCustomProps before activating module is required
288 // by Config_PropManger to restore user-defined path to plugins
289 ModuleBase_Preferences::loadCustomProps();
293 myMainWindow->show();
294 updateCommandStatus();
299 myViewerProxy->connectViewProxy();
300 connect(myViewerProxy, SIGNAL(trihedronVisibilityChanged(bool)),
301 SLOT(onTrihedronVisibilityChanged(bool)));
303 emit applicationStarted();
306 void XGUI_Workshop::activateModule()
308 myModule->activateSelectionFilters();
310 connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
311 myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
312 connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
313 myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
315 updateCommandStatus();
317 // TODO: get default selection mode
319 // activate visualized objects in the viewer
320 activateObjectsSelection(displayer()->displayedObjects());
321 myOperationMgr->activate();
324 void XGUI_Workshop::deactivateModule()
326 myModule->deactivateSelectionFilters();
328 // remove internal displayer filter
329 displayer()->deactivateSelectionFilters();
331 disconnect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
332 myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
333 disconnect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
334 myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
336 XGUI_Displayer* aDisplayer = displayer();
337 QObjectPtrList aDisplayed = aDisplayer->displayedObjects();
338 aDisplayer->deactivateObjects(aDisplayed, true);
339 Handle(AIS_InteractiveContext) aContext = viewer()->AISContext();
340 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(aDisplayer->getTrihedron());
341 /// deactivate trihedron in selection modes
342 TColStd_ListOfInteger aTColModes;
343 aContext->ActivatedModes(aTrihedron, aTColModes);
344 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
345 for (; itr.More(); itr.Next() ) {
346 Standard_Integer aMode = itr.Value();
347 aContext->Deactivate(aTrihedron, aMode);
349 #ifdef BEFORE_TRIHEDRON_PATCH
350 /// Trihedron problem: objects stayed in the viewer, should be removed manually
351 /// otherwise in SALOME happens crash by HideAll in the viewer
352 aContext->Remove(aTrihedron->Position(), true);
353 aContext->Remove(aTrihedron->Axis(), true);
354 aContext->Remove(aTrihedron->XAxis(), true);
355 aContext->Remove(aTrihedron->YAxis(), true);
358 myOperationMgr->deactivate();
361 //******************************************************
362 void XGUI_Workshop::initMenu()
364 myContextMenuMgr->createActions();
367 // Create only Undo, Redo commands
368 QAction* aAction = salomeConnector()->addDesktopCommand("UNDO_CMD", tr("Undo"),
369 tr("Undo last command"),
370 QIcon(":pictures/undo.png"),
371 QKeySequence::Undo, false,
373 QString aToolBarTitle = tr( "INF_DESK_TOOLBAR_STANDARD" );
374 salomeConnector()->addActionInToolbar( aAction,aToolBarTitle );
376 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onUndo()));
377 addHistoryMenu(aAction, SIGNAL(updateUndoHistory(const QList<ActionInfo>&)), SLOT(onUndo(int)));
379 aAction = salomeConnector()->addDesktopCommand("REDO_CMD", tr("Redo"), tr("Redo last command"),
380 QIcon(":pictures/redo.png"), QKeySequence::Redo,
381 false, "MEN_DESK_EDIT");
382 salomeConnector()->addActionInToolbar( aAction, aToolBarTitle );
384 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo()));
385 addHistoryMenu(aAction, SIGNAL(updateRedoHistory(const QList<ActionInfo>&)), SLOT(onRedo(int)));
387 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
388 //aAction = salomeConnector()->addDesktopCommand("REBUILD_CMD", tr("Rebuild"),
389 // tr("Rebuild data objects"),
390 // QIcon(":pictures/rebuild.png"), QKeySequence(),
391 // false, "MEN_DESK_EDIT");
392 //salomeConnector()->addActionInToolbar( aAction, aToolBarTitle );
394 //connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRebuild()));
395 //salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
397 aAction = salomeConnector()->addDesktopCommand("SAVEAS_CMD", tr("Export native..."),
398 tr("Export the current document into a native file"),
399 QIcon(), QKeySequence(),
400 false, "MEN_DESK_FILE");
401 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onSaveAs()));
403 aAction = salomeConnector()->addDesktopCommand("OPEN_CMD", tr("Import native..."),
404 tr("Import native file"),
405 QIcon(), QKeySequence(),
406 false, "MEN_DESK_FILE");
407 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onOpen()));
408 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_FILE");
411 // File commands group
412 AppElements_MenuGroupPanel* aGroup = myMainWindow->menuObject()->generalPage();
414 AppElements_Command* aCommand;
416 aCommand = aGroup->addFeature("SAVE_CMD", tr("Save"), tr("Save the document"),
417 QIcon(":pictures/save.png"), QKeySequence::Save);
418 aCommand->connectTo(this, SLOT(onSave()));
419 //aCommand->disable();
421 aCommand = aGroup->addFeature("SAVEAS_CMD", tr("Save as..."), tr("Save the document into a file"),
422 QIcon(":pictures/save.png"), QKeySequence());
423 aCommand->connectTo(this, SLOT(onSaveAs()));
425 QString aUndoId = "UNDO_CMD";
426 aCommand = aGroup->addFeature(aUndoId, tr("Undo"), tr("Undo last command"),
427 QIcon(":pictures/undo.png"), QKeySequence::Undo);
428 aCommand->connectTo(this, SLOT(onUndo()));
429 AppElements_Button* aUndoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aUndoId));
430 addHistoryMenu(aUndoButton,
431 SIGNAL(updateUndoHistory(const QList<ActionInfo>&)),
434 QString aRedoId = "REDO_CMD";
435 aCommand = aGroup->addFeature(aRedoId, tr("Redo"), tr("Redo last command"),
436 QIcon(":pictures/redo.png"), QKeySequence::Redo);
437 aCommand->connectTo(this, SLOT(onRedo()));
438 AppElements_Button* aRedoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aRedoId));
439 addHistoryMenu(aRedoButton,
440 SIGNAL(updateRedoHistory(const QList<ActionInfo>&)),
443 //aCommand = aGroup->addFeature("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
444 // QIcon(":pictures/rebuild.png"), QKeySequence());
445 //aCommand->connectTo(this, SLOT(onRebuild()));
447 //aCommand->disable();
449 aCommand = aGroup->addFeature("OPEN_CMD", tr("Open..."), tr("Open a new document"),
450 QIcon(":pictures/open.png"), QKeySequence::Open);
451 aCommand->connectTo(this, SLOT(onOpen()));
453 aCommand = aGroup->addFeature("PREF_CMD", tr("Preferences"), tr("Edit preferences"),
454 QIcon(":pictures/preferences.png"), QKeySequence::Preferences);
455 aCommand->connectTo(this, SLOT(onPreferences()));
457 aCommand = aGroup->addFeature("EXIT_CMD", tr("Exit"), tr("Exit application"),
458 QIcon(":pictures/close.png"), QKeySequence::Close);
459 aCommand->connectTo(this, SLOT(onExit()));
464 AppElements_Workbench* XGUI_Workshop::addWorkbench(const QString& theName)
466 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
467 return aMenuBar->addWorkbench(theName);
471 //******************************************************
472 QMainWindow* XGUI_Workshop::desktop() const
475 return salomeConnector()->desktop();
481 //******************************************************
482 void XGUI_Workshop::onStartWaiting()
484 if (Events_LongOp::isPerformed()) {
485 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
489 //******************************************************
490 void XGUI_Workshop::onAcceptActionClicked()
492 QAction* anAction = dynamic_cast<QAction*>(sender());
493 XGUI_OperationMgr* anOperationMgr = operationMgr();
494 if (anOperationMgr) {
495 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
496 (anOperationMgr->currentOperation());
498 //if (errorMgr()->canProcessClick(anAction, aFOperation->feature()))
499 myOperationMgr->onCommitOperation();
504 //******************************************************
505 void XGUI_Workshop::onPreviewActionClicked()
507 ModuleBase_IPropertyPanel* aPanel = propertyPanel();
509 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
510 if (anActiveWidget && anActiveWidget->getValueState() == ModuleBase_ModelWidget::ModifiedInPP) {
511 anActiveWidget->storeValue();
514 std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
515 new Events_Message(Events_Loop::eventByName(EVENT_PREVIEW_REQUESTED)));
516 Events_Loop::loop()->send(aMsg);
519 //******************************************************
520 void XGUI_Workshop::deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer)
522 if (!myModule->canActivateSelection(theObject)) {
523 if (myDisplayer->isActive(theObject)) {
524 QObjectPtrList anObjects;
525 anObjects.append(theObject);
526 myDisplayer->deactivateObjects(anObjects, theUpdateViewer);
531 //******************************************************
532 bool XGUI_Workshop::isFeatureOfNested(const FeaturePtr& theFeature)
534 bool aHasNested = false;
535 std::string aFeatureKind = theFeature->getKind();
537 XGUI_SalomeConnector* aSalomeConnector = salomeConnector();
538 if (aSalomeConnector->isFeatureOfNested(actionsMgr()->action(aFeatureKind.c_str())))
541 AppElements_MainMenu* aMenuBar = mainWindow()->menuObject();
542 AppElements_Command* aCommand = aMenuBar->feature(aFeatureKind.c_str());
543 if (aCommand && aCommand->button()->additionalButtonWidget())
549 void XGUI_Workshop::fillPropertyPanel(ModuleBase_Operation* theOperation)
551 ModuleBase_OperationFeature* aFOperation =
552 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
557 myPropertyPanel->cleanContent();
559 QList<ModuleBase_ModelWidget*> aWidgets;
560 if (!module()->createWidgets(theOperation, aWidgets)) {
561 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
562 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), myModuleConnector);
563 aFactory.createWidget(myPropertyPanel->contentWidget());
564 aWidgets = aFactory.getModelWidgets();
567 // check compatibility of feature and widgets
568 FeaturePtr aFeature = aFOperation->feature();
569 std::string aFeatureKind = aFeature->getKind();
570 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
571 if (!aWidget->attributeID().empty() && !aFeature->attribute(aWidget->attributeID()).get()) {
572 std::string anErrorMsg = "The feature '%1' has no attribute '%2' used by widget '%3'.";
573 Events_InfoMessage("XGUI_Workshop", anErrorMsg)
574 .arg(aFeatureKind).arg(aWidget->attributeID())
575 .arg(aWidget->metaObject()->className()).send();
576 myPropertyPanel->cleanContent();
580 // for performance purpose, flush should be done after all controls are filled
581 bool isUpdateFlushed = false;
582 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
583 bool isStoreValue = !aFOperation->isEditOperation() &&
584 !aWidget->getDefaultValue().empty() &&
585 !aWidget->isComputedDefault();
586 aWidget->setFeature(aFeature, isStoreValue, isUpdateFlushed);
588 aWidget->restoreValue();
589 aWidget->enableFocusProcessing();
591 ModuleBase_Tools::flushUpdated(aFeature);
593 // update visible state of Preview button
595 bool anIsAutoPreview =
596 mySalomeConnector->featureInfo(aFeatureKind.c_str())->isAutoPreview();
598 AppElements_MainMenu* aMenuBar = mainWindow()->menuObject();
599 AppElements_Command* aCommand = aMenuBar->feature(aFeatureKind.c_str());
600 bool anIsAutoPreview = aCommand && aCommand->featureMessage()->isAutoPreview();
602 if (!anIsAutoPreview) {
603 myPropertyPanel->findButton(PROP_PANEL_PREVIEW)->setVisible(true);
604 // send signal about preview should not be computed automatically, click on preview
605 // button should initiate it
606 std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
607 new Events_Message(Events_Loop::eventByName(EVENT_PREVIEW_BLOCKED)));
608 Events_Loop::loop()->send(aMsg);
610 myPropertyPanel->setModelWidgets(aWidgets);
611 aFOperation->setPropertyPanel(myPropertyPanel);
613 myModule->propertyPanelDefined(theOperation);
615 #ifndef DEBUG_FEATURE_NAME
616 myPropertyPanel->setWindowTitle(theOperation->getDescription()->description());
618 std::string aFeatureName = aFeature->name();
619 myPropertyPanel->setWindowTitle(QString("%1: %2")
620 .arg(theOperation->getDescription()->description())
621 .arg(aFeatureName.c_str()));
624 myErrorMgr->setPropertyPanel(myPropertyPanel);
627 void XGUI_Workshop::connectToPropertyPanel(const bool isToConnect)
629 XGUI_PropertyPanel* aPropertyPanel = propertyPanel();
630 if (aPropertyPanel) {
631 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
632 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
633 myModule->connectToPropertyPanel(aWidget, isToConnect);
635 connect(aWidget, SIGNAL(valueStateChanged(int)), this, SLOT(onWidgetStateChanged(int)));
636 connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
637 connect(aWidget, SIGNAL(objectUpdated()), this, SLOT(onWidgetObjectUpdated()));
640 disconnect(aWidget, SIGNAL(valueStateChanged(int)), this, SLOT(onWidgetStateChanged(int)));
641 disconnect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
642 disconnect(aWidget, SIGNAL(objectUpdated()), this, SLOT(onWidgetObjectUpdated()));
648 //******************************************************
649 void XGUI_Workshop::onOperationResumed(ModuleBase_Operation* theOperation)
651 setGrantedFeatures(theOperation);
653 if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
654 fillPropertyPanel(theOperation);
655 connectToPropertyPanel(true);
657 updateCommandStatus();
659 myModule->operationResumed(theOperation);
663 //******************************************************
664 void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
666 updateCommandStatus();
668 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
673 ModuleBase_ISelection* aSel = mySelector->selection();
674 QObjectPtrList aObj = aSel->selectedPresentations();
675 //!< No need for property panel
677 myPropertyPanel->cleanContent();
679 connectToPropertyPanel(false);
680 myModule->operationStopped(aFOperation);
682 // the deactivated objects of the current operation should be activated back.
683 // They were deactivated on operation start or an object redisplay
684 QObjectPtrList anObjects;
685 FeaturePtr aFeature = aFOperation->feature();
686 if (aFeature.get()) { // feature may be not created (plugin load fail)
687 if (myDisplayer->isVisible(aFeature) && !myDisplayer->isActive(aFeature))
688 anObjects.append(aFeature);
689 std::list<ResultPtr> aResults;
690 ModelAPI_Tools::allResults(aFeature, aResults);
691 std::list<ResultPtr>::const_iterator aIt;
692 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
693 ResultPtr anObject = *aIt;
694 if (myDisplayer->isVisible(anObject) && !myDisplayer->isActive(anObject)) {
695 anObjects.append(anObject);
699 activateObjectsSelection(anObjects);
703 void XGUI_Workshop::onOperationCommitted(ModuleBase_Operation* theOperation)
705 myModule->operationCommitted(theOperation);
708 void XGUI_Workshop::onOperationAborted(ModuleBase_Operation* theOperation)
710 myModule->operationAborted(theOperation);
713 void XGUI_Workshop::setGrantedFeatures(ModuleBase_Operation* theOperation)
715 ModuleBase_OperationFeature* aFOperation =
716 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
720 QStringList aGrantedIds;
721 if (isSalomeMode()) {
722 const std::shared_ptr<Config_FeatureMessage>& anInfo =
723 mySalomeConnector->featureInfo(theOperation->id());
725 aGrantedIds = QString::fromStdString(anInfo->nestedFeatures())
726 .split(" ", QString::SkipEmptyParts);
729 aGrantedIds = myActionsMgr->nestedCommands(theOperation->id());
731 ModuleBase_IModule* aModule = module();
733 aModule->grantedOperationIds(theOperation, aGrantedIds);
735 aFOperation->setGrantedOperationIds(aGrantedIds);
738 //******************************************************
739 void XGUI_Workshop::saveDocument(const QString& theName, std::list<std::string>& theFileNames)
741 QApplication::restoreOverrideCursor();
742 SessionPtr aMgr = ModelAPI_Session::get();
744 std::list<DocumentPtr> aDocList = aMgr->allOpenedDocuments();
745 std::list<DocumentPtr>::const_iterator aIt;
746 for (aIt = aDocList.cbegin(); aIt != aDocList.cend(); aIt++) {
747 std::list<bool> aState = myObjectBrowser->getStateForDoc(*aIt);
748 (*aIt)->storeNodesState(aState);
751 aMgr->save(theName.toLatin1().constData(), theFileNames);
753 QApplication::restoreOverrideCursor();
756 //******************************************************
757 bool XGUI_Workshop::abortAllOperations()
759 return myOperationMgr->abortAllOperations();
762 //******************************************************
763 void XGUI_Workshop::operationStarted(ModuleBase_Operation* theOperation)
765 setGrantedFeatures(theOperation);
766 if (!theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
767 updateCommandStatus();
770 myModule->operationStarted(theOperation);
774 //******************************************************
775 void XGUI_Workshop::onOpen()
777 if(!abortAllOperations())
779 //save current file before close if modified
780 SessionPtr aSession = ModelAPI_Session::get();
781 if (aSession->isModified()) {
782 //TODO(sbh): re-launch the app?
783 int anAnswer = QMessageBox::question(
784 desktop(), tr("Save current file"),
785 tr("The document is modified, save before opening another?"),
786 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
787 if (anAnswer == QMessageBox::Save) {
789 } else if (anAnswer == QMessageBox::Cancel) {
795 //show file dialog, check if readable and open
796 QString aDirectory = QFileDialog::getExistingDirectory(desktop(), tr("Select directory"));
797 openDirectory(aDirectory);
800 //******************************************************
801 void XGUI_Workshop::openDirectory(const QString& theDirectory)
803 myCurrentDir = theDirectory;
804 if (myCurrentDir.isEmpty())
807 QFileInfo aFileInfo(myCurrentDir);
808 if (!aFileInfo.exists() || !aFileInfo.isReadable()) {
809 QMessageBox::critical(desktop(), tr("Warning"), tr("Unable to open the file."));
814 QApplication::setOverrideCursor(Qt::WaitCursor);
815 module()->closeDocument();
816 SessionPtr aSession = ModelAPI_Session::get();
817 aSession->closeAll();
818 aSession->load(myCurrentDir.toLatin1().constData());
819 myObjectBrowser->rebuildDataTree();
821 // Open first level of data tree
822 DocumentPtr aRootDoc = aSession->moduleDocument();
823 std::list<bool> aStates;
824 aRootDoc->restoreNodesState(aStates);
825 myObjectBrowser->setStateForDoc(aRootDoc, aStates);
827 updateCommandStatus();
829 myMainWindow->setCurrentDir(myCurrentDir, true);
831 QApplication::restoreOverrideCursor();
834 //******************************************************
835 void XGUI_Workshop::onNew()
837 QApplication::setOverrideCursor(Qt::WaitCursor);
838 if (objectBrowser() == 0) {
840 mySelector->connectViewers();
842 myViewerProxy->connectToViewer();
845 myMainWindow->showPythonConsole();
846 QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
847 aWnd->showMaximized();
848 updateCommandStatus();
850 myContextMenuMgr->connectViewer();
851 QApplication::restoreOverrideCursor();
855 //******************************************************
856 void XGUI_Workshop::onExit()
858 SessionPtr aMgr = ModelAPI_Session::get();
859 if (aMgr->isModified()) {
860 int anAnswer = QMessageBox::question(
861 myMainWindow, tr("Save current file"), tr("The document is modified, save before exit?"),
862 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
863 if (anAnswer == QMessageBox::Save) {
864 bool saved = onSave();
868 } else if (anAnswer == QMessageBox::Cancel) {
875 //******************************************************
876 void XGUI_Workshop::onPreferences()
878 ModuleBase_Prefs aModif;
879 ModuleBase_Preferences::editPreferences(aModif);
880 if (aModif.size() > 0) {
882 foreach (ModuleBase_Pref aPref, aModif)
884 aSection = aPref.first;
885 if (aSection == ModuleBase_Preferences::VIEWER_SECTION) {
886 myMainWindow->viewer()->updateFromResources();
887 } else if (aSection == ModuleBase_Preferences::MENU_SECTION) {
888 myMainWindow->menuObject()->updateFromResources();
891 displayer()->redisplayObjects();
896 //******************************************************
897 void XGUI_Workshop::onTrihedronVisibilityChanged(bool theState)
899 XGUI_Displayer* aDisplayer = displayer();
901 aDisplayer->displayTrihedron(theState);
904 //******************************************************
905 bool XGUI_Workshop::onSave()
907 if(!abortAllOperations())
909 if (myCurrentDir.isEmpty()) {
912 std::list<std::string> aFiles;
913 saveDocument(myCurrentDir, aFiles);
914 updateCommandStatus();
916 myMainWindow->setModifiedState(false);
921 //******************************************************
922 bool XGUI_Workshop::onSaveAs()
924 if(!abortAllOperations())
926 QFileDialog dialog(desktop());
927 dialog.setWindowTitle(tr("Select directory to save files..."));
928 dialog.setFileMode(QFileDialog::Directory);
929 dialog.setFilter(QDir::AllDirs);
930 dialog.setOptions(QFileDialog::HideNameFilterDetails | QFileDialog::ShowDirsOnly);
931 dialog.setViewMode(QFileDialog::Detail);
933 if (!dialog.exec()) {
937 QString aTempDir = dialog.selectedFiles().first();
939 if (aDir.exists() && !aDir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries).isEmpty()) {
940 int answer = QMessageBox::question(
942 // Title of the dialog which asks user if he wants to save study
943 // in existing non-empty folder
945 tr("The directory already contains some files, save anyway?"),
946 QMessageBox::Save | QMessageBox::Cancel);
947 if (answer == QMessageBox::Cancel) {
951 myCurrentDir = aTempDir;
953 myMainWindow->setCurrentDir(myCurrentDir, false);
954 myMainWindow->setModifiedState(false);
959 //******************************************************
960 void XGUI_Workshop::onUndo(int theTimes)
962 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
963 SessionPtr aMgr = ModelAPI_Session::get();
964 std::list<std::string> aUndoList = aMgr->undoList();
965 if (aMgr->isOperation()) {
966 /// this is important for nested operations
967 /// when sketch operation is active, this condition is false and
968 /// the sketch operation is not aborted
969 operationMgr()->onAbortOperation();
971 std::list<std::string>::const_iterator aIt = aUndoList.cbegin();
972 for (int i = 0; (i < theTimes) && (aIt != aUndoList.cend()); ++i, ++aIt) {
974 if (QString((*aIt).c_str()) == MOVE_TO_END_COMMAND)
975 myObjectBrowser->rebuildDataTree();
978 operationMgr()->updateApplyOfOperations();
979 updateCommandStatus();
982 //******************************************************
983 void XGUI_Workshop::onRedo(int theTimes)
985 // the viewer update should be blocked in order to avoid the features blinking. For the created
986 // feature a results are created, the flush of the created signal caused the viewer redisplay for
987 // each created result. After a redisplay signal is flushed. So, the viewer update is blocked
988 // until redo of all possible objects happens
989 bool isUpdateEnabled = myDisplayer->enableUpdateViewer(false);
991 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
992 SessionPtr aMgr = ModelAPI_Session::get();
993 std::list<std::string> aRedoList = aMgr->redoList();
994 if (aMgr->isOperation()) {
995 /// this is important for nested operations
996 /// when sketch operation is active, this condition is false and
997 /// the sketch operation is not aborted
998 operationMgr()->onAbortOperation();
1000 std::list<std::string>::const_iterator aIt = aRedoList.cbegin();
1001 for (int i = 0; (i < theTimes) && (aIt != aRedoList.cend()); ++i, ++aIt) {
1003 if (QString((*aIt).c_str()) == MOVE_TO_END_COMMAND)
1004 myObjectBrowser->rebuildDataTree();
1006 operationMgr()->updateApplyOfOperations();
1007 updateCommandStatus();
1009 // unblock the viewer update functionality and make update on purpose
1010 myDisplayer->enableUpdateViewer(isUpdateEnabled);
1011 myDisplayer->updateViewer();
1014 //******************************************************
1015 //void XGUI_Workshop::onRebuild()
1017 // SessionPtr aMgr = ModelAPI_Session::get();
1018 // bool aWasOperation = aMgr->isOperation(); // keep this value
1019 // if (!aWasOperation) {
1020 // aMgr->startOperation("Rebuild");
1022 // static const Events_ID aRebuildEvent = Events_Loop::loop()->eventByName("Rebuild");
1023 // Events_Loop::loop()->send(std::shared_ptr<Events_Message>(
1024 // new Events_Message(aRebuildEvent, this)));
1025 // if (!aWasOperation) {
1026 // aMgr->finishOperation();
1028 // updateCommandStatus();
1031 //******************************************************
1032 void XGUI_Workshop::onWidgetStateChanged(int thePreviousState)
1034 ModuleBase_ModelWidget* anActiveWidget = 0;
1035 ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
1037 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1039 anActiveWidget = aPanel->activeWidget();
1042 operationMgr()->onValidateOperation();
1044 myModule->widgetStateChanged(thePreviousState);
1047 //******************************************************
1048 void XGUI_Workshop::onValuesChanged()
1050 ModuleBase_ModelWidget* aSenderWidget = (ModuleBase_ModelWidget*)(sender());
1051 if (!aSenderWidget || aSenderWidget->canAcceptFocus())
1054 ModuleBase_ModelWidget* anActiveWidget = 0;
1055 ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
1057 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1059 anActiveWidget = aPanel->activeWidget();
1061 if (anActiveWidget) {
1062 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1064 if (aWidgetValidated)
1065 aWidgetValidated->clearValidatedCash();
1069 void XGUI_Workshop::onWidgetObjectUpdated()
1071 operationMgr()->onValidateOperation();
1074 ModuleBase_IModule* XGUI_Workshop::loadModule(const QString& theModule)
1076 QString libName = QString::fromStdString(library(theModule.toStdString()));
1077 if (libName.isEmpty()) {
1078 qWarning(qPrintable(tr("Information about module \"%1\" doesn't exist.").arg(theModule)));
1083 CREATE_FUNC crtInst = 0;
1086 HINSTANCE modLib = ::LoadLibrary((LPTSTR) qPrintable(libName));
1090 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
1091 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
1092 QString aMsg((char*) &lpMsgBuf);
1093 err = QString("Failed to load %1. %2").arg(libName).arg(aMsg);
1094 ::LocalFree(lpMsgBuf);
1096 crtInst = (CREATE_FUNC) ::GetProcAddress(modLib, CREATE_MODULE);
1100 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
1101 | FORMAT_MESSAGE_IGNORE_INSERTS,
1102 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
1103 QString aMsg((char*) &lpMsgBuf);
1104 err = QString("Failed to find %1 function. %2").arg( CREATE_MODULE).arg(aMsg);
1105 ::LocalFree(lpMsgBuf);
1109 void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY | RTLD_GLOBAL );
1111 err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
1113 crtInst = (CREATE_FUNC)dlsym( modLib, CREATE_MODULE );
1115 err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() );
1120 ModuleBase_IModule* aModule = crtInst ? crtInst(myModuleConnector) : 0;
1122 if (!err.isEmpty()) {
1124 Events_InfoMessage("XGUI_Workshop", err.toStdString()).send();
1126 qWarning(qPrintable(err));
1132 //******************************************************
1133 bool XGUI_Workshop::createModule()
1135 Config_ModuleReader aModuleReader;
1136 QString moduleName = QString::fromStdString(aModuleReader.getModuleName());
1137 myModule = loadModule(moduleName);
1141 //connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
1142 // myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
1143 //connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
1144 // myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
1146 myModule->createFeatures();
1148 salomeConnector()->createFeatureActions();
1150 //myActionsMgr->update();
1154 //******************************************************
1155 void XGUI_Workshop::updateCommandStatus()
1157 QList<QAction*> aCommands;
1159 aCommands = salomeConnector()->commandList();
1161 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
1162 foreach (AppElements_Command* aCmd, aMenuBar->features())
1163 aCommands.append(aCmd);
1165 SessionPtr aMgr = ModelAPI_Session::get();
1166 if (aMgr->hasModuleDocument()) {
1167 foreach(QAction* aCmd, aCommands) {
1168 QString aId = aCmd->data().toString();
1169 if (aId == "UNDO_CMD")
1170 aCmd->setEnabled(myModule->canUndo());
1171 else if (aId == "REDO_CMD")
1172 aCmd->setEnabled(myModule->canRedo());
1174 // Enable all commands
1175 aCmd->setEnabled(true);
1179 foreach(QAction* aCmd, aCommands) {
1180 QString aId = aCmd->data().toString();
1181 if (aId == "NEW_CMD")
1182 aCmd->setEnabled(true);
1183 else if (aId == "EXIT_CMD")
1184 aCmd->setEnabled(true);
1186 aCmd->setEnabled(false);
1189 myActionsMgr->updateCommandsStatus();
1190 emit commandStatusUpdated();
1193 void XGUI_Workshop::updateHistory()
1195 std::list<std::string> aUndoList = ModelAPI_Session::get()->undoList();
1196 QList<ActionInfo> aUndoRes = processHistoryList(aUndoList);
1197 emit updateUndoHistory(aUndoRes);
1199 std::list<std::string> aRedoList = ModelAPI_Session::get()->redoList();
1200 QList<ActionInfo> aRedoRes = processHistoryList(aRedoList);
1201 emit updateRedoHistory(aRedoRes);
1204 //******************************************************
1205 QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
1207 QDockWidget* aObjDock = new QDockWidget(theParent);
1208 aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea |
1209 Qt::RightDockWidgetArea |
1210 Qt::BottomDockWidgetArea);
1211 aObjDock->setWindowTitle(tr("Object browser"));
1212 aObjDock->setStyleSheet(
1213 "::title { position: relative; padding-left: 5px; text-align: left center }");
1214 myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock);
1215 myObjectBrowser->setXMLReader(myDataModelXMLReader);
1216 myModule->customizeObjectBrowser(myObjectBrowser);
1217 aObjDock->setWidget(myObjectBrowser);
1219 myContextMenuMgr->connectObjectBrowser();
1223 //******************************************************
1225 * Creates dock widgets, places them in corresponding area
1226 * and tabifies if necessary.
1228 void XGUI_Workshop::createDockWidgets()
1230 QMainWindow* aDesktop = desktop();
1231 QDockWidget* aObjDock = createObjectBrowser(aDesktop);
1232 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
1233 myPropertyPanel = new XGUI_PropertyPanel(aDesktop, myOperationMgr);
1234 myPropertyPanel->setupActions(myActionsMgr);
1235 myPropertyPanel->setAllowedAreas(Qt::LeftDockWidgetArea |
1236 Qt::RightDockWidgetArea |
1237 Qt::BottomDockWidgetArea);
1238 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel);
1239 hidePropertyPanel(); ///<! Invisible by default
1240 hideObjectBrowser();
1241 aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
1242 myPropertyPanel->installEventFilter(myOperationMgr);
1244 QAction* aOkAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept);
1245 connect(aOkAct, SIGNAL(triggered()), this, SLOT(onAcceptActionClicked()));
1247 QAction* aCancelAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Abort);
1248 connect(aCancelAct, SIGNAL(triggered()), myOperationMgr, SLOT(onAbortOperation()));
1250 QAction* aPreviewAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Preview);
1251 connect(aPreviewAct, SIGNAL(triggered()), this, SLOT(onPreviewActionClicked()));
1253 connect(myPropertyPanel, SIGNAL(keyReleased(QObject*, QKeyEvent*)),
1254 myOperationMgr, SLOT(onKeyReleased(QObject*, QKeyEvent*)));
1255 connect(myPropertyPanel, SIGNAL(enterClicked(QObject*)),
1256 myOperationMgr, SLOT(onProcessEnter(QObject*)));
1259 //******************************************************
1260 void XGUI_Workshop::showPropertyPanel()
1262 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1263 ///<! Restore ability to close panel from the window's menu
1264 aViewAct->setEnabled(true);
1265 myPropertyPanel->show();
1266 myPropertyPanel->raise();
1268 // The next code is necessary to made the property panel the active window
1269 // in order to operation manager could process key events of the panel.
1270 // otherwise they are ignored. It happens only if the same(activateWindow) is
1271 // not happened by property panel activation(e.g. resume operation of Sketch)
1272 ModuleBase_Tools::activateWindow(myPropertyPanel, "XGUI_Workshop::showPropertyPanel()");
1273 ModuleBase_Tools::setFocus(myPropertyPanel, "XGUI_Workshop::showPropertyPanel()");
1276 //******************************************************
1277 void XGUI_Workshop::hidePropertyPanel()
1279 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1280 ///<! Do not allow to show empty property panel
1281 aViewAct->setEnabled(false);
1282 myPropertyPanel->hide();
1284 // the property panel is active window of the desktop, when it is
1285 // hidden, it is undefined which window becomes active. By this reason
1286 // it is defined to perform the desktop as the active window.
1287 // in SALOME mode, workstack made the PyConsole the active window,
1288 // set the focus on it. As a result, shortcuts of the application, like
1289 // are processed by this console. For example Undo actions.
1290 // It is possible that this code is to be moved to SHAPER package
1291 QMainWindow* aDesktop = desktop();
1292 ModuleBase_Tools::activateWindow(aDesktop, "XGUI_Workshop::hidePropertyPanel()");
1293 ModuleBase_Tools::setFocus(aDesktop, "XGUI_Workshop::showPropertyPanel()");
1296 //******************************************************
1297 void XGUI_Workshop::showObjectBrowser()
1299 if (!isSalomeMode())
1300 myObjectBrowser->parentWidget()->show();
1303 //******************************************************
1304 void XGUI_Workshop::hideObjectBrowser()
1306 if (!isSalomeMode())
1307 myObjectBrowser->parentWidget()->hide();
1310 //******************************************************
1311 void XGUI_Workshop::salomeViewerSelectionChanged()
1313 emit salomeViewerSelection();
1316 //**************************************************************
1317 ModuleBase_IViewer* XGUI_Workshop::salomeViewer() const
1319 return mySalomeConnector->viewer();
1322 //**************************************************************
1323 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
1325 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1326 if (theId == "DELETE_CMD")
1328 else if (theId == "CLEAN_HISTORY_CMD")
1330 else if (theId == "MOVE_CMD")
1332 else if (theId == "COLOR_CMD")
1333 changeColor(aObjects);
1334 else if (theId == "DEFLECTION_CMD")
1335 changeDeflection(aObjects);
1336 else if (theId == "SHOW_CMD") {
1337 showObjects(aObjects, true);
1338 mySelector->updateSelectionBy(ModuleBase_ISelection::Browser);
1339 updateCommandStatus();
1341 else if (theId == "HIDE_CMD") {
1342 showObjects(aObjects, false);
1343 updateCommandStatus();
1345 else if (theId == "SHOW_ONLY_CMD") {
1346 showOnlyObjects(aObjects);
1347 mySelector->updateSelectionBy(ModuleBase_ISelection::Browser);
1348 updateCommandStatus();
1350 else if (theId == "SHADING_CMD")
1351 setDisplayMode(aObjects, XGUI_Displayer::Shading);
1352 else if (theId == "WIREFRAME_CMD")
1353 setDisplayMode(aObjects, XGUI_Displayer::Wireframe);
1354 else if (theId == "HIDEALL_CMD") {
1355 QObjectPtrList aList = myDisplayer->displayedObjects();
1356 foreach (ObjectPtr aObj, aList) {
1357 if (module()->canEraseObject(aObj))
1358 aObj->setDisplayed(false);
1360 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1361 updateCommandStatus();
1362 } else if (theId == "SELECT_VERTEX_CMD") {
1363 setViewerSelectionMode(TopAbs_VERTEX);
1364 } else if (theId == "SELECT_EDGE_CMD") {
1365 setViewerSelectionMode(TopAbs_EDGE);
1366 } else if (theId == "SELECT_FACE_CMD") {
1367 setViewerSelectionMode(TopAbs_FACE);
1368 } else if (theId == "SELECT_RESULT_CMD") {
1369 //setViewerSelectionMode(-1);
1370 //IMP: an attempt to use result selection with other selection modes
1371 setViewerSelectionMode(ModuleBase_ResultPrs::Sel_Result);
1372 setViewerSelectionMode(TopAbs_COMPSOLID);
1373 } else if (theId == "SHOW_RESULTS_CMD") {
1374 highlightResults(aObjects);
1375 } else if (theId == "SHOW_FEATURE_CMD") {
1376 highlightFeature(aObjects);
1379 else if (theId == "TINSPECTOR_VIEW") {
1380 Handle(CDF_Application) anApplication = CDF_Session::CurrentSession()->CurrentApplication();
1381 if (!anApplication.IsNull())
1383 if (!MyTCommunicator)
1385 MyTCommunicator = new TInspector_Communicator();
1387 NCollection_List<Handle(Standard_Transient)> aParameters;
1388 aParameters.Append(anApplication);
1389 Handle(AIS_InteractiveContext) aContext = viewer()->AISContext();
1390 if (!aContext.IsNull())
1391 aParameters.Append(aContext);
1393 MyVCallBack = new VInspector_CallBack();
1394 myDisplayer->setCallBack(MyVCallBack);
1396 AppElements_Viewer* aViewer = mainWindow()->viewer();
1398 aViewer->setCallBack(MyVCallBack);
1400 aParameters.Append(MyVCallBack);
1402 MyTCommunicator->init(aParameters);
1403 MyTCommunicator->Activate("TKVInspector"); // to have filled callback by model
1404 MyTCommunicator->Activate("TKDFBrowser");
1406 MyTCommunicator->setVisible(true);
1412 //**************************************************************
1413 void XGUI_Workshop::setViewerSelectionMode(int theMode)
1416 myViewerSelMode.clear();
1418 if (myViewerSelMode.contains(theMode))
1419 myViewerSelMode.removeAll(theMode);
1421 myViewerSelMode.append(theMode);
1423 activateObjectsSelection(myDisplayer->displayedObjects());
1426 //**************************************************************
1427 void XGUI_Workshop::activateObjectsSelection(const QObjectPtrList& theList)
1430 module()->activeSelectionModes(aModes);
1431 if (aModes.isEmpty() && (myViewerSelMode.length() > 0))
1432 aModes.append(myViewerSelMode);
1433 myDisplayer->activateObjects(aModes, theList);
1436 //**************************************************************
1437 void XGUI_Workshop::deleteObjects()
1439 ModuleBase_IModule* aModule = module();
1440 // allow the module to delete objects, do nothing if it has succeed
1441 if (aModule->deleteObjects()) {
1442 updateCommandStatus();
1446 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1447 if (!abortAllOperations())
1450 bool hasResult = false;
1451 bool hasFeature = false;
1452 bool hasParameter = false;
1453 bool hasCompositeOwner = false;
1454 ModuleBase_Tools::checkObjects(anObjects, hasResult, hasFeature, hasParameter, hasCompositeOwner);
1455 if (!(hasFeature || hasParameter))
1459 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1460 std::set<FeaturePtr> aFeatures;
1461 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1462 ModelAPI_Tools::findAllReferences(aFeatures, aReferences);
1465 QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text() + " %1";
1466 aDescription = aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
1467 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, module());
1469 operationMgr()->startOperation(anOpAction);
1471 std::set<FeaturePtr> aFeatureRefsToDelete;
1472 if (ModuleBase_Tools::askToDelete(aFeatures, aReferences, desktop(), aFeatureRefsToDelete)) {
1473 // WORKAROUND, should be done before each object remove, if it presents in XGUI_DataModel tree
1474 // It is necessary to clear selection in order to avoid selection changed event during
1475 // deletion and negative consequences connected with processing of already deleted items
1476 mySelector->clearSelection();
1478 if (!aFeatureRefsToDelete.empty())
1479 aFeatures.insert(aFeatureRefsToDelete.begin(), aFeatureRefsToDelete.end());
1480 aDone = ModelAPI_Tools::removeFeatures(aFeatures, false);
1483 operationMgr()->commitOperation();
1485 operationMgr()->abortOperation(operationMgr()->currentOperation());
1488 //**************************************************************
1489 void addRefsToFeature(const FeaturePtr& theFeature,
1490 const std::map<FeaturePtr, std::set<FeaturePtr> >& theMainList,
1491 std::set<FeaturePtr>& theReferences)
1493 //if (theReferences.find(theFeature) != theReferences.end())
1495 if (theMainList.find(theFeature) == theMainList.end())
1496 return; // this feature is not in the selection list, so exists without references to it
1497 std::set<FeaturePtr> aMainReferences = theMainList.at(theFeature);
1499 std::set<FeaturePtr>::const_iterator anIt = aMainReferences.begin(),
1500 aLast = aMainReferences.end();
1501 for (; anIt != aLast; anIt++) {
1502 FeaturePtr aRefFeature = *anIt;
1503 if (theReferences.find(aRefFeature) == theReferences.end())
1504 theReferences.insert(aRefFeature);
1505 addRefsToFeature(aRefFeature, theMainList, theReferences);
1509 //**************************************************************
1510 void XGUI_Workshop::cleanHistory()
1512 if (!abortAllOperations())
1515 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1516 std::set<FeaturePtr> aFeatures;
1517 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1519 #ifdef DEBUG_CLEAN_HISTORY
1521 std::set<FeaturePtr>::const_iterator aFIt;
1522 for (aFIt = aFeatures.begin(); aFIt != aFeatures.end(); ++aFIt) {
1523 FeaturePtr aFeature = ModelAPI_Feature::feature(*aFIt);
1524 anInfo.append(aFeature->name().c_str());
1526 QString anInfoStr = anInfo.join(";\t");
1527 qDebug(QString("cleanHistory for: [%1] - %2").
1528 arg(aFeatures.size()).arg(anInfoStr).toStdString().c_str());
1531 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1532 ModelAPI_Tools::findAllReferences(aFeatures, aReferences, true, false);
1533 // find for each object whether all reference values are in the map as key, that means that there
1534 // is no other reference in the model to this object, so it might be removed by cleaning history
1535 // sk_1(ext_1, vertex_1) + (sk_3, bool_1) - cann't be deleted, dependency to bool_1
1536 // ext_1(bool_1, sk_3) - cann't be deleted, dependency to bool_1
1538 // sk_2(ext_2) + (bool_1) - cann't be deleted, dependency to bool_1
1539 // ext_2(bool_1) - cann't be deleted, dependency to bool_1
1541 // Information: bool_1 is not selected
1542 std::set<FeaturePtr> anUnusedObjects;
1543 std::map<FeaturePtr, std::set<FeaturePtr> >::const_iterator aMainIt = aReferences.begin(),
1544 aMainLast = aReferences.end();
1545 for (; aMainIt != aMainLast; aMainIt++) {
1546 FeaturePtr aMainListFeature = aMainIt->first;
1547 std::set<FeaturePtr> aMainRefList = aMainIt->second;
1548 std::set<FeaturePtr>::const_iterator aRefIt = aMainRefList.begin(),
1549 aRefLast = aMainRefList.end();
1550 bool aFeatureOutOfTheList = false;
1551 for (; aRefIt != aRefLast && !aFeatureOutOfTheList; aRefIt++) {
1552 FeaturePtr aRefFeature = *aRefIt;
1553 aFeatureOutOfTheList = aReferences.find(aRefFeature) == aReferences.end();
1555 if (!aFeatureOutOfTheList)
1556 anUnusedObjects.insert(aMainListFeature);
1559 #ifdef DEBUG_CLEAN_HISTORY
1561 for (aFIt = anUnusedObjects.begin(); aFIt != anUnusedObjects.end(); ++aFIt) {
1562 FeaturePtr aFeature = *aFIt;
1563 anInfo.append(aFeature->name().c_str());
1565 qDebug(QString("unused objects: [%1] - %2").
1566 arg(anInfo.size()).arg(anInfo.join(";\t")).toStdString().c_str());
1569 // warn about the references remove, break the delete operation if the user chose it
1570 if (!anUnusedObjects.empty()) {
1572 foreach (const FeaturePtr& aFeature, anUnusedObjects) {
1573 aNames.append(aFeature->name().c_str());
1576 QString anUnusedNames = aNames.join(", ");
1578 QString anActionId = "CLEAN_HISTORY_CMD";
1579 QString aDescription = contextMenuMgr()->action(anActionId)->text();
1581 QMessageBox aMessageBox(desktop());
1582 aMessageBox.setWindowTitle(aDescription);
1583 aMessageBox.setIcon(QMessageBox::Warning);
1584 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
1585 aMessageBox.setDefaultButton(QMessageBox::No);
1587 const char* aKeyStr = "Unused features are the following: "
1588 "%1.\nThese features will be deleted.\nWould you like to continue?";
1589 QString aText = QString(tr(aKeyStr).arg(anUnusedNames));
1590 aMessageBox.setText(aText);
1591 if (aMessageBox.exec() == QMessageBox::No)
1594 // 1. start operation
1595 aDescription += "by deleting of " +
1596 aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
1597 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, module());
1598 operationMgr()->startOperation(anOpAction);
1600 // WORKAROUND, should be done before each object remove, if it presents in XGUI_DataModel tree
1601 // It is necessary to clear selection in order to avoid selection changed event during
1602 // deletion and negative consequences connected with processing of already deleted items
1603 mySelector->clearSelection();
1605 std::set<FeaturePtr> anIgnoredFeatures;
1606 if (ModelAPI_Tools::removeFeatures(anUnusedObjects, true)) {
1607 operationMgr()->commitOperation();
1610 operationMgr()->abortOperation(operationMgr()->currentOperation());
1614 QString anActionId = "CLEAN_HISTORY_CMD";
1615 QString aDescription = contextMenuMgr()->action(anActionId)->text();
1617 QMessageBox aMessageBox(desktop());
1618 aMessageBox.setWindowTitle(aDescription);
1619 aMessageBox.setIcon(QMessageBox::Warning);
1620 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
1621 aMessageBox.setDefaultButton(QMessageBox::No);
1624 aMessageBox.setStandardButtons(QMessageBox::Ok);
1625 aMessageBox.setDefaultButton(QMessageBox::Ok);
1627 aText = QString(tr("All features are relevant, there is nothing to be deleted"));
1628 aMessageBox.setText(aText);
1630 if (aMessageBox.exec() == QMessageBox::No)
1635 //**************************************************************
1636 void XGUI_Workshop::moveObjects()
1638 if (!abortAllOperations())
1641 SessionPtr aMgr = ModelAPI_Session::get();
1643 QString anActionId = "MOVE_CMD";
1644 QString aDescription = contextMenuMgr()->action(anActionId)->text();
1645 aMgr->startOperation(aDescription.toStdString());
1647 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1648 // It is necessary to clear selection in order to avoid selection changed event during
1649 // moving and negative consequences connected with processing of already moved items
1650 mySelector->clearSelection();
1651 // check whether the object can be moved. There should not be parts which are not loaded
1652 std::set<FeaturePtr> aFeatures;
1653 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1654 if (!XGUI_Tools::canRemoveOrRename(desktop(), aFeatures))
1657 DocumentPtr anActiveDocument = aMgr->activeDocument();
1658 FeaturePtr aCurrentFeature = anActiveDocument->currentFeature(true);
1659 std::set<FeaturePtr>::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
1660 for (; anIt != aLast; anIt++) {
1661 FeaturePtr aFeature = *anIt;
1662 if (!aFeature.get() || !myModule->canApplyAction(aFeature, anActionId))
1665 anActiveDocument->moveFeature(aFeature, aCurrentFeature);
1666 aCurrentFeature = anActiveDocument->currentFeature(true);
1668 aMgr->finishOperation();
1671 //**************************************************************
1672 bool XGUI_Workshop::deleteFeatures(const QObjectPtrList& theObjects)
1674 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1675 std::set<FeaturePtr> aFeatures;
1676 ModuleBase_Tools::convertToFeatures(theObjects, aFeatures);
1678 return ModelAPI_Tools::removeFeaturesAndReferences(aFeatures);
1681 bool hasResults(QObjectPtrList theObjects, const std::set<std::string>& theTypes)
1683 bool isFoundResultType = false;
1684 foreach(ObjectPtr anObj, theObjects)
1686 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
1687 if (aResult.get() == NULL)
1690 isFoundResultType = theTypes.find(aResult->groupName()) != theTypes.end();
1691 if (isFoundResultType)
1694 return isFoundResultType;
1697 //**************************************************************
1698 // Returns the list of all features for theDocument and all features of
1699 // all nested parts.
1700 std::list<FeaturePtr> allFeatures(const DocumentPtr& theDocument)
1702 std::list<FeaturePtr> aResultList;
1703 std::list<FeaturePtr> anAllFeatures = theDocument->allFeatures();
1704 foreach (const FeaturePtr& aFeature, anAllFeatures) {
1705 // The order of appending features of the part and the part itself is important
1707 // Append features from a part feature
1708 std::list<ResultPtr> aResults;
1709 ModelAPI_Tools::allResults(aFeature, aResults);
1710 foreach (const ResultPtr& aResult, aResults) {
1711 ResultPartPtr aResultPart =
1712 std::dynamic_pointer_cast<ModelAPI_ResultPart>(aResult);
1713 if (aResultPart.get() && aResultPart->partDoc().get()) {
1715 std::list<FeaturePtr> anAllFeatures = allFeatures(aResultPart->partDoc());
1716 aResultList.insert(aResultList.end(), anAllFeatures.begin(), anAllFeatures.end());
1720 aResultList.push_back(aFeature);
1725 //**************************************************************
1726 // Returns the list of features placed between theObject and the current feature
1727 // in the same document. Excludes theObject, includes the current feature.
1728 std::list<FeaturePtr> toCurrentFeatures(const ObjectPtr& theObject)
1730 std::list<FeaturePtr> aResult;
1731 DocumentPtr aDocument = theObject->document();
1732 std::list<FeaturePtr> anAllFeatures = allFeatures(aDocument);
1733 // find the object iterator
1734 std::list<FeaturePtr>::iterator aObjectIt =
1735 std::find(anAllFeatures.begin(), anAllFeatures.end(), theObject);
1736 if (aObjectIt == anAllFeatures.end())
1738 // find the current feature iterator
1739 std::list<FeaturePtr>::iterator aCurrentIt =
1740 std::find(anAllFeatures.begin(), anAllFeatures.end(), aDocument->currentFeature(true));
1741 if (aCurrentIt == anAllFeatures.end())
1743 // check the right order
1744 if (std::distance(aObjectIt, anAllFeatures.end()) <=
1745 std::distance(aCurrentIt, anAllFeatures.end()))
1747 // exclude the object
1748 std::advance(aObjectIt, 1);
1749 // include the current feature
1750 std::advance(aCurrentIt, 1);
1751 return std::list<FeaturePtr>(aObjectIt, aCurrentIt);
1754 bool XGUI_Workshop::canMoveFeature()
1756 QString anActionId = "MOVE_CMD";
1758 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1759 QObjectPtrList aValidatedObjects;
1760 foreach (ObjectPtr aObject, aObjects) {
1761 if (!myModule->canApplyAction(aObject, anActionId))
1763 // To be moved feature should be in active document
1764 if (aObject->document() != ModelAPI_Session::get()->activeDocument())
1766 aValidatedObjects.append(aObject);
1768 if (aValidatedObjects.size() != aObjects.size())
1769 aObjects = aValidatedObjects;
1771 bool aCanMove = !aObjects.empty();
1773 QObjectPtrList::const_iterator anIt = aObjects.begin(), aLast = aObjects.end();
1774 for (; anIt != aLast && aCanMove; anIt++) {
1775 ObjectPtr aObject = *anIt;
1776 // 1. Get features placed between selected and current in the document
1777 std::list<FeaturePtr> aFeaturesBetween = toCurrentFeatures(aObject);
1778 // if aFeaturesBetween is empty it means wrong order or aObject is the current feature
1779 if (aFeaturesBetween.empty())
1782 std::set<FeaturePtr> aPlacedFeatures(aFeaturesBetween.begin(), aFeaturesBetween.end());
1783 // 2. Get all reference features to the selected object in the document
1784 std::set<FeaturePtr> aRefFeatures;
1785 ModuleBase_Tools::refsToFeatureInFeatureDocument(aObject, aRefFeatures);
1787 if (aRefFeatures.empty())
1790 // 3. Find any placed features in all reference features
1791 std::set<FeaturePtr> aIntersectionFeatures;
1792 std::set_intersection(aRefFeatures.begin(), aRefFeatures.end(),
1793 aPlacedFeatures.begin(), aPlacedFeatures.end(),
1794 std::inserter(aIntersectionFeatures, aIntersectionFeatures.begin()));
1795 // 4. Return false if any reference feature is placed before current feature
1796 if (!aIntersectionFeatures.empty())
1804 //**************************************************************
1805 bool XGUI_Workshop::canBeShaded(const ObjectPtr& theObject) const
1807 bool aCanBeShaded = myDisplayer->canBeShaded(theObject);
1808 if (!aCanBeShaded) {
1809 ResultCompSolidPtr aCompsolidResult =
1810 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
1811 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
1812 for(int i = 0; i < aCompsolidResult->numberOfSubs() && !aCanBeShaded; i++)
1813 aCanBeShaded = myDisplayer->canBeShaded(aCompsolidResult->subResult(i));
1816 return aCanBeShaded;
1819 //**************************************************************
1820 bool XGUI_Workshop::canChangeColor() const
1822 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1824 std::set<std::string> aTypes;
1825 aTypes.insert(ModelAPI_ResultGroup::group());
1826 aTypes.insert(ModelAPI_ResultConstruction::group());
1827 aTypes.insert(ModelAPI_ResultBody::group());
1828 aTypes.insert(ModelAPI_ResultPart::group());
1830 return hasResults(aObjects, aTypes);
1833 void setColor(ResultPtr theResult, const std::vector<int>& theColor)
1835 if (!theResult.get())
1838 AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
1839 if (aColorAttr.get() != NULL) {
1840 if (!aColorAttr->size()) {
1841 aColorAttr->setSize(3);
1843 aColorAttr->setValue(0, theColor[0]);
1844 aColorAttr->setValue(1, theColor[1]);
1845 aColorAttr->setValue(2, theColor[2]);
1849 //**************************************************************
1850 void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
1853 AttributeIntArrayPtr aColorAttr;
1854 // 1. find the current color of the object. This is a color of AIS presentation
1855 // The objects are iterated until a first valid color is found
1856 std::vector<int> aColor;
1857 foreach(ObjectPtr anObject, theObjects) {
1858 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1859 if (aResult.get()) {
1860 XGUI_CustomPrs::getResultColor(aResult, aColor);
1863 // TODO: remove the obtaining a color from the AIS object
1864 // this does not happen never because:
1865 // 1. The color can be changed only on results
1866 // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
1867 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
1868 if (anAISObj.get()) {
1870 anAISObj->getColor(aColor[0], aColor[1], aColor[2]);
1873 if (!aColor.empty())
1876 if (aColor.size() != 3)
1879 if (!abortAllOperations())
1881 // 2. show the dialog to change the value
1882 XGUI_ColorDialog* aDlg = new XGUI_ColorDialog(desktop());
1883 aDlg->setColor(aColor);
1884 aDlg->move(QCursor::pos());
1885 bool isDone = aDlg->exec() == QDialog::Accepted;
1889 bool isRandomColor = aDlg->isRandomColor();
1891 // 3. abort the previous operation and start a new one
1892 SessionPtr aMgr = ModelAPI_Session::get();
1893 QString aDescription = contextMenuMgr()->action("COLOR_CMD")->text();
1894 aMgr->startOperation(aDescription.toStdString());
1896 // 4. set the value to all results
1897 std::vector<int> aColorResult = aDlg->getColor();
1898 foreach(ObjectPtr anObj, theObjects) {
1899 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
1900 if (aResult.get() != NULL) {
1901 ResultCompSolidPtr aCompsolidResult =
1902 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
1903 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
1904 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
1905 setColor(aCompsolidResult->subResult(i), !isRandomColor ? aColorResult :
1906 aDlg->getRandomColor());
1909 setColor(aResult, !isRandomColor ? aColorResult : aDlg->getRandomColor());
1912 aMgr->finishOperation();
1913 updateCommandStatus();
1916 //**************************************************************
1917 bool XGUI_Workshop::canChangeDeflection() const
1919 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1921 std::set<std::string> aTypes;
1922 aTypes.insert(ModelAPI_ResultGroup::group());
1923 aTypes.insert(ModelAPI_ResultConstruction::group());
1924 aTypes.insert(ModelAPI_ResultBody::group());
1925 aTypes.insert(ModelAPI_ResultPart::group());
1927 return hasResults(aObjects, aTypes);
1930 void setDeflection(ResultPtr theResult, const double theDeflection)
1932 if (!theResult.get())
1935 AttributeDoublePtr aDeflectionAttr = theResult->data()->real(ModelAPI_Result::DEFLECTION_ID());
1936 if (aDeflectionAttr.get() != NULL)
1937 aDeflectionAttr->setValue(theDeflection);
1941 //**************************************************************
1942 void XGUI_Workshop::changeDeflection(const QObjectPtrList& theObjects)
1944 AttributeDoublePtr aDoubleAttr;
1945 // 1. find the current color of the object. This is a color of AIS presentation
1946 // The objects are iterated until a first valid color is found
1947 double aDeflection = -1;
1948 foreach(ObjectPtr anObject, theObjects) {
1949 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1950 if (aResult.get()) {
1951 aDeflection = XGUI_CustomPrs::getResultDeflection(aResult);
1954 // TODO: remove the obtaining a color from the AIS object
1955 // this does not happen never because:
1956 // 1. The color can be changed only on results
1957 // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
1958 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
1959 if (anAISObj.get()) {
1960 aDeflection = anAISObj->getDeflection();
1963 if (aDeflection > 0)
1966 if (aDeflection < 0)
1969 if (!abortAllOperations())
1971 // 2. show the dialog to change the value
1972 XGUI_DeflectionDialog* aDlg = new XGUI_DeflectionDialog(desktop());
1973 aDlg->setDeflection(aDeflection);
1974 aDlg->move(QCursor::pos());
1975 bool isDone = aDlg->exec() == QDialog::Accepted;
1979 // 3. abort the previous operation and start a new one
1980 SessionPtr aMgr = ModelAPI_Session::get();
1981 QString aDescription = contextMenuMgr()->action("DEFLECTION_CMD")->text();
1982 aMgr->startOperation(aDescription.toStdString());
1984 // 4. set the value to all results
1985 aDeflection = aDlg->getDeflection();
1986 foreach(ObjectPtr anObj, theObjects) {
1987 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
1988 if (aResult.get() != NULL) {
1989 ResultCompSolidPtr aCompsolidResult =
1990 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
1991 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
1992 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
1993 setDeflection(aCompsolidResult->subResult(i), aDeflection);
1996 setDeflection(aResult, aDeflection);
1999 aMgr->finishOperation();
2000 updateCommandStatus();
2003 //**************************************************************
2004 #define SET_DISPLAY_GROUP(aGroupName, aDisplay) \
2005 for (int i = 0; i < aDoc->size(aGroupName); i++) { \
2006 aDoc->object(aGroupName, i)->setDisplayed(aDisplay); \
2008 void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible)
2010 foreach (ObjectPtr aObj, theList) {
2011 aObj->setDisplayed(isVisible);
2013 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2016 //**************************************************************
2017 void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList)
2019 // Hide all displayed objects
2020 QObjectPtrList aList = myDisplayer->displayedObjects();
2021 foreach (ObjectPtr aObj, aList) {
2022 if (module()->canEraseObject(aObj))
2023 aObj->setDisplayed(false);
2026 // Show only objects from the list
2027 foreach (ObjectPtr aObj, theList) {
2028 aObj->setDisplayed(true);
2030 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2034 //**************************************************************
2035 void XGUI_Workshop::registerValidators() const
2037 SessionPtr aMgr = ModelAPI_Session::get();
2038 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
2041 //**************************************************************
2042 void XGUI_Workshop::displayDocumentResults(DocumentPtr theDoc)
2046 displayGroupResults(theDoc, ModelAPI_ResultConstruction::group());
2047 displayGroupResults(theDoc, ModelAPI_ResultBody::group());
2050 //**************************************************************
2051 void XGUI_Workshop::displayGroupResults(DocumentPtr theDoc, std::string theGroup)
2053 for (int i = 0; i < theDoc->size(theGroup); i++)
2054 theDoc->object(theGroup, i)->setDisplayed(true);
2055 //displayObject(theDoc->object(theGroup, i));
2056 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2059 //**************************************************************
2060 void XGUI_Workshop::setDisplayMode(const QObjectPtrList& theList, int theMode)
2062 foreach(ObjectPtr aObj, theList) {
2063 myDisplayer->setDisplayMode(aObj, (XGUI_Displayer::DisplayMode)theMode, false);
2065 ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aObj);
2066 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
2067 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
2068 myDisplayer->setDisplayMode(aCompsolidResult->subResult(i),
2069 (XGUI_Displayer::DisplayMode)theMode, false);
2073 if (theList.size() > 0)
2074 myDisplayer->updateViewer();
2077 //**************************************************************
2078 void XGUI_Workshop::closeDocument()
2080 ModuleBase_Operation* anOperation = operationMgr()->currentOperation();
2081 while (anOperation) {
2082 anOperation->abort();
2083 anOperation = operationMgr()->currentOperation();
2085 //myDisplayer->closeLocalContexts();
2086 myDisplayer->eraseAll();
2087 objectBrowser()->clearContent();
2089 module()->closeDocument();
2091 // data model need not process the document's signals about objects modifications as
2092 // the document is closed
2093 //bool isBlocked = objectBrowser()->dataModel()->blockEventsProcessing(true);
2095 SessionPtr aMgr = ModelAPI_Session::get();
2098 //objectBrowser()->dataModel()->blockEventsProcessing(isBlocked);
2101 void XGUI_Workshop::addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot)
2103 XGUI_HistoryMenu* aMenu = NULL;
2104 if (isSalomeMode()) {
2105 QAction* anAction = qobject_cast<QAction*>(theObject);
2108 aMenu = new XGUI_HistoryMenu(anAction);
2110 QToolButton* aButton = qobject_cast<QToolButton*>(theObject);
2111 aMenu = new XGUI_HistoryMenu(aButton);
2113 connect(this, theSignal, aMenu, SLOT(setHistory(const QList<ActionInfo>&)));
2114 connect(aMenu, SIGNAL(actionSelected(int)), this, theSlot);
2117 QList<ActionInfo> XGUI_Workshop::processHistoryList(const std::list<std::string>& theList) const
2119 QList<ActionInfo> aResult;
2120 std::list<std::string>::const_iterator it = theList.cbegin();
2121 for (; it != theList.cend(); it++) {
2122 QString anId = QString::fromStdString(*it);
2123 bool isEditing = anId.endsWith(ModuleBase_OperationFeature::EditSuffix());
2125 anId.chop(ModuleBase_OperationFeature::EditSuffix().size());
2128 QAction* aContextMenuAct = myContextMenuMgr->actionByName(anId);
2129 if (aContextMenuAct) {
2130 anInfo.initFrom(aContextMenuAct);
2132 anInfo = myActionsMgr->actionInfoById(anId);
2135 anInfo.text = anInfo.text.prepend("Modify ");
2142 void XGUI_Workshop::setStatusBarMessage(const QString& theMessage)
2145 salomeConnector()->putInfo(theMessage, -1);
2147 myMainWindow->putInfo(theMessage, -1);
2151 void XGUI_Workshop::synchronizeViewer()
2153 SessionPtr aMgr = ModelAPI_Session::get();
2154 DocumentPtr aDoc = aMgr->activeDocument();
2156 synchronizeGroupInViewer(aDoc, ModelAPI_ResultConstruction::group(), false);
2157 synchronizeGroupInViewer(aDoc, ModelAPI_ResultBody::group(), false);
2158 synchronizeGroupInViewer(aDoc, ModelAPI_ResultPart::group(), false);
2159 synchronizeGroupInViewer(aDoc, ModelAPI_ResultGroup::group(), false);
2162 void XGUI_Workshop::synchronizeGroupInViewer(const DocumentPtr& theDoc,
2163 const std::string& theGroup,
2164 bool theUpdateViewer)
2167 int aSize = theDoc->size(theGroup);
2168 for (int i = 0; i < aSize; i++) {
2169 aObj = theDoc->object(theGroup, i);
2170 if (aObj->isDisplayed()) {
2171 // Hide the presentation with an empty shape. But isDisplayed state of the object should not
2172 // be changed to the object becomes visible when the shape becomes not empty
2173 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
2174 if (aRes.get() && (!aRes->shape().get() || aRes->shape()->isNull()))
2176 myDisplayer->display(aObj, false);
2179 if (theUpdateViewer)
2180 myDisplayer->updateViewer();
2183 void XGUI_Workshop::highlightResults(const QObjectPtrList& theObjects)
2185 FeaturePtr aFeature;
2186 QObjectPtrList aSelList = theObjects;
2187 bool aHasHidden = false;
2188 foreach(ObjectPtr aObj, theObjects) {
2189 aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
2190 if (aFeature.get()) {
2191 std::list<ResultPtr> aResults;
2192 ModelAPI_Tools::allResults(aFeature, aResults);
2193 std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aIt;
2194 for(aIt = aResults.cbegin(); aIt != aResults.cend(); aIt++) {
2195 aHasHidden |= (*aIt)->isConcealed();
2196 aSelList.append(*aIt);
2200 if (aSelList.count() > theObjects.count()) {
2201 // if something was found
2202 bool aBlocked = objectBrowser()->blockSignals(true);
2203 objectBrowser()->setObjectsSelected(aSelList);
2204 objectBrowser()->blockSignals(aBlocked);
2207 QMessageBox::information(desktop(), tr("Find results"),
2208 tr("Results not found"), QMessageBox::Ok);
2211 void XGUI_Workshop::highlightFeature(const QObjectPtrList& theObjects)
2214 QObjectPtrList aSelList = theObjects;
2215 FeaturePtr aFeature;
2216 foreach(ObjectPtr aObj, theObjects) {
2217 aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
2218 if (aResult.get()) {
2219 aFeature = ModelAPI_Feature::feature(aResult);
2220 if (aFeature.get()) {
2221 aSelList.append(aFeature);
2225 if (aSelList.count() > theObjects.count()) {
2226 // if something was found
2227 bool aBlocked = objectBrowser()->blockSignals(true);
2228 objectBrowser()->setObjectsSelected(aSelList);
2229 objectBrowser()->blockSignals(aBlocked);