1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "XGUI_Workshop.h"
23 #include "XGUI_ActionsMgr.h"
24 #include "XGUI_MenuMgr.h"
25 #include "XGUI_ColorDialog.h"
26 #include "XGUI_DeflectionDialog.h"
27 #include "XGUI_ContextMenuMgr.h"
28 #include "XGUI_Displayer.h"
29 #include "XGUI_ErrorDialog.h"
30 #include "XGUI_ErrorMgr.h"
31 #include "XGUI_ModuleConnector.h"
32 #include "XGUI_ObjectsBrowser.h"
33 #include "XGUI_OperationMgr.h"
34 #include "XGUI_PropertyPanel.h"
35 #include "XGUI_SalomeConnector.h"
36 #include "XGUI_Selection.h"
37 #include "XGUI_SelectionMgr.h"
38 #include "XGUI_Tools.h"
39 #include "XGUI_ViewerProxy.h"
40 #include "XGUI_WorkshopListener.h"
41 #include <XGUI_CustomPrs.h>
42 #include <XGUI_HistoryMenu.h>
43 #include <XGUI_QtEvents.h>
44 #include <XGUI_DataModel.h>
47 #include <AppElements_Button.h>
48 #include <AppElements_Command.h>
49 #include <AppElements_MainMenu.h>
50 #include <AppElements_MainWindow.h>
51 #include <AppElements_MenuGroupPanel.h>
52 #include <AppElements_Viewer.h>
53 #include <AppElements_Workbench.h>
56 #include <ModelAPI_AttributeDocRef.h>
57 #include <ModelAPI_AttributeIntArray.h>
58 #include <ModelAPI_AttributeDouble.h>
59 #include <ModelAPI_Data.h>
60 #include <ModelAPI_Events.h>
61 #include <ModelAPI_Feature.h>
62 #include <ModelAPI_Object.h>
63 #include <ModelAPI_ResultBody.h>
64 #include <ModelAPI_ResultConstruction.h>
65 #include <ModelAPI_ResultGroup.h>
66 #include <ModelAPI_ResultParameter.h>
67 #include <ModelAPI_ResultField.h>
68 #include <ModelAPI_Session.h>
69 #include <ModelAPI_Validator.h>
70 #include <ModelAPI_ResultCompSolid.h>
71 #include <ModelAPI_Tools.h>
73 //#include <PartSetPlugin_Part.h>
75 #include <Events_Loop.h>
76 #include <Events_InfoMessage.h>
77 #include <Events_LongOp.h>
79 #include <ModuleBase_IModule.h>
80 #include <ModuleBase_IViewer.h>
81 #include <ModuleBase_Operation.h>
82 #include <ModuleBase_OperationDescription.h>
83 #include <ModuleBase_PageBase.h>
84 #include <ModuleBase_Preferences.h>
85 #include <ModuleBase_SelectionValidator.h>
86 #include <ModuleBase_Tools.h>
87 #include <ModuleBase_WidgetFactory.h>
88 #include <ModuleBase_OperationFeature.h>
89 #include <ModuleBase_OperationAction.h>
90 #include <ModuleBase_PagedContainer.h>
91 #include <ModuleBase_WidgetValidated.h>
92 #include <ModuleBase_ModelWidget.h>
93 #include <ModuleBase_ResultPrs.h>
95 #include <Config_Common.h>
96 #include <Config_FeatureMessage.h>
97 #include <Config_ModuleReader.h>
98 #include <Config_PointerMessage.h>
99 #include <Config_PropManager.h>
100 #include <Config_DataModelReader.h>
101 #include <Config_Translator.h>
102 #include <Config_WidgetAPI.h>
103 #include <Config_Keywords.h>
105 #include <SUIT_ResourceMgr.h>
107 #include <AIS_Trihedron.hxx>
108 #ifdef BEFORE_TRIHEDRON_PATCH
109 #include <AIS_Point.hxx>
110 #include <AIS_Axis.hxx>
113 #include <QApplication>
114 #include <QFileDialog>
115 #include <QMessageBox>
116 #include <QMdiSubWindow>
117 #include <QMainWindow>
118 #include <QPushButton>
119 #include <QDockWidget>
124 #include <QToolButton>
126 #include <QDesktopWidget>
131 #include <CDF_Session.hxx>
132 #include <CDF_Application.hxx>
133 #include <TInspector_Communicator.hxx>
134 #include <VInspector_CallBack.hxx>
135 static TInspector_Communicator* MyTCommunicator;
136 static Handle(VInspector_CallBack) MyVCallBack;
151 QString XGUI_Workshop::MOVE_TO_END_COMMAND = QObject::tr("Move to the end");
153 //#define DEBUG_DELETE
154 //#define DEBUG_FEATURE_NAME
155 //#define DEBUG_CLEAN_HISTORY
157 XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
159 myCurrentDir(QString()),
161 mySalomeConnector(theConnector),
165 //myViewerSelMode(TopAbs_FACE)
167 mySelector = new XGUI_SelectionMgr(this);
168 myModuleConnector = new XGUI_ModuleConnector(this);
169 myOperationMgr = new XGUI_OperationMgr(this, 0);
170 ModuleBase_IWorkshop* aWorkshop = moduleConnector();
171 // Has to be defined first in order to get errors and messages from other components
172 myEventsListener = new XGUI_WorkshopListener(aWorkshop);
174 SUIT_ResourceMgr* aResMgr = ModuleBase_Preferences::resourceMgr();
176 myMainWindow = new AppElements_MainWindow();
178 bool aCloc = aResMgr->booleanValue("language", "locale", true);
180 QLocale::setDefault( QLocale::c() );
182 QLocale::setDefault( QLocale::system() );
184 QString aPath = Config_XMLReader::pluginConfigFile().c_str();
189 aLangs << "*_en.ts"; // load by default eng translations
190 QString aCurrLang = aResMgr->stringValue("language", "language", "en");
191 if(aCurrLang != "en") {
192 aLangs << "*_" + aCurrLang + ".ts"; // then replace with translated files
195 foreach(QString aLang, aLangs) {
196 QStringList aFilters;
198 QStringList aTsFiles = aDir.entryList(aFilters, QDir::Files);
199 foreach(QString aFileName, aTsFiles) {
200 Config_Translator::load(aFileName.toStdString());
204 myDataModelXMLReader = new Config_DataModelReader();
205 //myDataModelXMLReader->readAll();
207 myDisplayer = new XGUI_Displayer(this);
209 connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(updateCommandStatus()));
211 myActionsMgr = new XGUI_ActionsMgr(this);
212 myMenuMgr = new XGUI_MenuMgr(this);
213 myErrorDlg = new XGUI_ErrorDialog(QApplication::desktop());
214 myContextMenuMgr = new XGUI_ContextMenuMgr(this);
215 connect(myContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), this,
216 SLOT(onContextMenuCommand(const QString&, bool)));
218 myViewerProxy = new XGUI_ViewerProxy(this);
219 //connect(myViewerProxy, SIGNAL(selectionChanged()),
220 // myActionsMgr, SLOT(updateOnViewSelection()));
222 myOperationMgr->setWorkshop(aWorkshop);
224 myErrorMgr = new XGUI_ErrorMgr(this, aWorkshop);
226 connect(myOperationMgr, SIGNAL(operationResumed(ModuleBase_Operation*)),
227 SLOT(onOperationResumed(ModuleBase_Operation*)));
228 connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
229 SLOT(onOperationStopped(ModuleBase_Operation*)));
230 connect(myOperationMgr, SIGNAL(operationCommitted(ModuleBase_Operation*)),
231 SLOT(onOperationCommitted(ModuleBase_Operation*)));
232 connect(myOperationMgr, SIGNAL(operationAborted(ModuleBase_Operation*)),
233 SLOT(onOperationAborted(ModuleBase_Operation*)));
236 connect(myMainWindow, SIGNAL(exitKeySequence()), SLOT(onExit()));
237 onTrihedronVisibilityChanged(true);
240 connect(myEventsListener, SIGNAL(errorOccurred(std::shared_ptr<Events_InfoMessage>)),
241 myErrorDlg, SLOT(addError(std::shared_ptr<Events_InfoMessage>)));
243 //Config_PropManager::registerProp("Visualization", "object_default_color", "Object color",
244 // Config_Prop::Color, "225,225,225");
246 Config_PropManager::registerProp("Visualization", "result_body_color", "Result color",
247 Config_Prop::Color, ModelAPI_ResultBody::DEFAULT_COLOR());
248 Config_PropManager::registerProp("Visualization", "result_group_color", "Group color",
249 Config_Prop::Color, ModelAPI_ResultGroup::DEFAULT_COLOR());
250 Config_PropManager::registerProp("Visualization", "result_construction_color",
251 "Construction color",
253 ModelAPI_ResultConstruction::DEFAULT_COLOR());
254 Config_PropManager::registerProp("Visualization", "result_part_color", "Part color",
255 Config_Prop::Color, ModelAPI_ResultPart::DEFAULT_COLOR());
256 Config_PropManager::registerProp("Visualization", "result_field_color", "Field color",
257 Config_Prop::Color, ModelAPI_ResultField::DEFAULT_COLOR());
259 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "face-selection", true))
260 myViewerSelMode.append(TopAbs_FACE);
261 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "edge-selection", true))
262 myViewerSelMode.append(TopAbs_EDGE);
263 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "vertex-selection", true))
264 myViewerSelMode.append(TopAbs_VERTEX);
265 //IMP: an attempt to use result selection with other selection modes
266 myViewerSelMode.append(ModuleBase_ResultPrs::Sel_Result);//TopAbs_VERTEX);
267 myViewerSelMode.append(TopAbs_COMPSOLID);
270 //******************************************************
271 XGUI_Workshop::~XGUI_Workshop(void)
274 #ifdef MISSED_TRANSLATION
275 // Save Missed translations
276 Config_Translator::saveMissedTranslations();
281 delete myDataModelXMLReader;
284 //******************************************************
285 void XGUI_Workshop::startApplication()
287 //Initialize event listening
288 myEventsListener->initializeEventListening();
290 myDataModelXMLReader->readAll();
293 Config_PropManager::registerProp("Plugins", "default_path", "Default Path",
294 Config_Prop::Directory, "");
297 registerValidators();
299 // Calling of loadCustomProps before activating module is required
300 // by Config_PropManger to restore user-defined path to plugins
301 ModuleBase_Preferences::loadCustomProps();
305 myMainWindow->show();
306 updateCommandStatus();
311 myViewerProxy->connectViewProxy();
312 connect(myViewerProxy, SIGNAL(trihedronVisibilityChanged(bool)),
313 SLOT(onTrihedronVisibilityChanged(bool)));
315 emit applicationStarted();
318 void XGUI_Workshop::activateModule()
320 myModule->activateSelectionFilters();
322 connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
323 myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
324 connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
325 myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
327 updateCommandStatus();
329 // TODO: get default selection mode
331 // activate visualized objects in the viewer
332 activateObjectsSelection(displayer()->displayedObjects());
333 myOperationMgr->activate();
336 void XGUI_Workshop::deactivateModule()
338 myModule->deactivateSelectionFilters();
340 // remove internal displayer filter
341 displayer()->deactivateSelectionFilters();
343 disconnect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
344 myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
345 disconnect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
346 myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
348 XGUI_Displayer* aDisplayer = displayer();
349 QObjectPtrList aDisplayed = aDisplayer->displayedObjects();
350 aDisplayer->deactivateObjects(aDisplayed, true);
351 Handle(AIS_InteractiveContext) aContext = viewer()->AISContext();
352 Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(aDisplayer->getTrihedron());
353 /// deactivate trihedron in selection modes
354 TColStd_ListOfInteger aTColModes;
355 aContext->ActivatedModes(aTrihedron, aTColModes);
356 TColStd_ListIteratorOfListOfInteger itr( aTColModes );
357 for (; itr.More(); itr.Next() ) {
358 Standard_Integer aMode = itr.Value();
359 aContext->Deactivate(aTrihedron, aMode);
361 #ifdef BEFORE_TRIHEDRON_PATCH
362 /// Trihedron problem: objects stayed in the viewer, should be removed manually
363 /// otherwise in SALOME happens crash by HideAll in the viewer
364 aContext->Remove(aTrihedron->Position(), true);
365 aContext->Remove(aTrihedron->Axis(), true);
366 aContext->Remove(aTrihedron->XAxis(), true);
367 aContext->Remove(aTrihedron->YAxis(), true);
370 myOperationMgr->deactivate();
373 //******************************************************
374 void XGUI_Workshop::initMenu()
376 myContextMenuMgr->createActions();
379 // Create only Undo, Redo commands
380 QAction* aAction = salomeConnector()->addDesktopCommand("UNDO_CMD", tr("Undo"),
381 tr("Undo last command"),
382 QIcon(":pictures/undo.png"),
383 QKeySequence::Undo, false,
385 QString aToolBarTitle = tr( "INF_DESK_TOOLBAR_STANDARD" );
386 salomeConnector()->addActionInToolbar( aAction,aToolBarTitle );
388 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onUndo()));
389 addHistoryMenu(aAction, SIGNAL(updateUndoHistory(const QList<ActionInfo>&)), SLOT(onUndo(int)));
391 aAction = salomeConnector()->addDesktopCommand("REDO_CMD", tr("Redo"), tr("Redo last command"),
392 QIcon(":pictures/redo.png"), QKeySequence::Redo,
393 false, "MEN_DESK_EDIT");
394 salomeConnector()->addActionInToolbar( aAction, aToolBarTitle );
396 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo()));
397 addHistoryMenu(aAction, SIGNAL(updateRedoHistory(const QList<ActionInfo>&)), SLOT(onRedo(int)));
399 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
400 //aAction = salomeConnector()->addDesktopCommand("REBUILD_CMD", tr("Rebuild"),
401 // tr("Rebuild data objects"),
402 // QIcon(":pictures/rebuild.png"), QKeySequence(),
403 // false, "MEN_DESK_EDIT");
404 //salomeConnector()->addActionInToolbar( aAction, aToolBarTitle );
406 //connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRebuild()));
407 //salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
409 aAction = salomeConnector()->addDesktopCommand("SAVEAS_CMD", tr("Export native..."),
410 tr("Export the current document into a native file"),
411 QIcon(), QKeySequence(),
412 false, "MEN_DESK_FILE");
413 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onSaveAs()));
415 aAction = salomeConnector()->addDesktopCommand("OPEN_CMD", tr("Import native..."),
416 tr("Import native file"),
417 QIcon(), QKeySequence(),
418 false, "MEN_DESK_FILE");
419 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onOpen()));
420 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_FILE");
423 // File commands group
424 AppElements_MenuGroupPanel* aGroup = myMainWindow->menuObject()->generalPage();
426 AppElements_Command* aCommand;
428 aCommand = aGroup->addFeature("SAVE_CMD", tr("Save"), tr("Save the document"),
429 QIcon(":pictures/save.png"), QKeySequence::Save);
430 aCommand->connectTo(this, SLOT(onSave()));
431 //aCommand->disable();
433 aCommand = aGroup->addFeature("SAVEAS_CMD", tr("Save as..."), tr("Save the document into a file"),
434 QIcon(":pictures/save.png"), QKeySequence());
435 aCommand->connectTo(this, SLOT(onSaveAs()));
437 QString aUndoId = "UNDO_CMD";
438 aCommand = aGroup->addFeature(aUndoId, tr("Undo"), tr("Undo last command"),
439 QIcon(":pictures/undo.png"), QKeySequence::Undo);
440 aCommand->connectTo(this, SLOT(onUndo()));
441 AppElements_Button* aUndoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aUndoId));
442 addHistoryMenu(aUndoButton,
443 SIGNAL(updateUndoHistory(const QList<ActionInfo>&)),
446 QString aRedoId = "REDO_CMD";
447 aCommand = aGroup->addFeature(aRedoId, tr("Redo"), tr("Redo last command"),
448 QIcon(":pictures/redo.png"), QKeySequence::Redo);
449 aCommand->connectTo(this, SLOT(onRedo()));
450 AppElements_Button* aRedoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aRedoId));
451 addHistoryMenu(aRedoButton,
452 SIGNAL(updateRedoHistory(const QList<ActionInfo>&)),
455 //aCommand = aGroup->addFeature("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
456 // QIcon(":pictures/rebuild.png"), QKeySequence());
457 //aCommand->connectTo(this, SLOT(onRebuild()));
459 //aCommand->disable();
461 aCommand = aGroup->addFeature("OPEN_CMD", tr("Open..."), tr("Open a new document"),
462 QIcon(":pictures/open.png"), QKeySequence::Open);
463 aCommand->connectTo(this, SLOT(onOpen()));
465 aCommand = aGroup->addFeature("PREF_CMD", tr("Preferences"), tr("Edit preferences"),
466 QIcon(":pictures/preferences.png"), QKeySequence::Preferences);
467 aCommand->connectTo(this, SLOT(onPreferences()));
469 aCommand = aGroup->addFeature("EXIT_CMD", tr("Exit"), tr("Exit application"),
470 QIcon(":pictures/close.png"), QKeySequence::Close);
471 aCommand->connectTo(this, SLOT(onExit()));
476 AppElements_Workbench* XGUI_Workshop::addWorkbench(const QString& theName)
478 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
479 return aMenuBar->addWorkbench(theName);
483 //******************************************************
484 QMainWindow* XGUI_Workshop::desktop() const
487 return salomeConnector()->desktop();
493 //******************************************************
494 void XGUI_Workshop::onStartWaiting()
496 if (Events_LongOp::isPerformed()) {
497 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
501 //******************************************************
502 void XGUI_Workshop::onAcceptActionClicked()
504 QAction* anAction = dynamic_cast<QAction*>(sender());
505 XGUI_OperationMgr* anOperationMgr = operationMgr();
506 if (anOperationMgr) {
507 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
508 (anOperationMgr->currentOperation());
510 //if (errorMgr()->canProcessClick(anAction, aFOperation->feature()))
511 myOperationMgr->commitOperation();
516 //******************************************************
517 void XGUI_Workshop::onPreviewActionClicked()
519 ModuleBase_IPropertyPanel* aPanel = propertyPanel();
521 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
522 if (anActiveWidget && anActiveWidget->getValueState() == ModuleBase_ModelWidget::ModifiedInPP) {
523 anActiveWidget->storeValue();
526 std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
527 new Events_Message(Events_Loop::eventByName(EVENT_PREVIEW_REQUESTED)));
528 Events_Loop::loop()->send(aMsg);
531 //******************************************************
532 void XGUI_Workshop::deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer)
534 if (!myModule->canActivateSelection(theObject)) {
535 if (myDisplayer->isActive(theObject)) {
536 QObjectPtrList anObjects;
537 anObjects.append(theObject);
538 myDisplayer->deactivateObjects(anObjects, theUpdateViewer);
543 //******************************************************
544 bool XGUI_Workshop::isFeatureOfNested(const FeaturePtr& theFeature)
546 bool aHasNested = false;
547 std::string aFeatureKind = theFeature->getKind();
549 XGUI_SalomeConnector* aSalomeConnector = salomeConnector();
550 if (aSalomeConnector->isFeatureOfNested(actionsMgr()->action(aFeatureKind.c_str())))
553 AppElements_MainMenu* aMenuBar = mainWindow()->menuObject();
554 AppElements_Command* aCommand = aMenuBar->feature(aFeatureKind.c_str());
555 if (aCommand && aCommand->button()->additionalButtonWidget())
561 void XGUI_Workshop::fillPropertyPanel(ModuleBase_Operation* theOperation)
563 ModuleBase_OperationFeature* aFOperation =
564 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
569 myPropertyPanel->cleanContent();
571 QList<ModuleBase_ModelWidget*> aWidgets;
572 if (!module()->createWidgets(theOperation, aWidgets)) {
573 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
574 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), myModuleConnector);
575 aFactory.createWidget(myPropertyPanel->contentWidget());
576 aWidgets = aFactory.getModelWidgets();
579 // check compatibility of feature and widgets
580 FeaturePtr aFeature = aFOperation->feature();
581 std::string aFeatureKind = aFeature->getKind();
582 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
583 if (!aWidget->attributeID().empty() && !aFeature->attribute(aWidget->attributeID()).get()) {
584 std::string anErrorMsg = "The feature '%1' has no attribute '%2' used by widget '%3'.";
585 Events_InfoMessage("XGUI_Workshop", anErrorMsg)
586 .arg(aFeatureKind).arg(aWidget->attributeID())
587 .arg(aWidget->metaObject()->className()).send();
588 myPropertyPanel->cleanContent();
592 // for performance purpose, flush should be done after all controls are filled
593 bool isUpdateFlushed = false;
594 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
595 bool isStoreValue = !aFOperation->isEditOperation() &&
596 !aWidget->getDefaultValue().empty() &&
597 !aWidget->isComputedDefault();
598 aWidget->setFeature(aFeature, isStoreValue, isUpdateFlushed);
600 aWidget->restoreValue();
601 aWidget->enableFocusProcessing();
603 ModuleBase_Tools::flushUpdated(aFeature);
605 // update visible state of Preview button
606 std::shared_ptr<Config_FeatureMessage> aFeatureInfo;
608 aFeatureInfo = mySalomeConnector->featureInfo(aFeatureKind.c_str());
610 AppElements_MainMenu* aMenuBar = mainWindow()->menuObject();
611 AppElements_Command* aCommand = aMenuBar->feature(aFeatureKind.c_str());
613 aFeatureInfo = aCommand->featureMessage();
615 bool anIsAutoPreview = true;
616 if (aFeatureInfo.get())
617 anIsAutoPreview = aFeatureInfo->isAutoPreview();
619 std::string aXmlCfg, aDescription;
620 module()->getXMLRepresentation(aFeatureKind, aXmlCfg, aDescription);
621 ModuleBase_WidgetFactory aFactory(aXmlCfg, moduleConnector());
622 anIsAutoPreview = aFactory.widgetAPI()->getBooleanAttribute(FEATURE_AUTO_PREVIEW, true);
625 if (!anIsAutoPreview) {
626 myPropertyPanel->findButton(PROP_PANEL_PREVIEW)->setVisible(true);
627 // send signal about preview should not be computed automatically, click on preview
628 // button should initiate it
629 std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
630 new Events_Message(Events_Loop::eventByName(EVENT_PREVIEW_BLOCKED)));
631 Events_Loop::loop()->send(aMsg);
633 myPropertyPanel->setModelWidgets(aWidgets);
634 aFOperation->setPropertyPanel(myPropertyPanel);
636 myModule->propertyPanelDefined(theOperation);
638 #ifndef DEBUG_FEATURE_NAME
639 myPropertyPanel->setWindowTitle(theOperation->getDescription()->description());
641 std::string aFeatureName = aFeature->name();
642 myPropertyPanel->setWindowTitle(QString("%1: %2")
643 .arg(theOperation->getDescription()->description())
644 .arg(aFeatureName.c_str()));
647 myErrorMgr->setPropertyPanel(myPropertyPanel);
650 void XGUI_Workshop::connectToPropertyPanel(const bool isToConnect)
652 XGUI_PropertyPanel* aPropertyPanel = propertyPanel();
653 if (aPropertyPanel) {
654 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
655 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
656 myModule->connectToPropertyPanel(aWidget, isToConnect);
658 connect(aWidget, SIGNAL(valueStateChanged(int)), this, SLOT(onWidgetStateChanged(int)));
659 connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
660 connect(aWidget, SIGNAL(objectUpdated()), this, SLOT(onWidgetObjectUpdated()));
663 disconnect(aWidget, SIGNAL(valueStateChanged(int)), this, SLOT(onWidgetStateChanged(int)));
664 disconnect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
665 disconnect(aWidget, SIGNAL(objectUpdated()), this, SLOT(onWidgetObjectUpdated()));
671 //******************************************************
672 void XGUI_Workshop::onOperationResumed(ModuleBase_Operation* theOperation)
674 setGrantedFeatures(theOperation);
676 if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
677 fillPropertyPanel(theOperation);
678 connectToPropertyPanel(true);
680 updateCommandStatus();
682 myModule->operationResumed(theOperation);
686 //******************************************************
687 void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
689 updateCommandStatus();
691 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
696 ModuleBase_ISelection* aSel = mySelector->selection();
697 QObjectPtrList aObj = aSel->selectedPresentations();
698 //!< No need for property panel
700 myPropertyPanel->cleanContent();
702 connectToPropertyPanel(false);
703 myModule->operationStopped(aFOperation);
705 // the deactivated objects of the current operation should be activated back.
706 // They were deactivated on operation start or an object redisplay
707 QObjectPtrList anObjects;
708 FeaturePtr aFeature = aFOperation->feature();
709 if (aFeature.get()) { // feature may be not created (plugin load fail)
710 if (myDisplayer->isVisible(aFeature) && !myDisplayer->isActive(aFeature))
711 anObjects.append(aFeature);
712 std::list<ResultPtr> aResults;
713 ModelAPI_Tools::allResults(aFeature, aResults);
714 std::list<ResultPtr>::const_iterator aIt;
715 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
716 ResultPtr anObject = *aIt;
717 if (myDisplayer->isVisible(anObject) && !myDisplayer->isActive(anObject)) {
718 anObjects.append(anObject);
722 activateObjectsSelection(anObjects);
726 void XGUI_Workshop::onOperationCommitted(ModuleBase_Operation* theOperation)
728 myModule->operationCommitted(theOperation);
731 void XGUI_Workshop::onOperationAborted(ModuleBase_Operation* theOperation)
733 myModule->operationAborted(theOperation);
736 void XGUI_Workshop::setGrantedFeatures(ModuleBase_Operation* theOperation)
738 ModuleBase_OperationFeature* aFOperation =
739 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
743 QStringList aGrantedIds;
744 if (isSalomeMode()) {
745 const std::shared_ptr<Config_FeatureMessage>& anInfo =
746 mySalomeConnector->featureInfo(theOperation->id());
748 aGrantedIds = QString::fromStdString(anInfo->nestedFeatures())
749 .split(" ", QString::SkipEmptyParts);
752 aGrantedIds = myActionsMgr->nestedCommands(theOperation->id());
754 ModuleBase_IModule* aModule = module();
756 aModule->grantedOperationIds(theOperation, aGrantedIds);
758 aFOperation->setGrantedOperationIds(aGrantedIds);
761 //******************************************************
762 void XGUI_Workshop::saveDocument(const QString& theName, std::list<std::string>& theFileNames)
764 QApplication::restoreOverrideCursor();
765 SessionPtr aMgr = ModelAPI_Session::get();
767 std::list<DocumentPtr> aDocList = aMgr->allOpenedDocuments();
768 std::list<DocumentPtr>::const_iterator aIt;
769 for (aIt = aDocList.cbegin(); aIt != aDocList.cend(); aIt++) {
770 std::list<bool> aState = myObjectBrowser->getStateForDoc(*aIt);
771 (*aIt)->storeNodesState(aState);
774 aMgr->save(theName.toLatin1().constData(), theFileNames);
776 QApplication::restoreOverrideCursor();
779 //******************************************************
780 bool XGUI_Workshop::abortAllOperations()
782 return myOperationMgr->abortAllOperations();
785 //******************************************************
786 void XGUI_Workshop::operationStarted(ModuleBase_Operation* theOperation)
788 setGrantedFeatures(theOperation);
789 if (!theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
790 updateCommandStatus();
793 myModule->operationStarted(theOperation);
797 //******************************************************
798 void XGUI_Workshop::onOpen()
800 if(!abortAllOperations())
802 //save current file before close if modified
803 SessionPtr aSession = ModelAPI_Session::get();
804 if (aSession->isModified()) {
805 //TODO(sbh): re-launch the app?
806 int anAnswer = QMessageBox::question(
807 desktop(), tr("Save current file"),
808 tr("The document is modified, save before opening another?"),
809 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
810 if (anAnswer == QMessageBox::Save) {
812 } else if (anAnswer == QMessageBox::Cancel) {
818 //show file dialog, check if readable and open
819 QString aDirectory = QFileDialog::getExistingDirectory(desktop(), tr("Select directory"));
820 openDirectory(aDirectory);
823 //******************************************************
824 void XGUI_Workshop::openDirectory(const QString& theDirectory)
826 myCurrentDir = theDirectory;
827 if (myCurrentDir.isEmpty())
830 QFileInfo aFileInfo(myCurrentDir);
831 if (!aFileInfo.exists() || !aFileInfo.isReadable()) {
832 QMessageBox::critical(desktop(), tr("Warning"), tr("Unable to open the file."));
837 QApplication::setOverrideCursor(Qt::WaitCursor);
838 module()->closeDocument();
839 SessionPtr aSession = ModelAPI_Session::get();
840 aSession->closeAll();
841 aSession->load(myCurrentDir.toLatin1().constData());
842 myObjectBrowser->rebuildDataTree();
844 // Open first level of data tree
845 DocumentPtr aRootDoc = aSession->moduleDocument();
846 std::list<bool> aStates;
847 aRootDoc->restoreNodesState(aStates);
848 myObjectBrowser->setStateForDoc(aRootDoc, aStates);
850 updateCommandStatus();
852 myMainWindow->setCurrentDir(myCurrentDir, true);
854 QApplication::restoreOverrideCursor();
857 //******************************************************
858 void XGUI_Workshop::onNew()
860 QApplication::setOverrideCursor(Qt::WaitCursor);
861 if (objectBrowser() == 0) {
863 mySelector->connectViewers();
865 myViewerProxy->connectToViewer();
868 myMainWindow->showPythonConsole();
869 QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
870 aWnd->showMaximized();
871 updateCommandStatus();
873 myContextMenuMgr->connectViewer();
874 QApplication::restoreOverrideCursor();
878 //******************************************************
879 void XGUI_Workshop::onExit()
881 SessionPtr aMgr = ModelAPI_Session::get();
882 if (aMgr->isModified()) {
883 int anAnswer = QMessageBox::question(
884 myMainWindow, tr("Save current file"), tr("The document is modified, save before exit?"),
885 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
886 if (anAnswer == QMessageBox::Save) {
887 bool saved = onSave();
891 } else if (anAnswer == QMessageBox::Cancel) {
898 //******************************************************
899 void XGUI_Workshop::onPreferences()
901 ModuleBase_Prefs aModif;
902 ModuleBase_Preferences::editPreferences(aModif);
903 if (aModif.size() > 0) {
905 foreach (ModuleBase_Pref aPref, aModif)
907 aSection = aPref.first;
908 if (aSection == ModuleBase_Preferences::VIEWER_SECTION) {
909 myMainWindow->viewer()->updateFromResources();
910 } else if (aSection == ModuleBase_Preferences::MENU_SECTION) {
911 myMainWindow->menuObject()->updateFromResources();
914 displayer()->redisplayObjects();
919 //******************************************************
920 void XGUI_Workshop::onTrihedronVisibilityChanged(bool theState)
922 XGUI_Displayer* aDisplayer = displayer();
924 aDisplayer->displayTrihedron(theState);
927 //******************************************************
928 bool XGUI_Workshop::onSave()
930 if(!myOperationMgr->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
932 if (myCurrentDir.isEmpty()) {
935 std::list<std::string> aFiles;
936 saveDocument(myCurrentDir, aFiles);
937 updateCommandStatus();
939 myMainWindow->setModifiedState(false);
944 //******************************************************
945 bool XGUI_Workshop::onSaveAs()
947 if(!myOperationMgr->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
949 QFileDialog dialog(desktop());
950 dialog.setWindowTitle(tr("Select directory to save files..."));
951 dialog.setFileMode(QFileDialog::Directory);
952 dialog.setFilter(QDir::AllDirs);
953 dialog.setOptions(QFileDialog::HideNameFilterDetails | QFileDialog::ShowDirsOnly);
954 dialog.setViewMode(QFileDialog::Detail);
956 if (!dialog.exec()) {
960 QString aTempDir = dialog.selectedFiles().first();
962 if (aDir.exists() && !aDir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries).isEmpty()) {
963 int answer = QMessageBox::question(
965 // Title of the dialog which asks user if he wants to save study
966 // in existing non-empty folder
968 tr("The directory already contains some files, save anyway?"),
969 QMessageBox::Save | QMessageBox::Cancel);
970 if (answer == QMessageBox::Cancel) {
974 myCurrentDir = aTempDir;
976 myMainWindow->setCurrentDir(myCurrentDir, false);
977 myMainWindow->setModifiedState(false);
982 //******************************************************
983 void XGUI_Workshop::onUndo(int theTimes)
985 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
986 SessionPtr aMgr = ModelAPI_Session::get();
987 std::list<std::string> aUndoList = aMgr->undoList();
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 = aUndoList.cbegin();
995 for (int i = 0; (i < theTimes) && (aIt != aUndoList.cend()); ++i, ++aIt) {
997 if (QString((*aIt).c_str()) == MOVE_TO_END_COMMAND)
998 myObjectBrowser->rebuildDataTree();
1001 operationMgr()->updateApplyOfOperations();
1002 operationMgr()->updateOperationByUndoRedo();
1003 updateCommandStatus();
1006 //******************************************************
1007 void XGUI_Workshop::onRedo(int theTimes)
1009 // the viewer update should be blocked in order to avoid the features blinking. For the created
1010 // feature a results are created, the flush of the created signal caused the viewer redisplay for
1011 // each created result. After a redisplay signal is flushed. So, the viewer update is blocked
1012 // until redo of all possible objects happens
1013 bool isUpdateEnabled = myDisplayer->enableUpdateViewer(false);
1015 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
1016 SessionPtr aMgr = ModelAPI_Session::get();
1017 std::list<std::string> aRedoList = aMgr->redoList();
1018 if (aMgr->isOperation()) {
1019 /// this is important for nested operations
1020 /// when sketch operation is active, this condition is false and
1021 /// the sketch operation is not aborted
1022 operationMgr()->onAbortOperation();
1024 std::list<std::string>::const_iterator aIt = aRedoList.cbegin();
1025 for (int i = 0; (i < theTimes) && (aIt != aRedoList.cend()); ++i, ++aIt) {
1027 if (QString((*aIt).c_str()) == MOVE_TO_END_COMMAND)
1028 myObjectBrowser->rebuildDataTree();
1030 operationMgr()->updateApplyOfOperations();
1031 operationMgr()->updateOperationByUndoRedo();
1032 updateCommandStatus();
1034 // unblock the viewer update functionality and make update on purpose
1035 myDisplayer->enableUpdateViewer(isUpdateEnabled);
1036 myDisplayer->updateViewer();
1039 //******************************************************
1040 //void XGUI_Workshop::onRebuild()
1042 // SessionPtr aMgr = ModelAPI_Session::get();
1043 // bool aWasOperation = aMgr->isOperation(); // keep this value
1044 // if (!aWasOperation) {
1045 // aMgr->startOperation("Rebuild");
1047 // static const Events_ID aRebuildEvent = Events_Loop::loop()->eventByName("Rebuild");
1048 // Events_Loop::loop()->send(std::shared_ptr<Events_Message>(
1049 // new Events_Message(aRebuildEvent, this)));
1050 // if (!aWasOperation) {
1051 // aMgr->finishOperation();
1053 // updateCommandStatus();
1056 //******************************************************
1057 void XGUI_Workshop::onWidgetStateChanged(int thePreviousState)
1059 ModuleBase_ModelWidget* anActiveWidget = 0;
1060 ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
1062 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1064 anActiveWidget = aPanel->activeWidget();
1067 operationMgr()->onValidateOperation();
1069 myModule->widgetStateChanged(thePreviousState);
1072 //******************************************************
1073 void XGUI_Workshop::onValuesChanged()
1075 ModuleBase_ModelWidget* aSenderWidget = (ModuleBase_ModelWidget*)(sender());
1076 if (!aSenderWidget || aSenderWidget->canAcceptFocus())
1079 ModuleBase_ModelWidget* anActiveWidget = 0;
1080 ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
1082 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1084 anActiveWidget = aPanel->activeWidget();
1086 if (anActiveWidget) {
1087 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1089 if (aWidgetValidated)
1090 aWidgetValidated->clearValidatedCash();
1094 void XGUI_Workshop::onWidgetObjectUpdated()
1096 operationMgr()->onValidateOperation();
1099 ModuleBase_IModule* XGUI_Workshop::loadModule(const QString& theModule)
1101 QString libName = QString::fromStdString(library(theModule.toStdString()));
1102 if (libName.isEmpty()) {
1103 qWarning(qPrintable(tr("Information about module \"%1\" doesn't exist.").arg(theModule)));
1108 CREATE_FUNC crtInst = 0;
1111 HINSTANCE modLib = ::LoadLibrary((LPTSTR) qPrintable(libName));
1115 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
1116 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
1117 QString aMsg((char*) &lpMsgBuf);
1118 err = QString("Failed to load %1. %2").arg(libName).arg(aMsg);
1119 ::LocalFree(lpMsgBuf);
1121 crtInst = (CREATE_FUNC) ::GetProcAddress(modLib, CREATE_MODULE);
1125 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
1126 | FORMAT_MESSAGE_IGNORE_INSERTS,
1127 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
1128 QString aMsg((char*) &lpMsgBuf);
1129 err = QString("Failed to find %1 function. %2").arg( CREATE_MODULE).arg(aMsg);
1130 ::LocalFree(lpMsgBuf);
1134 void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY | RTLD_GLOBAL );
1136 err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
1138 crtInst = (CREATE_FUNC)dlsym( modLib, CREATE_MODULE );
1140 err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() );
1145 ModuleBase_IModule* aModule = crtInst ? crtInst(myModuleConnector) : 0;
1147 if (!err.isEmpty()) {
1149 Events_InfoMessage("XGUI_Workshop", err.toStdString()).send();
1151 qWarning(qPrintable(err));
1157 //******************************************************
1158 bool XGUI_Workshop::createModule()
1160 Config_ModuleReader aModuleReader;
1161 QString moduleName = QString::fromStdString(aModuleReader.getModuleName());
1162 myModule = loadModule(moduleName);
1166 //connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
1167 // myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
1168 //connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
1169 // myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
1171 myModule->createFeatures();
1173 salomeConnector()->createFeatureActions();
1175 //myActionsMgr->update();
1179 //******************************************************
1180 void XGUI_Workshop::updateCommandStatus()
1182 QList<QAction*> aCommands;
1184 aCommands = salomeConnector()->commandList();
1186 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
1187 foreach (AppElements_Command* aCmd, aMenuBar->features())
1188 aCommands.append(aCmd);
1190 SessionPtr aMgr = ModelAPI_Session::get();
1191 if (aMgr->hasModuleDocument()) {
1192 foreach(QAction* aCmd, aCommands) {
1193 QString aId = aCmd->data().toString();
1194 if (aId == "UNDO_CMD")
1195 aCmd->setEnabled(myModule->canUndo());
1196 else if (aId == "REDO_CMD")
1197 aCmd->setEnabled(myModule->canRedo());
1199 // Enable all commands
1200 aCmd->setEnabled(true);
1204 foreach(QAction* aCmd, aCommands) {
1205 QString aId = aCmd->data().toString();
1206 if (aId == "NEW_CMD")
1207 aCmd->setEnabled(true);
1208 else if (aId == "EXIT_CMD")
1209 aCmd->setEnabled(true);
1211 aCmd->setEnabled(false);
1214 myActionsMgr->updateCommandsStatus();
1215 emit commandStatusUpdated();
1218 void XGUI_Workshop::updateHistory()
1220 std::list<std::string> aUndoList = ModelAPI_Session::get()->undoList();
1221 QList<ActionInfo> aUndoRes = processHistoryList(aUndoList);
1222 emit updateUndoHistory(aUndoRes);
1224 std::list<std::string> aRedoList = ModelAPI_Session::get()->redoList();
1225 QList<ActionInfo> aRedoRes = processHistoryList(aRedoList);
1226 emit updateRedoHistory(aRedoRes);
1229 //******************************************************
1230 QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
1232 QDockWidget* aObjDock = new QDockWidget(theParent);
1233 aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea |
1234 Qt::RightDockWidgetArea |
1235 Qt::BottomDockWidgetArea);
1236 aObjDock->setWindowTitle(tr("Object browser"));
1237 aObjDock->setStyleSheet(
1238 "::title { position: relative; padding-left: 5px; text-align: left center }");
1239 myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock, this);
1240 myObjectBrowser->setXMLReader(myDataModelXMLReader);
1241 myModule->customizeObjectBrowser(myObjectBrowser);
1242 aObjDock->setWidget(myObjectBrowser);
1244 myContextMenuMgr->connectObjectBrowser();
1248 //******************************************************
1250 * Creates dock widgets, places them in corresponding area
1251 * and tabifies if necessary.
1253 void XGUI_Workshop::createDockWidgets()
1255 QMainWindow* aDesktop = desktop();
1256 QDockWidget* aObjDock = createObjectBrowser(aDesktop);
1257 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
1258 myPropertyPanel = new XGUI_PropertyPanel(aDesktop, myOperationMgr);
1259 myPropertyPanel->setupActions(myActionsMgr);
1260 myPropertyPanel->setAllowedAreas(Qt::LeftDockWidgetArea |
1261 Qt::RightDockWidgetArea |
1262 Qt::BottomDockWidgetArea);
1263 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel);
1264 hidePropertyPanel(); ///<! Invisible by default
1265 hideObjectBrowser();
1266 aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
1267 myPropertyPanel->installEventFilter(myOperationMgr);
1269 QAction* aOkAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept);
1270 connect(aOkAct, SIGNAL(triggered()), this, SLOT(onAcceptActionClicked()));
1272 QAction* aCancelAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Abort);
1273 connect(aCancelAct, SIGNAL(triggered()), myOperationMgr, SLOT(onAbortOperation()));
1275 QAction* aPreviewAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Preview);
1276 connect(aPreviewAct, SIGNAL(triggered()), this, SLOT(onPreviewActionClicked()));
1278 connect(myPropertyPanel, SIGNAL(keyReleased(QObject*, QKeyEvent*)),
1279 myOperationMgr, SLOT(onKeyReleased(QObject*, QKeyEvent*)));
1280 connect(myPropertyPanel, SIGNAL(enterClicked(QObject*)),
1281 myOperationMgr, SLOT(onProcessEnter(QObject*)));
1284 //******************************************************
1285 void XGUI_Workshop::showPropertyPanel()
1287 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1288 ///<! Restore ability to close panel from the window's menu
1289 aViewAct->setEnabled(true);
1290 myPropertyPanel->show();
1291 myPropertyPanel->raise();
1293 // The next code is necessary to made the property panel the active window
1294 // in order to operation manager could process key events of the panel.
1295 // otherwise they are ignored. It happens only if the same(activateWindow) is
1296 // not happened by property panel activation(e.g. resume operation of Sketch)
1297 ModuleBase_Tools::setFocus(myPropertyPanel, "XGUI_Workshop::showPropertyPanel()");
1300 //******************************************************
1301 void XGUI_Workshop::hidePropertyPanel()
1303 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1304 ///<! Do not allow to show empty property panel
1305 aViewAct->setEnabled(false);
1306 myPropertyPanel->hide();
1308 // the property panel is active window of the desktop, when it is
1309 // hidden, it is undefined which window becomes active. By this reason
1310 // it is defined to perform the desktop as the active window.
1311 // in SALOME mode, workstack made the PyConsole the active window,
1312 // set the focus on it. As a result, shortcuts of the application, like
1313 // are processed by this console. For example Undo actions.
1314 // It is possible that this code is to be moved to SHAPER package
1315 QMainWindow* aDesktop = desktop();
1316 ModuleBase_Tools::setFocus(aDesktop, "XGUI_Workshop::showPropertyPanel()");
1319 //******************************************************
1320 void XGUI_Workshop::showObjectBrowser()
1322 if (!isSalomeMode())
1323 myObjectBrowser->parentWidget()->show();
1326 //******************************************************
1327 void XGUI_Workshop::hideObjectBrowser()
1329 if (!isSalomeMode())
1330 myObjectBrowser->parentWidget()->hide();
1333 //******************************************************
1334 void XGUI_Workshop::salomeViewerSelectionChanged()
1336 emit salomeViewerSelection();
1339 //**************************************************************
1340 ModuleBase_IViewer* XGUI_Workshop::salomeViewer() const
1342 return mySalomeConnector->viewer();
1345 //**************************************************************
1346 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
1348 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1349 if (theId == "DELETE_CMD")
1351 else if (theId == "CLEAN_HISTORY_CMD")
1353 else if (theId == "MOVE_CMD")
1355 else if (theId == "COLOR_CMD")
1356 changeColor(aObjects);
1357 else if (theId == "DEFLECTION_CMD")
1358 changeDeflection(aObjects);
1359 else if (theId == "SHOW_CMD") {
1360 showObjects(aObjects, true);
1361 mySelector->updateSelectionBy(ModuleBase_ISelection::Browser);
1362 updateCommandStatus();
1364 else if (theId == "HIDE_CMD") {
1365 showObjects(aObjects, false);
1366 updateCommandStatus();
1368 else if (theId == "SHOW_ONLY_CMD") {
1369 showOnlyObjects(aObjects);
1370 mySelector->updateSelectionBy(ModuleBase_ISelection::Browser);
1371 updateCommandStatus();
1373 else if (theId == "SHADING_CMD")
1374 setDisplayMode(aObjects, XGUI_Displayer::Shading);
1375 else if (theId == "WIREFRAME_CMD")
1376 setDisplayMode(aObjects, XGUI_Displayer::Wireframe);
1377 else if (theId == "HIDEALL_CMD") {
1378 QObjectPtrList aList = myDisplayer->displayedObjects();
1379 foreach (ObjectPtr aObj, aList) {
1380 if (module()->canEraseObject(aObj))
1381 aObj->setDisplayed(false);
1383 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1385 //issue #2159 Hide all incomplete behavior
1386 viewer()->eraseAll();
1388 updateCommandStatus();
1389 } else if (theId == "SELECT_VERTEX_CMD") {
1390 setViewerSelectionMode(TopAbs_VERTEX);
1391 } else if (theId == "SELECT_EDGE_CMD") {
1392 setViewerSelectionMode(TopAbs_EDGE);
1393 } else if (theId == "SELECT_FACE_CMD") {
1394 setViewerSelectionMode(TopAbs_FACE);
1395 } else if (theId == "SELECT_RESULT_CMD") {
1396 //setViewerSelectionMode(-1);
1397 //IMP: an attempt to use result selection with other selection modes
1398 setViewerSelectionMode(ModuleBase_ResultPrs::Sel_Result);
1399 setViewerSelectionMode(TopAbs_COMPSOLID);
1400 } else if (theId == "SHOW_RESULTS_CMD") {
1401 highlightResults(aObjects);
1402 } else if (theId == "SHOW_FEATURE_CMD") {
1403 highlightFeature(aObjects);
1406 else if (theId == "TINSPECTOR_VIEW") {
1407 Handle(CDF_Application) anApplication = CDF_Session::CurrentSession()->CurrentApplication();
1408 if (!anApplication.IsNull())
1410 if (!MyTCommunicator)
1412 MyTCommunicator = new TInspector_Communicator();
1414 NCollection_List<Handle(Standard_Transient)> aParameters;
1415 aParameters.Append(anApplication);
1416 Handle(AIS_InteractiveContext) aContext = viewer()->AISContext();
1417 if (!aContext.IsNull())
1418 aParameters.Append(aContext);
1420 MyVCallBack = new VInspector_CallBack();
1421 MyTCommunicator->RegisterPlugin("TKDFBrowser");
1422 MyTCommunicator->RegisterPlugin("TKVInspector");
1423 MyTCommunicator->RegisterPlugin("TKShapeView");
1424 myDisplayer->setCallBack(MyVCallBack);
1426 AppElements_Viewer* aViewer = mainWindow()->viewer();
1428 aViewer->setCallBack(MyVCallBack);
1430 aParameters.Append(MyVCallBack);
1432 MyTCommunicator->RegisterPlugin("TKDFBrowser");
1433 MyTCommunicator->RegisterPlugin("TKShapeView");
1434 MyTCommunicator->RegisterPlugin("TKVInspector");
1435 MyTCommunicator->RegisterPlugin("TKSMBrowser"); // custom plugin to view ModelAPI
1437 MyTCommunicator->Init(aParameters);
1438 MyTCommunicator->Activate("TKSMBrowser"); // to have button in TInspector
1439 MyTCommunicator->Activate("TKVInspector"); // to have filled callback by model
1440 MyTCommunicator->Activate("TKDFBrowser");
1442 MyTCommunicator->SetVisible(true);
1448 //**************************************************************
1449 void XGUI_Workshop::setViewerSelectionMode(int theMode)
1452 myViewerSelMode.clear();
1454 if (myViewerSelMode.contains(theMode))
1455 myViewerSelMode.removeAll(theMode);
1457 myViewerSelMode.append(theMode);
1459 activateObjectsSelection(myDisplayer->displayedObjects());
1462 //**************************************************************
1463 void XGUI_Workshop::activateObjectsSelection(const QObjectPtrList& theList)
1466 module()->activeSelectionModes(aModes);
1467 if (aModes.isEmpty() && (myViewerSelMode.length() > 0))
1468 aModes.append(myViewerSelMode);
1469 myDisplayer->activateObjects(aModes, theList);
1472 //**************************************************************
1473 void XGUI_Workshop::deleteObjects()
1475 ModuleBase_IModule* aModule = module();
1476 // allow the module to delete objects, do nothing if it has succeed
1477 if (aModule->deleteObjects()) {
1478 updateCommandStatus();
1482 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1483 if (!abortAllOperations())
1486 bool hasResult = false;
1487 bool hasFeature = false;
1488 bool hasParameter = false;
1489 bool hasCompositeOwner = false;
1490 bool hasResultInHistory = false;
1491 ModuleBase_Tools::checkObjects(anObjects, hasResult, hasFeature, hasParameter, hasCompositeOwner,
1492 hasResultInHistory);
1493 if (!(hasFeature || hasParameter))
1497 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1498 std::set<FeaturePtr> aFeatures;
1499 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1500 ModelAPI_Tools::findAllReferences(aFeatures, aReferences);
1503 QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text() + " %1";
1504 aDescription = aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
1505 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, module());
1507 operationMgr()->startOperation(anOpAction);
1509 std::set<FeaturePtr> aFeatureRefsToDelete;
1510 if (ModuleBase_Tools::askToDelete(aFeatures, aReferences, desktop(), aFeatureRefsToDelete)) {
1511 // WORKAROUND, should be done before each object remove, if it presents in XGUI_DataModel tree
1512 // It is necessary to clear selection in order to avoid selection changed event during
1513 // deletion and negative consequences connected with processing of already deleted items
1514 mySelector->clearSelection();
1516 if (!aFeatureRefsToDelete.empty())
1517 aFeatures.insert(aFeatureRefsToDelete.begin(), aFeatureRefsToDelete.end());
1518 aDone = ModelAPI_Tools::removeFeatures(aFeatures, false);
1521 operationMgr()->commitOperation();
1523 operationMgr()->abortOperation(operationMgr()->currentOperation());
1526 //**************************************************************
1527 void addRefsToFeature(const FeaturePtr& theFeature,
1528 const std::map<FeaturePtr, std::set<FeaturePtr> >& theMainList,
1529 std::set<FeaturePtr>& theReferences)
1531 //if (theReferences.find(theFeature) != theReferences.end())
1533 if (theMainList.find(theFeature) == theMainList.end())
1534 return; // this feature is not in the selection list, so exists without references to it
1535 std::set<FeaturePtr> aMainReferences = theMainList.at(theFeature);
1537 std::set<FeaturePtr>::const_iterator anIt = aMainReferences.begin(),
1538 aLast = aMainReferences.end();
1539 for (; anIt != aLast; anIt++) {
1540 FeaturePtr aRefFeature = *anIt;
1541 if (theReferences.find(aRefFeature) == theReferences.end())
1542 theReferences.insert(aRefFeature);
1543 addRefsToFeature(aRefFeature, theMainList, theReferences);
1547 //**************************************************************
1548 void XGUI_Workshop::cleanHistory()
1550 if (!abortAllOperations())
1553 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1554 std::set<FeaturePtr> aFeatures;
1555 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1557 #ifdef DEBUG_CLEAN_HISTORY
1559 std::set<FeaturePtr>::const_iterator aFIt;
1560 for (aFIt = aFeatures.begin(); aFIt != aFeatures.end(); ++aFIt) {
1561 FeaturePtr aFeature = ModelAPI_Feature::feature(*aFIt);
1562 anInfo.append(aFeature->name().c_str());
1564 QString anInfoStr = anInfo.join(";\t");
1565 qDebug(QString("cleanHistory for: [%1] - %2").
1566 arg(aFeatures.size()).arg(anInfoStr).toStdString().c_str());
1569 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1570 ModelAPI_Tools::findAllReferences(aFeatures, aReferences, true, false);
1571 // find for each object whether all reference values are in the map as key, that means that there
1572 // is no other reference in the model to this object, so it might be removed by cleaning history
1573 // sk_1(ext_1, vertex_1) + (sk_3, bool_1) - cann't be deleted, dependency to bool_1
1574 // ext_1(bool_1, sk_3) - cann't be deleted, dependency to bool_1
1576 // sk_2(ext_2) + (bool_1) - cann't be deleted, dependency to bool_1
1577 // ext_2(bool_1) - cann't be deleted, dependency to bool_1
1579 // Information: bool_1 is not selected
1580 std::set<FeaturePtr> anUnusedObjects;
1581 std::map<FeaturePtr, std::set<FeaturePtr> >::const_iterator aMainIt = aReferences.begin(),
1582 aMainLast = aReferences.end();
1583 for (; aMainIt != aMainLast; aMainIt++) {
1584 FeaturePtr aMainListFeature = aMainIt->first;
1585 std::set<FeaturePtr> aMainRefList = aMainIt->second;
1586 std::set<FeaturePtr>::const_iterator aRefIt = aMainRefList.begin(),
1587 aRefLast = aMainRefList.end();
1588 bool aFeatureOutOfTheList = false;
1589 for (; aRefIt != aRefLast && !aFeatureOutOfTheList; aRefIt++) {
1590 FeaturePtr aRefFeature = *aRefIt;
1591 aFeatureOutOfTheList = aReferences.find(aRefFeature) == aReferences.end();
1593 if (!aFeatureOutOfTheList)
1594 anUnusedObjects.insert(aMainListFeature);
1597 #ifdef DEBUG_CLEAN_HISTORY
1599 for (aFIt = anUnusedObjects.begin(); aFIt != anUnusedObjects.end(); ++aFIt) {
1600 FeaturePtr aFeature = *aFIt;
1601 anInfo.append(aFeature->name().c_str());
1603 qDebug(QString("unused objects: [%1] - %2").
1604 arg(anInfo.size()).arg(anInfo.join(";\t")).toStdString().c_str());
1607 // warn about the references remove, break the delete operation if the user chose it
1608 if (!anUnusedObjects.empty()) {
1610 foreach (const FeaturePtr& aFeature, anUnusedObjects) {
1611 aNames.append(aFeature->name().c_str());
1614 QString anUnusedNames = aNames.join(", ");
1616 QString anActionId = "CLEAN_HISTORY_CMD";
1617 QString aDescription = contextMenuMgr()->action(anActionId)->text();
1619 QMessageBox aMessageBox(desktop());
1620 aMessageBox.setWindowTitle(aDescription);
1621 aMessageBox.setIcon(QMessageBox::Warning);
1622 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
1623 aMessageBox.setDefaultButton(QMessageBox::No);
1625 const char* aKeyStr = "Unused features are the following: "
1626 "%1.\nThese features will be deleted.\nWould you like to continue?";
1627 QString aText = QString(tr(aKeyStr).arg(anUnusedNames));
1628 aMessageBox.setText(aText);
1629 if (aMessageBox.exec() == QMessageBox::No)
1632 // 1. start operation
1633 aDescription += "by deleting of " +
1634 aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
1635 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, module());
1636 operationMgr()->startOperation(anOpAction);
1638 // WORKAROUND, should be done before each object remove, if it presents in XGUI_DataModel tree
1639 // It is necessary to clear selection in order to avoid selection changed event during
1640 // deletion and negative consequences connected with processing of already deleted items
1641 mySelector->clearSelection();
1643 std::set<FeaturePtr> anIgnoredFeatures;
1644 if (ModelAPI_Tools::removeFeatures(anUnusedObjects, true)) {
1645 operationMgr()->commitOperation();
1648 operationMgr()->abortOperation(operationMgr()->currentOperation());
1652 QString anActionId = "CLEAN_HISTORY_CMD";
1653 QString aDescription = contextMenuMgr()->action(anActionId)->text();
1655 QMessageBox aMessageBox(desktop());
1656 aMessageBox.setWindowTitle(aDescription);
1657 aMessageBox.setIcon(QMessageBox::Warning);
1658 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
1659 aMessageBox.setDefaultButton(QMessageBox::No);
1662 aMessageBox.setStandardButtons(QMessageBox::Ok);
1663 aMessageBox.setDefaultButton(QMessageBox::Ok);
1665 aText = QString(tr("All features are relevant, there is nothing to be deleted"));
1666 aMessageBox.setText(aText);
1668 if (aMessageBox.exec() == QMessageBox::No)
1673 //**************************************************************
1674 void XGUI_Workshop::moveObjects()
1676 if (!abortAllOperations())
1679 SessionPtr aMgr = ModelAPI_Session::get();
1681 QString anActionId = "MOVE_CMD";
1682 QString aDescription = contextMenuMgr()->action(anActionId)->text();
1683 aMgr->startOperation(aDescription.toStdString());
1685 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1686 // It is necessary to clear selection in order to avoid selection changed event during
1687 // moving and negative consequences connected with processing of already moved items
1688 mySelector->clearSelection();
1689 // check whether the object can be moved. There should not be parts which are not loaded
1690 std::set<FeaturePtr> aFeatures;
1691 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1692 if (!XGUI_Tools::canRemoveOrRename(desktop(), aFeatures))
1695 DocumentPtr anActiveDocument = aMgr->activeDocument();
1696 FeaturePtr aCurrentFeature = anActiveDocument->currentFeature(true);
1697 std::set<FeaturePtr>::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
1698 for (; anIt != aLast; anIt++) {
1699 FeaturePtr aFeature = *anIt;
1700 if (!aFeature.get() || !myModule->canApplyAction(aFeature, anActionId))
1703 anActiveDocument->moveFeature(aFeature, aCurrentFeature);
1704 aCurrentFeature = anActiveDocument->currentFeature(true);
1706 aMgr->finishOperation();
1709 //**************************************************************
1710 bool XGUI_Workshop::deleteFeatures(const QObjectPtrList& theObjects)
1712 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1713 std::set<FeaturePtr> aFeatures;
1714 ModuleBase_Tools::convertToFeatures(theObjects, aFeatures);
1716 return ModelAPI_Tools::removeFeaturesAndReferences(aFeatures);
1719 bool hasResults(QObjectPtrList theObjects, const std::set<std::string>& theTypes)
1721 bool isFoundResultType = false;
1722 foreach(ObjectPtr anObj, theObjects)
1724 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
1725 if (aResult.get() == NULL)
1728 isFoundResultType = theTypes.find(aResult->groupName()) != theTypes.end();
1729 if (isFoundResultType)
1732 return isFoundResultType;
1735 //**************************************************************
1736 // Returns the list of all features for theDocument and all features of
1737 // all nested parts.
1738 std::list<FeaturePtr> allFeatures(const DocumentPtr& theDocument)
1740 std::list<FeaturePtr> aResultList;
1741 std::list<FeaturePtr> anAllFeatures = theDocument->allFeatures();
1742 foreach (const FeaturePtr& aFeature, anAllFeatures) {
1743 // The order of appending features of the part and the part itself is important
1745 // Append features from a part feature
1746 std::list<ResultPtr> aResults;
1747 ModelAPI_Tools::allResults(aFeature, aResults);
1748 foreach (const ResultPtr& aResult, aResults) {
1749 ResultPartPtr aResultPart =
1750 std::dynamic_pointer_cast<ModelAPI_ResultPart>(aResult);
1751 if (aResultPart.get() && aResultPart->partDoc().get()) {
1753 std::list<FeaturePtr> anAllFeatures = allFeatures(aResultPart->partDoc());
1754 aResultList.insert(aResultList.end(), anAllFeatures.begin(), anAllFeatures.end());
1758 aResultList.push_back(aFeature);
1763 //**************************************************************
1764 // Returns the list of features placed between theObject and the current feature
1765 // in the same document. Excludes theObject, includes the current feature.
1766 std::list<FeaturePtr> toCurrentFeatures(const ObjectPtr& theObject)
1768 std::list<FeaturePtr> aResult;
1769 DocumentPtr aDocument = theObject->document();
1770 std::list<FeaturePtr> anAllFeatures = allFeatures(aDocument);
1771 // find the object iterator
1772 std::list<FeaturePtr>::iterator aObjectIt =
1773 std::find(anAllFeatures.begin(), anAllFeatures.end(), theObject);
1774 if (aObjectIt == anAllFeatures.end())
1776 // find the current feature iterator
1777 std::list<FeaturePtr>::iterator aCurrentIt =
1778 std::find(anAllFeatures.begin(), anAllFeatures.end(), aDocument->currentFeature(true));
1779 if (aCurrentIt == anAllFeatures.end())
1781 // check the right order
1782 if (std::distance(aObjectIt, anAllFeatures.end()) <=
1783 std::distance(aCurrentIt, anAllFeatures.end()))
1785 // exclude the object
1786 std::advance(aObjectIt, 1);
1787 // include the current feature
1788 std::advance(aCurrentIt, 1);
1789 return std::list<FeaturePtr>(aObjectIt, aCurrentIt);
1792 bool XGUI_Workshop::canMoveFeature()
1794 QString anActionId = "MOVE_CMD";
1796 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1797 QObjectPtrList aValidatedObjects;
1798 foreach (ObjectPtr aObject, aObjects) {
1799 if (!myModule->canApplyAction(aObject, anActionId))
1801 // To be moved feature should be in active document
1802 if (aObject->document() != ModelAPI_Session::get()->activeDocument())
1804 aValidatedObjects.append(aObject);
1806 if (aValidatedObjects.size() != aObjects.size())
1807 aObjects = aValidatedObjects;
1809 bool aCanMove = !aObjects.empty();
1811 QObjectPtrList::const_iterator anIt = aObjects.begin(), aLast = aObjects.end();
1812 for (; anIt != aLast && aCanMove; anIt++) {
1813 ObjectPtr aObject = *anIt;
1814 // 1. Get features placed between selected and current in the document
1815 std::list<FeaturePtr> aFeaturesBetween = toCurrentFeatures(aObject);
1816 // if aFeaturesBetween is empty it means wrong order or aObject is the current feature
1817 if (aFeaturesBetween.empty())
1820 std::set<FeaturePtr> aPlacedFeatures(aFeaturesBetween.begin(), aFeaturesBetween.end());
1821 // 2. Get all reference features to the selected object in the document
1822 std::set<FeaturePtr> aRefFeatures;
1823 ModuleBase_Tools::refsToFeatureInFeatureDocument(aObject, aRefFeatures);
1825 if (aRefFeatures.empty())
1828 // 3. Find any placed features in all reference features
1829 std::set<FeaturePtr> aIntersectionFeatures;
1830 std::set_intersection(aRefFeatures.begin(), aRefFeatures.end(),
1831 aPlacedFeatures.begin(), aPlacedFeatures.end(),
1832 std::inserter(aIntersectionFeatures, aIntersectionFeatures.begin()));
1833 // 4. Return false if any reference feature is placed before current feature
1834 if (!aIntersectionFeatures.empty())
1842 //**************************************************************
1843 bool XGUI_Workshop::canBeShaded(const ObjectPtr& theObject) const
1845 bool aCanBeShaded = myDisplayer->canBeShaded(theObject);
1846 if (!aCanBeShaded) {
1847 ResultCompSolidPtr aCompsolidResult =
1848 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theObject);
1849 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
1850 for(int i = 0; i < aCompsolidResult->numberOfSubs() && !aCanBeShaded; i++)
1851 aCanBeShaded = myDisplayer->canBeShaded(aCompsolidResult->subResult(i));
1854 return aCanBeShaded;
1857 //**************************************************************
1858 bool XGUI_Workshop::canChangeColor() const
1860 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1862 std::set<std::string> aTypes;
1863 aTypes.insert(ModelAPI_ResultGroup::group());
1864 aTypes.insert(ModelAPI_ResultConstruction::group());
1865 aTypes.insert(ModelAPI_ResultBody::group());
1866 aTypes.insert(ModelAPI_ResultPart::group());
1868 return hasResults(aObjects, aTypes);
1871 void setColor(ResultPtr theResult, const std::vector<int>& theColor)
1873 if (!theResult.get())
1876 AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
1877 if (aColorAttr.get() != NULL) {
1878 if (!aColorAttr->size()) {
1879 aColorAttr->setSize(3);
1881 aColorAttr->setValue(0, theColor[0]);
1882 aColorAttr->setValue(1, theColor[1]);
1883 aColorAttr->setValue(2, theColor[2]);
1887 //**************************************************************
1888 void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
1891 AttributeIntArrayPtr aColorAttr;
1892 // 1. find the current color of the object. This is a color of AIS presentation
1893 // The objects are iterated until a first valid color is found
1894 std::vector<int> aColor;
1895 foreach(ObjectPtr anObject, theObjects) {
1896 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1897 if (aResult.get()) {
1898 XGUI_CustomPrs::getResultColor(aResult, aColor);
1901 // TODO: remove the obtaining a color from the AIS object
1902 // this does not happen never because:
1903 // 1. The color can be changed only on results
1904 // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
1905 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
1906 if (anAISObj.get()) {
1908 anAISObj->getColor(aColor[0], aColor[1], aColor[2]);
1911 if (!aColor.empty())
1914 if (aColor.size() != 3)
1917 if (!abortAllOperations())
1919 // 2. show the dialog to change the value
1920 XGUI_ColorDialog* aDlg = new XGUI_ColorDialog(desktop());
1921 aDlg->setColor(aColor);
1922 aDlg->move(QCursor::pos());
1923 bool isDone = aDlg->exec() == QDialog::Accepted;
1927 bool isRandomColor = aDlg->isRandomColor();
1929 // 3. abort the previous operation and start a new one
1930 SessionPtr aMgr = ModelAPI_Session::get();
1931 QString aDescription = contextMenuMgr()->action("COLOR_CMD")->text();
1932 aMgr->startOperation(aDescription.toStdString());
1934 // 4. set the value to all results
1935 std::vector<int> aColorResult = aDlg->getColor();
1936 foreach(ObjectPtr anObj, theObjects) {
1937 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
1938 if (aResult.get() != NULL) {
1939 ResultCompSolidPtr aCompsolidResult =
1940 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
1941 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
1942 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
1943 setColor(aCompsolidResult->subResult(i), !isRandomColor ? aColorResult :
1944 aDlg->getRandomColor());
1947 setColor(aResult, !isRandomColor ? aColorResult : aDlg->getRandomColor());
1950 aMgr->finishOperation();
1951 updateCommandStatus();
1954 //**************************************************************
1955 bool XGUI_Workshop::canChangeDeflection() const
1957 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1959 std::set<std::string> aTypes;
1960 aTypes.insert(ModelAPI_ResultGroup::group());
1961 aTypes.insert(ModelAPI_ResultConstruction::group());
1962 aTypes.insert(ModelAPI_ResultBody::group());
1963 aTypes.insert(ModelAPI_ResultPart::group());
1965 return hasResults(aObjects, aTypes);
1968 void setDeflection(ResultPtr theResult, const double theDeflection)
1970 if (!theResult.get())
1973 AttributeDoublePtr aDeflectionAttr = theResult->data()->real(ModelAPI_Result::DEFLECTION_ID());
1974 if (aDeflectionAttr.get() != NULL)
1975 aDeflectionAttr->setValue(theDeflection);
1979 //**************************************************************
1980 void XGUI_Workshop::changeDeflection(const QObjectPtrList& theObjects)
1982 AttributeDoublePtr aDoubleAttr;
1983 // 1. find the current color of the object. This is a color of AIS presentation
1984 // The objects are iterated until a first valid color is found
1985 double aDeflection = -1;
1986 foreach(ObjectPtr anObject, theObjects) {
1987 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1988 if (aResult.get()) {
1989 aDeflection = XGUI_CustomPrs::getResultDeflection(aResult);
1992 // TODO: remove the obtaining a color from the AIS object
1993 // this does not happen never because:
1994 // 1. The color can be changed only on results
1995 // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
1996 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
1997 if (anAISObj.get()) {
1998 aDeflection = anAISObj->getDeflection();
2001 if (aDeflection > 0)
2004 if (aDeflection < 0)
2007 if (!abortAllOperations())
2009 // 2. show the dialog to change the value
2010 XGUI_DeflectionDialog* aDlg = new XGUI_DeflectionDialog(desktop());
2011 aDlg->setDeflection(aDeflection);
2012 aDlg->move(QCursor::pos());
2013 bool isDone = aDlg->exec() == QDialog::Accepted;
2017 // 3. abort the previous operation and start a new one
2018 SessionPtr aMgr = ModelAPI_Session::get();
2019 QString aDescription = contextMenuMgr()->action("DEFLECTION_CMD")->text();
2020 aMgr->startOperation(aDescription.toStdString());
2022 // 4. set the value to all results
2023 aDeflection = aDlg->getDeflection();
2024 foreach(ObjectPtr anObj, theObjects) {
2025 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
2026 if (aResult.get() != NULL) {
2027 ResultCompSolidPtr aCompsolidResult =
2028 std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
2029 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
2030 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
2031 setDeflection(aCompsolidResult->subResult(i), aDeflection);
2034 setDeflection(aResult, aDeflection);
2037 aMgr->finishOperation();
2038 updateCommandStatus();
2041 //**************************************************************
2042 #define SET_DISPLAY_GROUP(aGroupName, aDisplay) \
2043 for (int i = 0; i < aDoc->size(aGroupName); i++) { \
2044 aDoc->object(aGroupName, i)->setDisplayed(aDisplay); \
2046 void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible)
2048 foreach (ObjectPtr aObj, theList) {
2049 aObj->setDisplayed(isVisible);
2051 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2054 //**************************************************************
2055 void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList)
2057 // Hide all displayed objects
2058 QObjectPtrList aList = myDisplayer->displayedObjects();
2059 foreach (ObjectPtr aObj, aList) {
2060 if (module()->canEraseObject(aObj))
2061 aObj->setDisplayed(false);
2063 //Do not use eraseAll if you didn't send Redisplay event:
2064 //all objects are erased from viewer, but considered as displayed in displayer
2065 // Problem in bug 2218
2066 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2068 //issue #2159 Hide all incomplete behavior
2069 viewer()->eraseAll();
2072 // Show only objects from the list
2073 foreach (ObjectPtr aObj, theList) {
2074 aObj->setDisplayed(true);
2076 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2080 //**************************************************************
2081 void XGUI_Workshop::registerValidators() const
2083 SessionPtr aMgr = ModelAPI_Session::get();
2084 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
2087 //**************************************************************
2088 void XGUI_Workshop::displayDocumentResults(DocumentPtr theDoc)
2092 displayGroupResults(theDoc, ModelAPI_ResultConstruction::group());
2093 displayGroupResults(theDoc, ModelAPI_ResultBody::group());
2096 //**************************************************************
2097 void XGUI_Workshop::displayGroupResults(DocumentPtr theDoc, std::string theGroup)
2099 for (int i = 0; i < theDoc->size(theGroup); i++)
2100 theDoc->object(theGroup, i)->setDisplayed(true);
2101 //displayObject(theDoc->object(theGroup, i));
2102 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2105 //**************************************************************
2106 void XGUI_Workshop::setDisplayMode(const QObjectPtrList& theList, int theMode)
2108 foreach(ObjectPtr aObj, theList) {
2109 myDisplayer->setDisplayMode(aObj, (XGUI_Displayer::DisplayMode)theMode, false);
2111 ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aObj);
2112 if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
2113 for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
2114 myDisplayer->setDisplayMode(aCompsolidResult->subResult(i),
2115 (XGUI_Displayer::DisplayMode)theMode, false);
2119 if (theList.size() > 0)
2120 myDisplayer->updateViewer();
2123 //**************************************************************
2124 void XGUI_Workshop::closeDocument()
2126 ModuleBase_Operation* anOperation = operationMgr()->currentOperation();
2127 while (anOperation) {
2128 anOperation->abort();
2129 anOperation = operationMgr()->currentOperation();
2131 //myDisplayer->closeLocalContexts();
2132 myDisplayer->eraseAll();
2133 objectBrowser()->clearContent();
2135 module()->closeDocument();
2137 // data model need not process the document's signals about objects modifications as
2138 // the document is closed
2139 //bool isBlocked = objectBrowser()->dataModel()->blockEventsProcessing(true);
2141 SessionPtr aMgr = ModelAPI_Session::get();
2144 //objectBrowser()->dataModel()->blockEventsProcessing(isBlocked);
2147 void XGUI_Workshop::addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot)
2149 XGUI_HistoryMenu* aMenu = NULL;
2150 if (isSalomeMode()) {
2151 QAction* anAction = qobject_cast<QAction*>(theObject);
2154 aMenu = new XGUI_HistoryMenu(anAction);
2156 QToolButton* aButton = qobject_cast<QToolButton*>(theObject);
2157 aMenu = new XGUI_HistoryMenu(aButton);
2159 connect(this, theSignal, aMenu, SLOT(setHistory(const QList<ActionInfo>&)));
2160 connect(aMenu, SIGNAL(actionSelected(int)), this, theSlot);
2163 QList<ActionInfo> XGUI_Workshop::processHistoryList(const std::list<std::string>& theList) const
2165 QList<ActionInfo> aResult;
2166 std::list<std::string>::const_iterator it = theList.cbegin();
2167 for (; it != theList.cend(); it++) {
2168 QString anId = QString::fromStdString(*it);
2169 bool isEditing = anId.endsWith(ModuleBase_OperationFeature::EditSuffix());
2171 anId.chop(ModuleBase_OperationFeature::EditSuffix().size());
2174 QAction* aContextMenuAct = myContextMenuMgr->actionByName(anId);
2175 if (aContextMenuAct) {
2176 anInfo.initFrom(aContextMenuAct);
2178 anInfo = myActionsMgr->actionInfoById(anId);
2181 anInfo.text = anInfo.text.prepend("Modify ");
2188 void XGUI_Workshop::setStatusBarMessage(const QString& theMessage)
2191 salomeConnector()->putInfo(theMessage, -1);
2193 myMainWindow->putInfo(theMessage, -1);
2197 void XGUI_Workshop::synchronizeViewer()
2199 SessionPtr aMgr = ModelAPI_Session::get();
2200 QList<DocumentPtr> aDocs;
2201 aDocs.append(aMgr->activeDocument());
2202 aDocs.append(aMgr->moduleDocument());
2204 foreach(DocumentPtr aDoc, aDocs) {
2205 synchronizeGroupInViewer(aDoc, ModelAPI_ResultConstruction::group(), false);
2206 synchronizeGroupInViewer(aDoc, ModelAPI_ResultBody::group(), false);
2207 synchronizeGroupInViewer(aDoc, ModelAPI_ResultPart::group(), false);
2208 synchronizeGroupInViewer(aDoc, ModelAPI_ResultGroup::group(), false);
2212 void XGUI_Workshop::synchronizeGroupInViewer(const DocumentPtr& theDoc,
2213 const std::string& theGroup,
2214 bool theUpdateViewer)
2217 int aSize = theDoc->size(theGroup);
2218 for (int i = 0; i < aSize; i++) {
2219 aObj = theDoc->object(theGroup, i);
2220 if (aObj->isDisplayed()) {
2221 // Hide the presentation with an empty shape. But isDisplayed state of the object should not
2222 // be changed to the object becomes visible when the shape becomes not empty
2223 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
2224 if (aRes.get() && (!aRes->shape().get() || aRes->shape()->isNull()))
2226 myDisplayer->display(aObj, false);
2229 if (theUpdateViewer)
2230 myDisplayer->updateViewer();
2233 void XGUI_Workshop::highlightResults(const QObjectPtrList& theObjects)
2235 FeaturePtr aFeature;
2236 QObjectPtrList aSelList = theObjects;
2237 bool aHasHidden = false;
2238 foreach(ObjectPtr aObj, theObjects) {
2239 aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
2240 if (aFeature.get()) {
2241 std::list<ResultPtr> aResults;
2242 ModelAPI_Tools::allResults(aFeature, aResults);
2243 std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aIt;
2244 for(aIt = aResults.cbegin(); aIt != aResults.cend(); aIt++) {
2245 aHasHidden |= (*aIt)->isConcealed();
2246 aSelList.append(*aIt);
2250 if (aSelList.count() > theObjects.count()) {
2251 // if something was found
2252 bool aBlocked = objectBrowser()->blockSignals(true);
2253 objectBrowser()->setObjectsSelected(aSelList);
2254 objectBrowser()->blockSignals(aBlocked);
2257 QMessageBox::information(desktop(), tr("Find results"),
2258 tr("Results not found"), QMessageBox::Ok);
2261 void XGUI_Workshop::highlightFeature(const QObjectPtrList& theObjects)
2264 QObjectPtrList aSelList = theObjects;
2265 FeaturePtr aFeature;
2266 foreach(ObjectPtr aObj, theObjects) {
2267 aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
2268 if (aResult.get()) {
2269 aFeature = ModelAPI_Feature::feature(aResult);
2270 if (aFeature.get()) {
2271 aSelList.append(aFeature);
2275 if (aSelList.count() > theObjects.count()) {
2276 // if something was found
2277 bool aBlocked = objectBrowser()->blockSignals(true);
2278 objectBrowser()->setObjectsSelected(aSelList);
2279 objectBrowser()->blockSignals(aBlocked);