1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "XGUI_Workshop.h"
23 #include "XGUI_ActionsMgr.h"
24 #include "XGUI_ActiveControlMgr.h"
25 #include "XGUI_ActiveControlSelector.h"
26 #include "XGUI_MenuMgr.h"
27 #include "XGUI_ColorDialog.h"
28 #include "XGUI_DeflectionDialog.h"
29 #include "XGUI_TransparencyWidget.h"
30 #include "XGUI_ContextMenuMgr.h"
31 #include "XGUI_Displayer.h"
32 #include "XGUI_ErrorDialog.h"
33 #include "XGUI_ErrorMgr.h"
34 #include "XGUI_FacesPanel.h"
35 #include "XGUI_FacesPanelSelector.h"
36 #include "XGUI_ModuleConnector.h"
37 #include "XGUI_ObjectsBrowser.h"
38 #include "XGUI_OperationMgr.h"
39 #include "XGUI_PropertyPanel.h"
40 #include "XGUI_PropertyPanelSelector.h"
41 #include "XGUI_PropertyDialog.h"
42 #include "XGUI_SalomeConnector.h"
43 #include "XGUI_Selection.h"
44 #include "XGUI_SelectionActivate.h"
45 #include "XGUI_SelectionMgr.h"
46 #include "XGUI_Tools.h"
47 #include "XGUI_ViewerProxy.h"
48 #include "XGUI_WorkshopListener.h"
49 #include <XGUI_CustomPrs.h>
50 #include <XGUI_HistoryMenu.h>
51 #include <XGUI_QtEvents.h>
52 #include <XGUI_DataModel.h>
53 #include <XGUI_InspectionPanel.h>
54 #include <XGUI_CompressFiles.h>
57 #include <AppElements_Button.h>
58 #include <AppElements_Command.h>
59 #include <AppElements_MainMenu.h>
60 #include <AppElements_MainWindow.h>
61 #include <AppElements_MenuGroupPanel.h>
62 #include <AppElements_Viewer.h>
63 #include <AppElements_Workbench.h>
66 #include <Config_XMLReader.h>
68 #include <ModelAPI_AttributeDocRef.h>
69 #include <ModelAPI_AttributeIntArray.h>
70 #include <ModelAPI_AttributeDouble.h>
71 #include <ModelAPI_Data.h>
72 #include <ModelAPI_Events.h>
73 #include <ModelAPI_Feature.h>
74 #include <ModelAPI_Object.h>
75 #include <ModelAPI_ResultBody.h>
76 #include <ModelAPI_ResultConstruction.h>
77 #include <ModelAPI_ResultGroup.h>
78 #include <ModelAPI_ResultParameter.h>
79 #include <ModelAPI_ResultField.h>
80 #include <ModelAPI_Session.h>
81 #include <ModelAPI_Validator.h>
82 #include <ModelAPI_Tools.h>
84 //#include <PartSetPlugin_Part.h>
86 #include <Events_Loop.h>
87 #include <Events_InfoMessage.h>
88 #include <Events_LongOp.h>
90 #include <ModuleBase_IModule.h>
91 #include <ModuleBase_IViewer.h>
92 #include <ModuleBase_Operation.h>
93 #include <ModuleBase_OperationDescription.h>
94 #include <ModuleBase_PageBase.h>
95 #include <ModuleBase_Preferences.h>
96 #include <ModuleBase_SelectionValidator.h>
97 #include <ModuleBase_Tools.h>
98 #include <ModuleBase_WidgetFactory.h>
99 #include <ModuleBase_OperationFeature.h>
100 #include <ModuleBase_OperationAction.h>
101 #include <ModuleBase_PagedContainer.h>
102 #include <ModuleBase_WidgetValidated.h>
103 #include <ModuleBase_ModelWidget.h>
104 #include <ModuleBase_ResultPrs.h>
105 #include <ModuleBase_ActionIntParameter.h>
107 #include <Config_Common.h>
108 #include <Config_FeatureMessage.h>
109 #include <Config_ModuleReader.h>
110 #include <Config_PointerMessage.h>
111 #include <Config_PropManager.h>
112 #include <Config_DataModelReader.h>
113 #include <Config_Translator.h>
114 #include <Config_WidgetAPI.h>
115 #include <Config_Keywords.h>
117 #include <SUIT_ResourceMgr.h>
119 #include <AIS_Trihedron.hxx>
120 #ifdef BEFORE_TRIHEDRON_PATCH
121 #include <AIS_Point.hxx>
122 #include <AIS_Axis.hxx>
125 #include <QApplication>
126 #include <QFileDialog>
127 #include <QMessageBox>
128 #include <QMdiSubWindow>
129 #include <QMainWindow>
130 #include <QPushButton>
131 #include <QDockWidget>
136 #include <QToolButton>
138 #include <QDesktopWidget>
140 #include <QDesktopServices>
145 #include <CDF_Session.hxx>
146 #include <CDF_Application.hxx>
147 #include <inspector/TInspector_Communicator.hxx>
148 #include <inspector/VInspector_CallBack.hxx>
149 static TInspector_Communicator* MyTCommunicator;
150 static Handle(VInspector_CallBack) MyVCallBack;
165 //#define DEBUG_WITH_MESSAGE_REPORT
167 QString XGUI_Workshop::MOVE_TO_END_COMMAND = QObject::tr("Move to the end");
169 //#define DEBUG_DELETE
170 //#define DEBUG_FEATURE_NAME
171 //#define DEBUG_CLEAN_HISTORY
174 static QString MyFilter(QObject::tr("OpenParts files (*.opp)"));
177 //******************************************************
178 XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
181 mySalomeConnector(theConnector),
183 myInspectionPanel(0),
187 //myViewerSelMode(TopAbs_FACE)
189 mySelector = new XGUI_SelectionMgr(this);
190 myModuleConnector = new XGUI_ModuleConnector(this);
191 myOperationMgr = new XGUI_OperationMgr(this, 0);
192 ModuleBase_IWorkshop* aWorkshop = moduleConnector();
193 // Has to be defined first in order to get errors and messages from other components
194 myEventsListener = new XGUI_WorkshopListener(this);
195 mySelectionActivate = new XGUI_SelectionActivate(aWorkshop);
197 SUIT_ResourceMgr* aResMgr = ModuleBase_Preferences::resourceMgr();
199 myMainWindow = new AppElements_MainWindow();
201 bool aCloc = aResMgr->booleanValue("language", "locale", true);
203 QLocale::setDefault( QLocale::c() );
205 QLocale::setDefault( QLocale::system() );
207 QString aPath = Config_XMLReader::pluginConfigFile().c_str();
212 aLangs << "*_en.ts"; // load by default eng translations
213 QString aCurrLang = aResMgr->stringValue("language", "language", "en");
214 if(aCurrLang != "en") {
215 aLangs << "*_" + aCurrLang + ".ts"; // then replace with translated files
218 foreach(QString aLang, aLangs) {
219 QStringList aFilters;
221 QStringList aTsFiles = aDir.entryList(aFilters, QDir::Files);
222 foreach(QString aFileName, aTsFiles) {
223 Config_Translator::load(aFileName.toStdString());
227 myDataModelXMLReader = new Config_DataModelReader();
228 //myDataModelXMLReader->readAll();
230 myDisplayer = new XGUI_Displayer(this);
232 connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(updateCommandStatus()));
234 myActionsMgr = new XGUI_ActionsMgr(this);
235 myActiveControlMgr = new XGUI_ActiveControlMgr(myModuleConnector);
236 myMenuMgr = new XGUI_MenuMgr(this);
237 myErrorDlg = new XGUI_ErrorDialog(QApplication::desktop());
238 myContextMenuMgr = new XGUI_ContextMenuMgr(this);
239 connect(myContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), this,
240 SLOT(onContextMenuCommand(const QString&, bool)));
242 myViewerProxy = new XGUI_ViewerProxy(this);
243 //connect(myViewerProxy, SIGNAL(selectionChanged()),
244 // myActionsMgr, SLOT(updateOnViewSelection()));
246 myOperationMgr->setWorkshop(aWorkshop);
248 myErrorMgr = new XGUI_ErrorMgr(this, aWorkshop);
250 connect(myOperationMgr, SIGNAL(operationResumed(ModuleBase_Operation*)),
251 SLOT(onOperationResumed(ModuleBase_Operation*)));
252 connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
253 SLOT(onOperationStopped(ModuleBase_Operation*)));
254 connect(myOperationMgr, SIGNAL(operationCommitted(ModuleBase_Operation*)),
255 SLOT(onOperationCommitted(ModuleBase_Operation*)));
256 connect(myOperationMgr, SIGNAL(operationAborted(ModuleBase_Operation*)),
257 SLOT(onOperationAborted(ModuleBase_Operation*)));
260 connect(myMainWindow, SIGNAL(exitKeySequence()), SLOT(onExit()));
261 onTrihedronVisibilityChanged(true);
264 connect(myEventsListener, SIGNAL(errorOccurred(std::shared_ptr<Events_InfoMessage>)),
265 myErrorDlg, SLOT(addError(std::shared_ptr<Events_InfoMessage>)));
267 //Config_PropManager::registerProp("Visualization", "object_default_color", "Object color",
268 // Config_Prop::Color, "225,225,225");
270 Config_PropManager::registerProp("Visualization", "result_body_color", "Result color",
271 Config_Prop::Color, ModelAPI_ResultBody::DEFAULT_COLOR());
272 Config_PropManager::registerProp("Visualization", "result_group_color", "Group color",
273 Config_Prop::Color, ModelAPI_ResultGroup::DEFAULT_COLOR());
274 Config_PropManager::registerProp("Visualization", "result_construction_color",
275 "Construction color",
277 ModelAPI_ResultConstruction::DEFAULT_COLOR());
278 Config_PropManager::registerProp("Visualization", "result_part_color", "Part color",
279 Config_Prop::Color, ModelAPI_ResultPart::DEFAULT_COLOR());
280 Config_PropManager::registerProp("Visualization", "result_field_color", "Field color",
281 Config_Prop::Color, ModelAPI_ResultField::DEFAULT_COLOR());
283 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "face-selection", true))
284 myViewerSelMode.append(TopAbs_FACE);
285 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "edge-selection", true))
286 myViewerSelMode.append(TopAbs_EDGE);
287 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "vertex-selection", true))
288 myViewerSelMode.append(TopAbs_VERTEX);
289 //IMP: an attempt to use result selection with other selection modes
290 myViewerSelMode.append(ModuleBase_ResultPrs::Sel_Result);//TopAbs_VERTEX);
291 myViewerSelMode.append(TopAbs_COMPSOLID);
294 //******************************************************
295 XGUI_Workshop::~XGUI_Workshop(void)
298 #ifdef MISSED_TRANSLATION
299 // Save Missed translations
300 Config_Translator::saveMissedTranslations();
305 delete myDataModelXMLReader;
309 //******************************************************
310 void XGUI_Workshop::startApplication()
312 //Initialize event listening
313 myEventsListener->initializeEventListening();
315 myDataModelXMLReader->readAll();
318 Config_PropManager::registerProp("Plugins", "default_path", "Default Path",
319 Config_Prop::Directory, "");
321 std::string aDir = Config_XMLReader::resourcesConfigFile();
322 Config_PropManager::registerProp("Plugins", "import_initial_path", "Import initial directory",
323 Config_Prop::Directory, aDir);
326 Config_PropManager::registerProp("Plugins", "create_part_by_start", "Create Part by Start",
327 Config_Prop::Boolean, "false");
329 Config_PropManager::registerProp("Plugins", "show_hide_faces", "Show Hide Faces (on the right)",
330 Config_Prop::Boolean, "false");
332 registerValidators();
334 // Calling of loadCustomProps before activating module is required
335 // by Config_PropManger to restore user-defined path to plugins
336 ModuleBase_Preferences::loadCustomProps();
340 myMainWindow->show();
341 updateCommandStatus();
346 myViewerProxy->connectViewProxy();
347 connect(myViewerProxy, SIGNAL(trihedronVisibilityChanged(bool)),
348 SLOT(onTrihedronVisibilityChanged(bool)));
350 emit applicationStarted();
353 bool aNewPart = Config_PropManager::boolean("Plugins", "create_part_by_start");
355 module()->launchOperation("Part", false); // PartSetPlugin_Part::ID()
360 //******************************************************
361 void XGUI_Workshop::activateModule()
363 selectionActivate()->updateSelectionFilters();
365 connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
366 myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
367 connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
368 myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
370 updateCommandStatus();
372 // TODO: get default selection mode
374 // activate visualized objects in the viewer
375 activateObjectsSelection(displayer()->displayedObjects());
376 myOperationMgr->activate();
379 //******************************************************
380 void XGUI_Workshop::deactivateModule()
382 // remove internal displayer filter
383 displayer()->deactivateSelectionFilters(false);
385 disconnect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
386 myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
387 disconnect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
388 myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
390 XGUI_Displayer* aDisplayer = displayer();
391 QObjectPtrList aDisplayed = aDisplayer->displayedObjects();
392 aDisplayer->deactivateObjects(aDisplayed, true);
393 selectionActivate()->deactivateTrihedronInSelectionModes();
395 #ifdef BEFORE_TRIHEDRON_PATCH
396 //Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(aDisplayer->getTrihedron());
397 /// Trihedron problem: objects stayed in the viewer, should be removed manually
398 /// otherwise in SALOME happens crash by HideAll in the viewer
399 aContext->Remove(aTrihedron->Position(), true);
400 aContext->Remove(aTrihedron->Axis(), true);
401 aContext->Remove(aTrihedron->XAxis(), true);
402 aContext->Remove(aTrihedron->YAxis(), true);
405 myOperationMgr->deactivate();
408 //******************************************************
409 void XGUI_Workshop::initMenu()
411 myContextMenuMgr->createActions();
414 // Create only Undo, Redo commands
415 QAction* aAction = salomeConnector()->addDesktopCommand("UNDO_CMD", tr("Undo"),
416 tr("Undo last command"),
417 QIcon(":pictures/undo.png"),
418 QKeySequence::Undo, false,
420 QString aToolBarTitle = tr( "INF_DESK_TOOLBAR_STANDARD" );
421 salomeConnector()->addActionInToolbar( aAction,aToolBarTitle );
423 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onUndo()));
424 addHistoryMenu(aAction, SIGNAL(updateUndoHistory(const QList<ActionInfo>&)), SLOT(onUndo(int)));
426 aAction = salomeConnector()->addDesktopCommand("REDO_CMD", tr("Redo"), tr("Redo last command"),
427 QIcon(":pictures/redo.png"), QKeySequence::Redo,
428 false, "MEN_DESK_EDIT");
429 salomeConnector()->addActionInToolbar( aAction, aToolBarTitle );
431 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo()));
432 addHistoryMenu(aAction, SIGNAL(updateRedoHistory(const QList<ActionInfo>&)), SLOT(onRedo(int)));
434 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
436 aAction = salomeConnector()->addDesktopCommand("AUTOCOMPUTE_CMD", tr("Block auto-apply"),
437 tr("Blocks immediate apply of modifications"),
438 QIcon(":pictures/autoapply.png"), QKeySequence(),
439 true, "MEN_DESK_EDIT");
440 salomeConnector()->addActionInToolbar( aAction, aToolBarTitle );
442 connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onAutoApply(bool)));
444 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
447 // Add commands to a file menu
448 aAction = salomeConnector()->addDesktopCommand("SAVEAS_CMD", tr("Export native..."),
449 tr("Export the current document into a native file"),
450 QIcon(), QKeySequence(),
451 false, "MEN_DESK_FILE");
452 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onSaveAs()));
454 aAction = salomeConnector()->addDesktopCommand("OPEN_CMD", tr("Import native..."),
455 tr("Import native file"),
456 QIcon(), QKeySequence(),
457 false, "MEN_DESK_FILE");
458 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onOpen()));
459 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_FILE");
462 // File commands group
463 AppElements_MenuGroupPanel* aGroup = myMainWindow->menuObject()->generalPage();
465 AppElements_Command* aCommand;
467 aCommand = aGroup->addFeature("SAVE_CMD", tr("Save"), tr("Save the document"),
468 QIcon(":pictures/save.png"), QKeySequence::Save);
469 aCommand->connectTo(this, SLOT(onSave()));
470 //aCommand->disable();
472 aCommand = aGroup->addFeature("SAVEAS_CMD", tr("Save as..."), tr("Save the document into a file"),
473 QIcon(":pictures/save.png"), QKeySequence());
474 aCommand->connectTo(this, SLOT(onSaveAs()));
476 QString aUndoId = "UNDO_CMD";
477 aCommand = aGroup->addFeature(aUndoId, tr("Undo"), tr("Undo last command"),
478 QIcon(":pictures/undo.png"), QKeySequence::Undo);
479 aCommand->connectTo(this, SLOT(onUndo()));
480 AppElements_Button* aUndoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aUndoId));
481 addHistoryMenu(aUndoButton,
482 SIGNAL(updateUndoHistory(const QList<ActionInfo>&)),
485 QString aRedoId = "REDO_CMD";
486 aCommand = aGroup->addFeature(aRedoId, tr("Redo"), tr("Redo last command"),
487 QIcon(":pictures/redo.png"), QKeySequence::Redo);
488 aCommand->connectTo(this, SLOT(onRedo()));
489 AppElements_Button* aRedoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aRedoId));
490 addHistoryMenu(aRedoButton,
491 SIGNAL(updateRedoHistory(const QList<ActionInfo>&)),
494 aCommand = aGroup->addFeature("OPEN_CMD", tr("Open..."), tr("Open a new document"),
495 QIcon(":pictures/open.png"), QKeySequence::Open);
496 aCommand->connectTo(this, SLOT(onOpen()));
499 aCommand = aGroup->addFeature("AUTOCOMPUTE_CMD", tr("Auto rebuild"),
500 tr("Blocks immediate apply of modifications"),
501 QIcon(":pictures/autoapply_start.png"), QKeySequence());
502 //aCommand->setChecked(ModelAPI_Session::get()->isAutoUpdateBlocked());
503 aCommand->connectTo(this, SLOT(onAutoApply()));
505 aCommand = aGroup->addFeature("PREF_CMD", tr("Preferences"), tr("Edit preferences"),
506 QIcon(":pictures/preferences.png"), QKeySequence::Preferences);
507 aCommand->connectTo(this, SLOT(onPreferences()));
509 aCommand = aGroup->addFeature("EXIT_CMD", tr("Exit"), tr("Exit application"),
510 QIcon(":pictures/close.png"), QKeySequence::Close);
511 aCommand->connectTo(this, SLOT(onExit()));
516 //******************************************************
517 AppElements_Workbench* XGUI_Workshop::addWorkbench(const QString& theName)
519 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
520 return aMenuBar->addWorkbench(theName);
524 //******************************************************
525 QMainWindow* XGUI_Workshop::desktop() const
528 return salomeConnector()->desktop();
534 //******************************************************
535 void XGUI_Workshop::onStartWaiting()
537 if (Events_LongOp::isPerformed()) {
538 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
542 //******************************************************
543 void XGUI_Workshop::onAcceptActionClicked()
545 QAction* anAction = dynamic_cast<QAction*>(sender());
546 XGUI_OperationMgr* anOperationMgr = operationMgr();
547 if (anOperationMgr) {
548 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
549 (anOperationMgr->currentOperation());
551 //if (errorMgr()->canProcessClick(anAction, aFOperation->feature()))
552 myOperationMgr->commitOperation();
557 //******************************************************
558 void XGUI_Workshop::onAcceptPlusActionClicked()
560 QAction* anAction = dynamic_cast<QAction*>(sender());
561 XGUI_OperationMgr* anOperationMgr = operationMgr();
562 if (anOperationMgr) {
563 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
564 (anOperationMgr->currentOperation());
566 if (myOperationMgr->commitOperation())
567 module()->launchOperation(aFOperation->id(), false);
572 //******************************************************
573 void XGUI_Workshop::onPreviewActionClicked()
575 ModuleBase_IPropertyPanel* aPanel = propertyPanel();
577 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
578 if (anActiveWidget && anActiveWidget->getValueState() == ModuleBase_ModelWidget::ModifiedInPP) {
579 anActiveWidget->storeValue();
582 std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
583 new Events_Message(Events_Loop::eventByName(EVENT_PREVIEW_REQUESTED)));
584 Events_Loop::loop()->send(aMsg);
588 //******************************************************
589 void XGUI_Workshop::onHelpActionClicked()
591 XGUI_OperationMgr* anOperationMgr = operationMgr();
592 if (anOperationMgr) {
593 ModuleBase_Operation* aOperation = anOperationMgr->currentOperation();
595 QString aHelpPage = aOperation->helpFileName();
596 if (!aHelpPage.isEmpty()) {
598 const QChar aSep = QDir::separator();
600 // SUIT_ResourceMgr* aResMgr = ModuleBase_Preferences::resourceMgr();
602 // platform = "winapplication";
604 // platform = "application";
606 // QString aBrowserName = aResMgr->stringValue("ExternalBrowser", platform);
609 QString aDir(getenv("SHAPER_ROOT_DIR"));
610 if (!aDir.isEmpty()) {
611 aDocDir = aDir + aSep + "share" + aSep + "doc" + aSep +
612 "salome" + aSep + "gui" + aSep + "SHAPER";
615 QString aDir(getenv("OPENPARTS_ROOT_DIR"));
616 aDocDir = aDir + aSep + "doc" + aSep + "gui";
618 QString aFileName = aDocDir + aSep + aHelpPage;
619 if (QFile::exists(aFileName)) {
620 QUrl aUrl = QUrl::fromLocalFile(aFileName);
621 QDesktopServices::openUrl(aUrl);
629 //******************************************************
630 void XGUI_Workshop::deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer)
632 if (!myModule->canActivateSelection(theObject)) {
633 if (selectionActivate()->isActive(theObject)) {
634 QObjectPtrList anObjects;
635 anObjects.append(theObject);
636 myDisplayer->deactivateObjects(anObjects, theUpdateViewer);
641 //******************************************************
642 bool XGUI_Workshop::isFeatureOfNested(const FeaturePtr& theFeature)
644 bool aHasNested = false;
645 std::string aFeatureKind = theFeature->getKind();
647 XGUI_SalomeConnector* aSalomeConnector = salomeConnector();
648 if (aSalomeConnector->isFeatureOfNested(actionsMgr()->action(aFeatureKind.c_str())))
651 AppElements_MainMenu* aMenuBar = mainWindow()->menuObject();
652 AppElements_Command* aCommand = aMenuBar->feature(aFeatureKind.c_str());
653 if (aCommand && aCommand->button()->additionalButtonWidget())
659 //******************************************************
660 void XGUI_Workshop::fillPropertyPanel(ModuleBase_Operation* theOperation)
662 ModuleBase_OperationFeature* aFOperation =
663 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
667 showPanel(myPropertyPanel);
668 myPropertyPanel->cleanContent();
670 QList<ModuleBase_ModelWidget*> aWidgets;
671 if (!module()->createWidgets(theOperation, aWidgets)) {
672 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
673 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), myModuleConnector);
674 aFactory.createWidget(myPropertyPanel->contentWidget());
675 aWidgets = aFactory.getModelWidgets();
678 // check compatibility of feature and widgets
679 FeaturePtr aFeature = aFOperation->feature();
680 std::string aFeatureKind = aFeature->getKind();
681 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
682 if (aWidget->usesAttribute()) {
683 if (!aWidget->attributeID().empty() && !aFeature->attribute(aWidget->attributeID()).get()) {
684 std::string anErrorMsg = "The feature '%1' has no attribute '%2' used by widget '%3'.";
685 Events_InfoMessage("XGUI_Workshop", anErrorMsg)
686 .arg(aFeatureKind).arg(aWidget->attributeID())
687 .arg(aWidget->metaObject()->className()).send();
688 myPropertyPanel->cleanContent();
693 // for performance purpose, flush should be done after all controls are filled
694 bool isUpdateFlushed = false;
695 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
696 bool isStoreValue = !aFOperation->isEditOperation() &&
697 !aWidget->getDefaultValue().empty() &&
698 !aWidget->isComputedDefault();
699 aWidget->setFeature(aFeature, isStoreValue, isUpdateFlushed);
701 aWidget->restoreValue();
702 aWidget->enableFocusProcessing();
704 // update visible state of Preview button
705 std::shared_ptr<Config_FeatureMessage> aFeatureInfo;
707 aFeatureInfo = mySalomeConnector->featureInfo(aFeatureKind.c_str());
709 AppElements_MainMenu* aMenuBar = mainWindow()->menuObject();
710 AppElements_Command* aCommand = aMenuBar->feature(aFeatureKind.c_str());
712 aFeatureInfo = aCommand->featureMessage();
714 bool anIsAutoPreview = true;
715 if (aFeatureInfo.get()) {
716 anIsAutoPreview = aFeatureInfo->isAutoPreview();
717 theOperation->setHelpFileName(aFeatureInfo->helpFileName().c_str());
719 std::string aXmlCfg, aDescription;
720 module()->getXMLRepresentation(aFeatureKind, aXmlCfg, aDescription);
721 ModuleBase_WidgetFactory aFactory(aXmlCfg, moduleConnector());
722 anIsAutoPreview = aFactory.widgetAPI()->getBooleanAttribute(FEATURE_AUTO_PREVIEW, true);
725 if (!anIsAutoPreview) {
726 myPropertyPanel->findButton(PROP_PANEL_PREVIEW)->setVisible(true);
727 // send signal about preview should not be computed automatically, click on preview
728 // button should initiate it
729 std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
730 new Events_Message(Events_Loop::eventByName(EVENT_PREVIEW_BLOCKED)));
731 Events_Loop::loop()->send(aMsg);
733 // if update happens after preview is blocked, it does nothing when blocked
734 // it improves performance for valid objects on feature start
735 ModuleBase_Tools::flushUpdated(aFeature);
737 myPropertyPanel->setModelWidgets(aWidgets);
738 aFOperation->setPropertyPanel(myPropertyPanel);
740 myModule->propertyPanelDefined(theOperation);
742 #ifndef DEBUG_FEATURE_NAME
743 myPropertyPanel->setWindowTitle(theOperation->getDescription()->description());
745 std::string aFeatureName = aFeature->name();
746 myPropertyPanel->setWindowTitle(QString("%1: %2")
747 .arg(theOperation->getDescription()->description())
748 .arg(aFeatureName.c_str()));
751 myErrorMgr->setPropertyPanel(myPropertyPanel);
754 //******************************************************
755 void XGUI_Workshop::connectToPropertyPanel(const bool isToConnect)
757 XGUI_PropertyPanel* aPropertyPanel = propertyPanel();
758 if (aPropertyPanel) {
759 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
760 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
761 myModule->connectToPropertyPanel(aWidget, isToConnect);
763 connect(aWidget, SIGNAL(valueStateChanged(int)), this, SLOT(onWidgetStateChanged(int)));
764 connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
765 connect(aWidget, SIGNAL(objectUpdated()), this, SLOT(onWidgetObjectUpdated()));
768 disconnect(aWidget, SIGNAL(valueStateChanged(int)), this, SLOT(onWidgetStateChanged(int)));
769 disconnect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
770 disconnect(aWidget, SIGNAL(objectUpdated()), this, SLOT(onWidgetObjectUpdated()));
776 //******************************************************
777 void XGUI_Workshop::onOperationResumed(ModuleBase_Operation* theOperation)
779 setGrantedFeatures(theOperation);
781 if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
782 fillPropertyPanel(theOperation);
783 connectToPropertyPanel(true);
785 updateCommandStatus();
787 myModule->operationResumed(theOperation);
790 //******************************************************
791 void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
793 updateCommandStatus();
795 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
800 ModuleBase_ISelection* aSel = mySelector->selection();
801 QObjectPtrList aObj = aSel->selectedPresentations();
802 //!< No need for property panel
803 hidePanel(myPropertyPanel);
804 myPropertyPanel->cleanContent();
806 connectToPropertyPanel(false);
807 myModule->operationStopped(aFOperation);
809 // the deactivated objects of the current operation should be activated back.
810 // They were deactivated on operation start or an object redisplay
811 QObjectPtrList anObjects;
812 FeaturePtr aFeature = aFOperation->feature();
813 if (aFeature.get()) { // feature may be not created (plugin load fail)
814 if (myDisplayer->isVisible(aFeature) && !selectionActivate()->isActive(aFeature))
815 anObjects.append(aFeature);
816 std::list<ResultPtr> aResults;
817 ModelAPI_Tools::allResults(aFeature, aResults);
818 std::list<ResultPtr>::const_iterator aIt;
819 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
820 ResultPtr anObject = *aIt;
821 if (myDisplayer->isVisible(anObject) && !selectionActivate()->isActive(anObject)) {
822 anObjects.append(anObject);
826 activateObjectsSelection(anObjects);
829 //******************************************************
830 void XGUI_Workshop::onOperationCommitted(ModuleBase_Operation* theOperation)
832 myModule->operationCommitted(theOperation);
835 //******************************************************
836 void XGUI_Workshop::onOperationAborted(ModuleBase_Operation* theOperation)
838 myModule->operationAborted(theOperation);
841 //******************************************************
842 void XGUI_Workshop::setGrantedFeatures(ModuleBase_Operation* theOperation)
844 ModuleBase_OperationFeature* aFOperation =
845 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
849 QStringList aGrantedIds;
850 if (isSalomeMode()) {
851 const std::shared_ptr<Config_FeatureMessage>& anInfo =
852 mySalomeConnector->featureInfo(theOperation->id());
854 aGrantedIds = QString::fromStdString(anInfo->nestedFeatures())
855 .split(" ", QString::SkipEmptyParts);
858 aGrantedIds = myActionsMgr->nestedCommands(theOperation->id());
860 ModuleBase_IModule* aModule = module();
862 aModule->grantedOperationIds(theOperation, aGrantedIds);
864 aFOperation->setGrantedOperationIds(aGrantedIds);
867 //******************************************************
868 void XGUI_Workshop::saveDocument(const QString& theName, std::list<std::string>& theFileNames)
870 QApplication::restoreOverrideCursor();
871 SessionPtr aMgr = ModelAPI_Session::get();
873 std::list<DocumentPtr> aDocList = aMgr->allOpenedDocuments();
874 std::list<DocumentPtr>::const_iterator aIt;
875 for (aIt = aDocList.cbegin(); aIt != aDocList.cend(); aIt++) {
876 std::list<bool> aState = myObjectBrowser->getStateForDoc(*aIt);
877 (*aIt)->storeNodesState(aState);
880 aMgr->save(theName.toLatin1().constData(), theFileNames);
882 QApplication::restoreOverrideCursor();
885 //******************************************************
886 bool XGUI_Workshop::abortAllOperations()
888 return myOperationMgr->abortAllOperations();
891 //******************************************************
892 void XGUI_Workshop::operationStarted(ModuleBase_Operation* theOperation)
894 setGrantedFeatures(theOperation);
895 if (!theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
896 updateCommandStatus();
899 myModule->operationStarted(theOperation);
903 //******************************************************
904 void XGUI_Workshop::onOpen()
906 if(!abortAllOperations())
908 //save current file before close if modified
909 SessionPtr aSession = ModelAPI_Session::get();
910 if (aSession->isModified()) {
911 //TODO(sbh): re-launch the app?
912 int anAnswer = QMessageBox::question(
913 desktop(), tr("Save current file"),
914 tr("The document is modified, save before opening another?"),
915 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
916 if (anAnswer == QMessageBox::Save) {
918 } else if (anAnswer == QMessageBox::Cancel) {
921 myCurrentFile = QString();
924 //show file dialog, check if readable and open
925 QString aFile = QFileDialog::getOpenFileName(desktop(), tr("Open file"), QString(), MyFilter);
930 //******************************************************
931 void XGUI_Workshop::openFile(const QString& theDirectory)
933 myCurrentFile = theDirectory;
934 if (myCurrentFile.isEmpty())
937 QFileInfo aFileInfo(myCurrentFile);
938 if (!aFileInfo.exists() || !aFileInfo.isReadable()) {
939 QMessageBox::critical(desktop(), tr("Warning"), tr("Unable to open the file."));
940 myCurrentFile = QString();
944 QApplication::setOverrideCursor(Qt::WaitCursor);
945 module()->closeDocument();
946 SessionPtr aSession = ModelAPI_Session::get();
947 aSession->closeAll();
950 XGUI_CompressFiles::uncompress(myCurrentFile, myTmpDir.path());
952 aSession->load(myTmpDir.path().toLatin1().constData());
953 myObjectBrowser->rebuildDataTree();
955 // Open first level of data tree
956 DocumentPtr aRootDoc = aSession->moduleDocument();
957 std::list<bool> aStates;
958 aRootDoc->restoreNodesState(aStates);
959 myObjectBrowser->setStateForDoc(aRootDoc, aStates);
961 updateCommandStatus();
963 myMainWindow->setCurrentDir(myCurrentFile, true);
967 bool aNewPart = Config_PropManager::boolean("Plugins", "create_part_by_start");
970 DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
971 int aSize = aRootDoc->size(ModelAPI_ResultPart::group());
973 ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), 0);
974 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
981 QApplication::restoreOverrideCursor();
984 //******************************************************
985 void XGUI_Workshop::onNew()
987 QApplication::setOverrideCursor(Qt::WaitCursor);
988 if (objectBrowser() == 0) {
990 mySelector->connectViewers();
992 myViewerProxy->connectToViewer();
995 myMainWindow->showPythonConsole();
996 QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
997 aWnd->showMaximized();
998 updateCommandStatus();
1000 myContextMenuMgr->connectViewer();
1001 QApplication::restoreOverrideCursor();
1005 //******************************************************
1006 void XGUI_Workshop::onExit()
1008 SessionPtr aMgr = ModelAPI_Session::get();
1009 if (aMgr->isModified()) {
1010 int anAnswer = QMessageBox::question(
1011 myMainWindow, tr("Save current file"), tr("The document is modified, save before exit?"),
1012 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
1013 if (anAnswer == QMessageBox::Save) {
1014 bool saved = onSave();
1018 } else if (anAnswer == QMessageBox::Cancel) {
1025 //******************************************************
1026 void XGUI_Workshop::onPreferences()
1028 ModuleBase_Prefs aModif;
1029 ModuleBase_Preferences::editPreferences(aModif);
1030 if (aModif.size() > 0) {
1032 foreach (ModuleBase_Pref aPref, aModif)
1034 aSection = aPref.first;
1035 if (aSection == ModuleBase_Preferences::VIEWER_SECTION) {
1036 myMainWindow->viewer()->updateFromResources();
1037 } else if (aSection == ModuleBase_Preferences::MENU_SECTION) {
1038 myMainWindow->menuObject()->updateFromResources();
1041 displayer()->redisplayObjects();
1046 //******************************************************
1047 void XGUI_Workshop::onTrihedronVisibilityChanged(bool theState)
1049 XGUI_Displayer* aDisplayer = displayer();
1051 aDisplayer->displayTrihedron(theState);
1054 //******************************************************
1055 bool XGUI_Workshop::onSave()
1057 if(!myOperationMgr->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
1059 if (myCurrentFile.isEmpty()) {
1062 SessionPtr aMgr = ModelAPI_Session::get();
1063 if (aMgr->isAutoUpdateBlocked())
1064 aMgr->blockAutoUpdate(false);
1066 std::list<std::string> aFiles;
1067 saveDocument(myTmpDir.path(), aFiles);
1068 XGUI_CompressFiles::compress(myCurrentFile, aFiles);
1070 updateCommandStatus();
1072 myMainWindow->setModifiedState(false);
1077 //******************************************************
1078 bool XGUI_Workshop::onSaveAs()
1080 if(!myOperationMgr->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
1082 myCurrentFile = QFileDialog::getSaveFileName(desktop(), tr("Select name to save file..."),
1083 QString(), MyFilter);
1084 if (!myCurrentFile.isNull()) {
1085 if (!myCurrentFile.endsWith(".opp")) {
1086 myCurrentFile += ".opp";
1090 myMainWindow->setCurrentDir(myCurrentFile, false);
1091 myMainWindow->setModifiedState(false);
1096 //******************************************************
1097 void XGUI_Workshop::onUndo(int theTimes)
1099 processUndoRedo(ActionUndo, theTimes);
1100 myObjectBrowser->updateAllIndexes(1);
1103 //******************************************************
1104 void XGUI_Workshop::onRedo(int theTimes)
1106 processUndoRedo(ActionRedo, theTimes);
1107 myObjectBrowser->updateAllIndexes(1);
1110 //******************************************************
1111 void XGUI_Workshop::processUndoRedo(const ModuleBase_ActionType theActionType, int theTimes)
1113 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1114 if (anActiveWidget) {
1115 ActionIntParamPtr aParam(new ModuleBase_ActionIntParameter(theTimes));
1116 if (anActiveWidget->processAction(theActionType, aParam))
1119 // the viewer update should be blocked in order to avoid the features blinking. For the created
1120 // feature a results are created, the flush of the created signal caused the viewer redisplay for
1121 // each created result. After a redisplay signal is flushed. So, the viewer update is blocked
1122 // until redo of all possible objects happens
1123 bool isUpdateEnabled = myDisplayer->enableUpdateViewer(false);
1125 SessionPtr aMgr = ModelAPI_Session::get();
1126 if (aMgr->isOperation()) {
1127 XGUI_OperationMgr* aOpMgr = operationMgr();
1128 /// this is important for nested operations
1129 /// when sketch operation is active, this condition is false and
1130 /// the sketch operation is not aborted
1131 if (aOpMgr->canStopOperation(aOpMgr->currentOperation()))
1132 aOpMgr->abortOperation(aOpMgr->currentOperation());
1135 myDisplayer->enableUpdateViewer(isUpdateEnabled);
1139 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
1140 std::list<std::string> anActionList = theActionType == ActionUndo ? aMgr->undoList()
1142 std::list<std::string>::const_iterator aIt = anActionList.cbegin();
1143 for (int i = 0; (i < theTimes) && (aIt != anActionList.cend()); ++i, ++aIt) {
1144 if (theActionType == ActionUndo)
1149 if (QString((*aIt).c_str()) == MOVE_TO_END_COMMAND)
1150 myObjectBrowser->rebuildDataTree();
1152 operationMgr()->updateApplyOfOperations();
1153 facesPanel()->reset(true);
1154 updateCommandStatus();
1156 // unblock the viewer update functionality and make update on purpose
1157 myDisplayer->enableUpdateViewer(isUpdateEnabled);
1158 myDisplayer->updateViewer();
1159 // Clear messages in status bar from previous operations if exists
1160 setStatusBarMessage("");
1163 //******************************************************
1164 void XGUI_Workshop::onWidgetStateChanged(int thePreviousState)
1166 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1167 //ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
1168 //if (anOperation) {
1169 // ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1171 // anActiveWidget = aPanel->activeWidget();
1174 operationMgr()->onValidateOperation();
1176 myModule->widgetStateChanged(thePreviousState);
1179 //******************************************************
1180 void XGUI_Workshop::onValuesChanged()
1182 ModuleBase_ModelWidget* aSenderWidget = (ModuleBase_ModelWidget*)(sender());
1183 if (!aSenderWidget || aSenderWidget->canAcceptFocus())
1186 ModuleBase_ModelWidget* anActiveWidget = 0;
1187 ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
1189 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1191 anActiveWidget = aPanel->activeWidget();
1193 if (anActiveWidget) {
1194 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1196 if (aWidgetValidated)
1197 aWidgetValidated->clearValidatedCash();
1201 //******************************************************
1202 void XGUI_Workshop::onWidgetObjectUpdated()
1204 operationMgr()->onValidateOperation();
1207 //******************************************************
1208 ModuleBase_IModule* XGUI_Workshop::loadModule(const QString& theModule)
1210 QString libName = QString::fromStdString(library(theModule.toStdString()));
1211 if (libName.isEmpty()) {
1212 qWarning(qPrintable(tr("Information about module \"%1\" doesn't exist.").arg(theModule)));
1217 CREATE_FUNC crtInst = 0;
1220 HINSTANCE modLib = ::LoadLibraryA(qPrintable(libName));
1224 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
1225 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
1226 QString aMsg((char*) &lpMsgBuf);
1227 err = QString("Failed to load %1. %2").arg(libName).arg(aMsg);
1228 ::LocalFree(lpMsgBuf);
1230 crtInst = (CREATE_FUNC) ::GetProcAddress(modLib, CREATE_MODULE);
1234 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
1235 | FORMAT_MESSAGE_IGNORE_INSERTS,
1236 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
1237 QString aMsg((char*) &lpMsgBuf);
1238 err = QString("Failed to find %1 function. %2").arg( CREATE_MODULE).arg(aMsg);
1239 ::LocalFree(lpMsgBuf);
1243 void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY | RTLD_GLOBAL );
1245 err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
1247 crtInst = (CREATE_FUNC)dlsym( modLib, CREATE_MODULE );
1249 err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() );
1254 ModuleBase_IModule* aModule = crtInst ? crtInst(myModuleConnector) : 0;
1256 if (!err.isEmpty()) {
1258 Events_InfoMessage("XGUI_Workshop", err.toStdString()).send();
1260 qWarning(qPrintable(err));
1266 //******************************************************
1267 bool XGUI_Workshop::createModule()
1269 Config_ModuleReader aModuleReader;
1270 QString moduleName = QString::fromStdString(aModuleReader.getModuleName());
1271 myModule = loadModule(moduleName);
1275 //connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
1276 // myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
1277 //connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
1278 // myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
1280 myModule->createFeatures();
1282 salomeConnector()->createFeatureActions();
1284 //myActionsMgr->update();
1288 //******************************************************
1289 void XGUI_Workshop::updateCommandStatus()
1291 QList<QAction*> aCommands;
1293 aCommands = salomeConnector()->commandList();
1295 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
1296 foreach (AppElements_Command* aCmd, aMenuBar->features())
1297 aCommands.append(aCmd);
1299 SessionPtr aMgr = ModelAPI_Session::get();
1300 if (aMgr->hasModuleDocument()) {
1301 foreach(QAction* aCmd, aCommands) {
1302 QString aId = aCmd->data().toString();
1303 if (aId == "UNDO_CMD") {
1304 bool isActionEnabled = false;
1305 // if ultimate is true -> using result of operation only, or using OR combination
1306 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1307 if (anActiveWidget && anActiveWidget->canProcessAction(ActionUndo, isActionEnabled))
1308 aCmd->setEnabled(isActionEnabled);
1310 aCmd->setEnabled(myModule->canUndo());
1312 else if (aId == "REDO_CMD") {
1313 bool isActionEnabled = false;
1314 // if ultimate is true -> using result of operation only, or using OR combination
1315 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1316 if (anActiveWidget && anActiveWidget->canProcessAction(ActionRedo, isActionEnabled))
1317 aCmd->setEnabled(isActionEnabled);
1319 aCmd->setEnabled(myModule->canRedo());
1321 else if (aId == "AUTOCOMPUTE_CMD") {
1322 //aCmd->setChecked(aMgr->isAutoUpdateBlocked());
1323 aCmd->setIcon(aMgr->isAutoUpdateBlocked() ?
1324 QIcon(":pictures/autoapply_stop.png") :
1325 QIcon(":pictures/autoapply_start.png"));
1328 // Enable all commands
1329 aCmd->setEnabled(true);
1333 foreach(QAction* aCmd, aCommands) {
1334 QString aId = aCmd->data().toString();
1335 if (aId == "NEW_CMD")
1336 aCmd->setEnabled(true);
1337 else if (aId == "EXIT_CMD")
1338 aCmd->setEnabled(true);
1340 aCmd->setEnabled(false);
1343 myActionsMgr->updateCommandsStatus();
1344 emit commandStatusUpdated();
1347 //******************************************************
1348 void XGUI_Workshop::updateHistory()
1350 bool isActionEnabled = false;
1351 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1352 QList<ActionInfo> aUndoRes;
1353 QList<ActionInfo> aRedoRes;
1354 if (anActiveWidget && anActiveWidget->canProcessAction(ActionUndo, isActionEnabled)) {
1355 aUndoRes = anActiveWidget->actionsList(ActionUndo);
1356 aRedoRes = anActiveWidget->actionsList(ActionRedo);
1358 std::list<std::string> aUndoList = ModelAPI_Session::get()->undoList();
1359 aUndoRes = processHistoryList(aUndoList);
1361 std::list<std::string> aRedoList = ModelAPI_Session::get()->redoList();
1362 aRedoRes = processHistoryList(aRedoList);
1364 emit updateUndoHistory(aUndoRes);
1365 emit updateRedoHistory(aRedoRes);
1368 //******************************************************
1369 QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
1371 QDockWidget* aObjDock = new QDockWidget(theParent);
1372 aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea |
1373 Qt::RightDockWidgetArea |
1374 Qt::BottomDockWidgetArea);
1375 aObjDock->setWindowTitle(tr("Object browser"));
1376 aObjDock->setStyleSheet(
1377 "::title { position: relative; padding-left: 5px; text-align: left center }");
1378 myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock, this);
1379 myObjectBrowser->initialize(myModule->rootNode());
1380 myModule->customizeObjectBrowser(myObjectBrowser);
1381 aObjDock->setWidget(myObjectBrowser);
1383 myContextMenuMgr->connectObjectBrowser();
1387 //******************************************************
1389 * Creates dock widgets, places them in corresponding area
1390 * and tabifies if necessary.
1392 void XGUI_Workshop::createDockWidgets()
1394 QMainWindow* aDesktop = desktop();
1395 QDockWidget* aObjDock = createObjectBrowser(aDesktop);
1396 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
1397 myPropertyPanel = new XGUI_PropertyPanel(aDesktop, myOperationMgr);
1398 myActiveControlMgr->addSelector(new XGUI_PropertyPanelSelector(myPropertyPanel));
1400 myPropertyPanel->setupActions(myActionsMgr);
1401 myPropertyPanel->setAllowedAreas(Qt::LeftDockWidgetArea |
1402 Qt::RightDockWidgetArea |
1403 Qt::BottomDockWidgetArea);
1404 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel);
1405 hidePanel(myPropertyPanel); ///<! Invisible by default
1407 myFacesPanel = new XGUI_FacesPanel(aDesktop, myModuleConnector);
1408 myActiveControlMgr->addSelector(new XGUI_FacesPanelSelector(myFacesPanel));
1409 myFacesPanel->setAllowedAreas(Qt::LeftDockWidgetArea |
1410 Qt::RightDockWidgetArea |
1411 Qt::BottomDockWidgetArea);
1412 connect(myFacesPanel, SIGNAL(closed()), myFacesPanel, SLOT(onClosed()));
1414 myInspectionPanel = new XGUI_InspectionPanel(aDesktop, mySelector);
1415 myInspectionPanel->setAllowedAreas(Qt::LeftDockWidgetArea |
1416 Qt::RightDockWidgetArea);
1417 aDesktop->addDockWidget(Qt::RightDockWidgetArea, myInspectionPanel);
1419 myInspectionPanel->hide();
1421 aDesktop->addDockWidget(
1423 Qt::RightDockWidgetArea,
1425 Qt::LeftDockWidgetArea,
1428 hidePanel(myFacesPanel); ///<! Invisible by default
1431 bool aShowOnTheRight = Config_PropManager::boolean("Plugins", "show_hide_faces");
1432 if (aShowOnTheRight) {
1433 aDesktop->addDockWidget(Qt::RightDockWidgetArea, myFacesPanel);
1434 showPanel(myFacesPanel);
1437 hideObjectBrowser();
1441 if (!aShowOnTheRight)
1444 aDesktop->tabifyDockWidget(myFacesPanel, aObjDock);
1449 #endif // HAVE_SALOME
1451 aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
1452 myPropertyPanel->installEventFilter(myOperationMgr);
1454 QAction* aOkAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept);
1455 connect(aOkAct, SIGNAL(triggered()), this, SLOT(onAcceptActionClicked()));
1457 QAction* aOkContAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptPlus);
1458 connect(aOkContAct, SIGNAL(triggered()), this, SLOT(onAcceptPlusActionClicked()));
1460 QAction* aCancelAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Abort);
1461 connect(aCancelAct, SIGNAL(triggered()), myOperationMgr, SLOT(onAbortOperation()));
1463 QAction* aPreviewAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Preview);
1464 connect(aPreviewAct, SIGNAL(triggered()), this, SLOT(onPreviewActionClicked()));
1466 QAction* aHelpAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Help);
1467 connect(aHelpAct, SIGNAL(triggered()), this, SLOT(onHelpActionClicked()));
1469 connect(myPropertyPanel, SIGNAL(keyReleased(QObject*, QKeyEvent*)),
1470 myOperationMgr, SLOT(onKeyReleased(QObject*, QKeyEvent*)));
1471 connect(myPropertyPanel, SIGNAL(enterClicked(QObject*)),
1472 myOperationMgr, SLOT(onProcessEnter(QObject*)));
1475 //******************************************************
1476 void XGUI_Workshop::showPanel(QDockWidget* theDockWidget)
1478 if (theDockWidget == myPropertyPanel) {
1479 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1480 ///<! Restore ability to close panel from the window's menu
1481 aViewAct->setEnabled(true);
1483 theDockWidget->show();
1484 theDockWidget->raise();
1486 // The next code is necessary to made the property panel the active window
1487 // in order to operation manager could process key events of the panel.
1488 // otherwise they are ignored. It happens only if the same(activateWindow) is
1489 // not happened by property panel activation(e.g. resume operation of Sketch)
1490 ModuleBase_Tools::setFocus(theDockWidget, "XGUI_Workshop::showPanel()");
1493 //******************************************************
1494 void XGUI_Workshop::hidePanel(QDockWidget* theDockWidget)
1496 if (theDockWidget && theDockWidget == myPropertyPanel) {
1497 QAction* aViewAct = theDockWidget->toggleViewAction();
1498 ///<! Do not allow to show empty property panel
1499 aViewAct->setEnabled(false);
1501 theDockWidget->hide();
1503 // the property panel is active window of the desktop, when it is
1504 // hidden, it is undefined which window becomes active. By this reason
1505 // it is defined to perform the desktop as the active window.
1506 // in SALOME mode, workstack made the PyConsole the active window,
1507 // set the focus on it. As a result, shortcuts of the application, like
1508 // are processed by this console. For example Undo actions.
1509 // It is possible that this code is to be moved to SHAPER package
1510 QMainWindow* aDesktop = desktop();
1511 ModuleBase_Tools::setFocus(aDesktop, "XGUI_Workshop::hidePanel()");
1514 //******************************************************
1515 void XGUI_Workshop::showObjectBrowser()
1517 if (!isSalomeMode()) {
1518 myObjectBrowser->parentWidget()->show();
1522 //******************************************************
1523 void XGUI_Workshop::hideObjectBrowser()
1525 if (!isSalomeMode())
1526 myObjectBrowser->parentWidget()->hide();
1529 //******************************************************
1530 void XGUI_Workshop::salomeViewerSelectionChanged()
1532 emit salomeViewerSelection();
1535 //**************************************************************
1536 ModuleBase_IViewer* XGUI_Workshop::salomeViewer() const
1538 return mySalomeConnector->viewer();
1541 //**************************************************************
1542 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
1544 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1545 if (theId == "DELETE_CMD")
1547 else if (theId == "CLEAN_HISTORY_CMD")
1549 else if (theId == "MOVE_CMD")
1551 else if (theId == "COLOR_CMD")
1552 changeColor(aObjects);
1553 else if (theId == "DEFLECTION_CMD")
1554 changeDeflection(aObjects);
1555 #ifdef USE_TRANSPARENCY
1556 else if (theId == "TRANSPARENCY_CMD")
1557 changeTransparency(aObjects);
1559 else if (theId == "SHOW_CMD") {
1560 showObjects(aObjects, true);
1561 mySelector->updateSelectionBy(ModuleBase_ISelection::Browser);
1562 updateCommandStatus();
1564 else if (theId == "HIDE_CMD") {
1565 showObjects(aObjects, false);
1566 updateCommandStatus();
1568 else if (theId == "SHOW_ONLY_CMD") {
1569 showOnlyObjects(aObjects);
1570 mySelector->updateSelectionBy(ModuleBase_ISelection::Browser);
1571 updateCommandStatus();
1573 else if (theId == "SHADING_CMD")
1574 setDisplayMode(aObjects, XGUI_Displayer::Shading);
1575 else if (theId == "WIREFRAME_CMD")
1576 setDisplayMode(aObjects, XGUI_Displayer::Wireframe);
1577 else if (theId == "HIDEALL_CMD") {
1578 QObjectPtrList aList = myDisplayer->displayedObjects();
1579 foreach (ObjectPtr aObj, aList) {
1580 if (module()->canEraseObject(aObj))
1581 aObj->setDisplayed(false);
1583 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1585 //issue #2159 Hide all incomplete behavior
1586 viewer()->eraseAll();
1588 updateCommandStatus();
1589 // Necessary for update icons in ObjectBrowser on Linux
1590 myObjectBrowser->updateAllIndexes();
1591 } else if (theId == "SELECT_VERTEX_CMD") {
1592 setViewerSelectionMode(TopAbs_VERTEX);
1593 } else if (theId == "SELECT_EDGE_CMD") {
1594 setViewerSelectionMode(TopAbs_EDGE);
1595 } else if (theId == "SELECT_FACE_CMD") {
1596 setViewerSelectionMode(TopAbs_FACE);
1597 } else if (theId == "INSERT_FOLDER_CMD") {
1598 insertFeatureFolder();
1599 } else if (theId == "ADD_TO_FOLDER_BEFORE_CMD") {
1600 insertToFolder(true);
1601 } else if (theId == "ADD_TO_FOLDER_AFTER_CMD") {
1602 insertToFolder(false);
1603 } else if (theId == "ADD_OUT_FOLDER_BEFORE_CMD") {
1604 moveOutFolder(true);
1605 } else if (theId == "ADD_OUT_FOLDER_AFTER_CMD") {
1606 moveOutFolder(false);
1607 } else if (theId == "SELECT_RESULT_CMD") {
1608 //setViewerSelectionMode(-1);
1609 //IMP: an attempt to use result selection with other selection modes
1610 setViewerSelectionMode(ModuleBase_ResultPrs::Sel_Result);
1611 setViewerSelectionMode(TopAbs_COMPSOLID);
1612 } else if (theId == "SHOW_RESULTS_CMD") {
1613 highlightResults(aObjects);
1614 } else if (theId == "SHOW_FEATURE_CMD") {
1615 highlightFeature(aObjects);
1618 else if (theId == "TINSPECTOR_VIEW") {
1619 Handle(CDF_Application) anApplication = CDF_Session::CurrentSession()->CurrentApplication();
1620 if (!anApplication.IsNull())
1622 if (!MyTCommunicator)
1624 MyTCommunicator = new TInspector_Communicator();
1626 NCollection_List<Handle(Standard_Transient)> aParameters;
1627 aParameters.Append(anApplication);
1628 Handle(AIS_InteractiveContext) aContext = viewer()->AISContext();
1629 if (!aContext.IsNull())
1630 aParameters.Append(aContext);
1632 #ifdef DEBUG_WITH_MESSAGE_REPORT
1633 Handle(Message_Report) aContextReport = aContext->GetReport();
1634 aContext->SetReportActive (Standard_True);
1635 aContextReport->SetLimit (1000);
1636 if (!aContextReport.IsNull())
1637 aParameters.Append(aContextReport);
1639 MyVCallBack = new VInspector_CallBack();
1640 myDisplayer->setCallBack(MyVCallBack);
1642 AppElements_Viewer* aViewer = mainWindow()->viewer();
1644 aViewer->setCallBack(MyVCallBack);
1646 aParameters.Append(MyVCallBack);
1648 MyTCommunicator->RegisterPlugin("TKDFBrowser");
1649 MyTCommunicator->RegisterPlugin("TKShapeView");
1650 MyTCommunicator->RegisterPlugin("TKVInspector");
1651 #ifdef DEBUG_WITH_MESSAGE_REPORT
1652 MyTCommunicator->RegisterPlugin("TKMessageView");
1654 //MyTCommunicator->RegisterPlugin("SMBrowser"); // custom plugin to view ModelAPI
1655 //MyTCommunicator->RegisterPlugin("TKSMBrowser"); // custom plugin to view ModelAPI
1657 MyTCommunicator->Init(aParameters);
1658 MyTCommunicator->Activate("TKSMBrowser"); // to have button in TInspector
1659 #ifndef DEBUG_WITH_MESSAGE_REPORT
1660 MyTCommunicator->Activate("TKVInspector"); // to have filled callback by model
1662 MyTCommunicator->Activate("TKDFBrowser");
1664 #ifdef DEBUG_WITH_MESSAGE_REPORT
1665 MyTCommunicator->Activate("TKMessageView"); // temporary
1666 MyTCommunicator->Activate("TKVInspector"); // to have filled callback by model
1669 MyTCommunicator->SetVisible(true);
1675 //**************************************************************
1676 void XGUI_Workshop::setViewerSelectionMode(int theMode)
1679 myViewerSelMode.clear();
1681 if (myViewerSelMode.contains(theMode))
1682 myViewerSelMode.removeAll(theMode);
1684 myViewerSelMode.append(theMode);
1686 selectionActivate()->updateSelectionModes();
1689 //**************************************************************
1690 void XGUI_Workshop::activateObjectsSelection(const QObjectPtrList& theList)
1693 module()->activeSelectionModes(aModes);
1694 if (aModes.isEmpty() && (myViewerSelMode.length() > 0))
1695 aModes.append(myViewerSelMode);
1696 selectionActivate()->activateObjects(aModes, theList);
1699 //**************************************************************
1700 bool XGUI_Workshop::prepareForDisplay(const std::set<ObjectPtr>& theObjects) const
1702 if (facesPanel()->isEmpty())
1705 // generate container of objects taking into account sub elments of compsolid
1706 std::set<ObjectPtr> anAllProcessedObjects;
1707 for (std::set<ObjectPtr>::const_iterator anObjectsIt = theObjects.begin();
1708 anObjectsIt != theObjects.end(); anObjectsIt++) {
1709 ObjectPtr anObject = *anObjectsIt;
1710 ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(anObject);
1711 if (aCompRes.get()) {
1712 std::list<ResultPtr> allRes;
1713 ModelAPI_Tools::allSubs(aCompRes, allRes);
1714 if (allRes.empty()) {
1715 anAllProcessedObjects.insert(anObject);
1717 for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
1718 ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aRes);
1719 if (aBody.get() && aBody->numberOfSubs() == 0)
1720 anAllProcessedObjects.insert(aBody);
1724 anAllProcessedObjects.insert(anObject);
1727 // find hidden objects in faces panel
1728 std::set<ObjectPtr> aHiddenObjects;
1729 QStringList aHiddenObjectNames;
1730 for (std::set<ObjectPtr>::const_iterator anObjectsIt = anAllProcessedObjects.begin();
1731 anObjectsIt != anAllProcessedObjects.end(); anObjectsIt++) {
1732 if (!facesPanel()->isObjectHiddenByPanel(*anObjectsIt))
1734 aHiddenObjects.insert(*anObjectsIt);
1735 aHiddenObjectNames.append((*anObjectsIt)->data()->name().c_str());
1737 if (aHiddenObjects.empty()) // in parameter objects there are no hidden objects in hide face
1740 int anAnswer = QMessageBox::question(
1741 desktop(), tr("Show object"),
1742 tr("'%1'\n are hidden by %2:\nRemove objects from the panel to be displayed?")
1743 .arg(aHiddenObjectNames.join(", ")).arg(facesPanel()->windowTitle()),
1744 QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
1746 bool aToBeDisplayed = anAnswer == QMessageBox::Yes;
1748 facesPanel()->restoreObjects(aHiddenObjects);
1750 return aToBeDisplayed;
1753 //**************************************************************
1754 void XGUI_Workshop::deleteObjects()
1756 ModuleBase_IModule* aModule = module();
1757 // allow the module to delete objects, do nothing if it has succeed
1758 if (aModule->deleteObjects()) {
1759 updateCommandStatus();
1763 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1764 if (!abortAllOperations())
1767 bool hasResult = false;
1768 bool hasFeature = false;
1769 bool hasParameter = false;
1770 bool hasCompositeOwner = false;
1771 bool hasResultInHistory = false;
1772 bool hasFolder = false;
1773 ModuleBase_Tools::checkObjects(anObjects, hasResult, hasFeature, hasParameter, hasCompositeOwner,
1774 hasResultInHistory, hasFolder);
1775 if (!(hasFeature || hasParameter || hasFolder))
1779 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1780 std::set<FeaturePtr> aFeatures;
1781 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1782 ModelAPI_Tools::findAllReferences(aFeatures, aReferences);
1784 std::set<FolderPtr> aFolders;
1785 ModuleBase_Tools::convertToFolders(anObjects, aFolders);
1788 QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text() + " %1";
1789 aDescription = aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
1790 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, module());
1792 operationMgr()->startOperation(anOpAction);
1794 std::set<FeaturePtr> aFeatureRefsToDelete;
1795 if (ModuleBase_Tools::askToDelete(aFeatures, aReferences, desktop(), aFeatureRefsToDelete)) {
1796 // WORKAROUND, should be done before each object remove, if it presents in XGUI_DataModel tree
1797 // It is necessary to clear selection in order to avoid selection changed event during
1798 // deletion and negative consequences connected with processing of already deleted items
1799 mySelector->clearSelection();
1801 if (!aFeatureRefsToDelete.empty())
1802 aFeatures.insert(aFeatureRefsToDelete.begin(), aFeatureRefsToDelete.end());
1803 aDone = ModelAPI_Tools::removeFeatures(aFeatures, false);
1805 if (aFolders.size() > 0) {
1806 std::set<FolderPtr>::const_iterator anIt = aFolders.begin(),
1807 aLast = aFolders.end();
1808 for (; anIt != aLast; anIt++) {
1809 FolderPtr aFolder = *anIt;
1810 if (aFolder.get()) {
1811 DocumentPtr aDoc = aFolder->document();
1812 aDoc->removeFolder(aFolder);
1818 operationMgr()->commitOperation();
1820 operationMgr()->abortOperation(operationMgr()->currentOperation());
1823 //**************************************************************
1824 void addRefsToFeature(const FeaturePtr& theFeature,
1825 const std::map<FeaturePtr, std::set<FeaturePtr> >& theMainList,
1826 std::set<FeaturePtr>& theReferences)
1828 //if (theReferences.find(theFeature) != theReferences.end())
1830 if (theMainList.find(theFeature) == theMainList.end())
1831 return; // this feature is not in the selection list, so exists without references to it
1832 std::set<FeaturePtr> aMainReferences = theMainList.at(theFeature);
1834 std::set<FeaturePtr>::const_iterator anIt = aMainReferences.begin(),
1835 aLast = aMainReferences.end();
1836 for (; anIt != aLast; anIt++) {
1837 FeaturePtr aRefFeature = *anIt;
1838 if (theReferences.find(aRefFeature) == theReferences.end())
1839 theReferences.insert(aRefFeature);
1840 addRefsToFeature(aRefFeature, theMainList, theReferences);
1844 //**************************************************************
1845 void XGUI_Workshop::cleanHistory()
1847 if (!abortAllOperations())
1850 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1851 std::set<FeaturePtr> aFeatures;
1852 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1854 #ifdef DEBUG_CLEAN_HISTORY
1856 std::set<FeaturePtr>::const_iterator aFIt;
1857 for (aFIt = aFeatures.begin(); aFIt != aFeatures.end(); ++aFIt) {
1858 FeaturePtr aFeature = ModelAPI_Feature::feature(*aFIt);
1859 anInfo.append(aFeature->name().c_str());
1861 QString anInfoStr = anInfo.join(";\t");
1862 qDebug(QString("cleanHistory for: [%1] - %2").
1863 arg(aFeatures.size()).arg(anInfoStr).toStdString().c_str());
1866 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1867 ModelAPI_Tools::findAllReferences(aFeatures, aReferences, true, false);
1868 // find for each object whether all reference values are in the map as key, that means that there
1869 // is no other reference in the model to this object, so it might be removed by cleaning history
1870 // sk_1(ext_1, vertex_1) + (sk_3, bool_1) - cann't be deleted, dependency to bool_1
1871 // ext_1(bool_1, sk_3) - cann't be deleted, dependency to bool_1
1873 // sk_2(ext_2) + (bool_1) - cann't be deleted, dependency to bool_1
1874 // ext_2(bool_1) - cann't be deleted, dependency to bool_1
1876 // Information: bool_1 is not selected
1877 std::set<FeaturePtr> anUnusedObjects;
1878 std::map<FeaturePtr, std::set<FeaturePtr> >::const_iterator aMainIt = aReferences.begin(),
1879 aMainLast = aReferences.end();
1880 for (; aMainIt != aMainLast; aMainIt++) {
1881 FeaturePtr aMainListFeature = aMainIt->first;
1882 std::set<FeaturePtr> aMainRefList = aMainIt->second;
1883 std::set<FeaturePtr>::const_iterator aRefIt = aMainRefList.begin(),
1884 aRefLast = aMainRefList.end();
1885 bool aFeatureOutOfTheList = false;
1886 for (; aRefIt != aRefLast && !aFeatureOutOfTheList; aRefIt++) {
1887 FeaturePtr aRefFeature = *aRefIt;
1888 aFeatureOutOfTheList = aReferences.find(aRefFeature) == aReferences.end();
1890 if (!aFeatureOutOfTheList)
1891 anUnusedObjects.insert(aMainListFeature);
1894 #ifdef DEBUG_CLEAN_HISTORY
1896 for (aFIt = anUnusedObjects.begin(); aFIt != anUnusedObjects.end(); ++aFIt) {
1897 FeaturePtr aFeature = *aFIt;
1898 anInfo.append(aFeature->name().c_str());
1900 qDebug(QString("unused objects: [%1] - %2").
1901 arg(anInfo.size()).arg(anInfo.join(";\t")).toStdString().c_str());
1904 // warn about the references remove, break the delete operation if the user chose it
1905 if (!anUnusedObjects.empty()) {
1907 foreach (const FeaturePtr& aFeature, anUnusedObjects) {
1908 aNames.append(aFeature->name().c_str());
1911 QString anUnusedNames = aNames.join(", ");
1913 QString anActionId = "CLEAN_HISTORY_CMD";
1914 QString aDescription = contextMenuMgr()->action(anActionId)->text();
1916 QMessageBox aMessageBox(desktop());
1917 aMessageBox.setWindowTitle(aDescription);
1918 aMessageBox.setIcon(QMessageBox::Warning);
1919 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
1920 aMessageBox.setDefaultButton(QMessageBox::No);
1922 const char* aKeyStr = "Unused features are the following: "
1923 "%1.\nThese features will be deleted.\nWould you like to continue?";
1924 QString aText = QString(tr(aKeyStr).arg(anUnusedNames));
1925 aMessageBox.setText(aText);
1926 if (aMessageBox.exec() == QMessageBox::No)
1929 // 1. start operation
1930 aDescription += "by deleting of " +
1931 aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
1932 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, module());
1933 operationMgr()->startOperation(anOpAction);
1935 // WORKAROUND, should be done before each object remove, if it presents in XGUI_DataModel tree
1936 // It is necessary to clear selection in order to avoid selection changed event during
1937 // deletion and negative consequences connected with processing of already deleted items
1938 mySelector->clearSelection();
1940 std::set<FeaturePtr> anIgnoredFeatures;
1941 if (ModelAPI_Tools::removeFeatures(anUnusedObjects, true)) {
1942 operationMgr()->commitOperation();
1945 operationMgr()->abortOperation(operationMgr()->currentOperation());
1949 QString anActionId = "CLEAN_HISTORY_CMD";
1950 QString aDescription = contextMenuMgr()->action(anActionId)->text();
1952 QMessageBox aMessageBox(desktop());
1953 aMessageBox.setWindowTitle(aDescription);
1954 aMessageBox.setIcon(QMessageBox::Warning);
1955 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
1956 aMessageBox.setDefaultButton(QMessageBox::No);
1959 aMessageBox.setStandardButtons(QMessageBox::Ok);
1960 aMessageBox.setDefaultButton(QMessageBox::Ok);
1962 aText = QString(tr("All features are relevant, there is nothing to be deleted"));
1963 aMessageBox.setText(aText);
1965 if (aMessageBox.exec() == QMessageBox::No)
1970 //**************************************************************
1971 void XGUI_Workshop::moveObjects()
1973 if (!abortAllOperations())
1976 SessionPtr aMgr = ModelAPI_Session::get();
1978 QString anActionId = "MOVE_CMD";
1979 QString aDescription = contextMenuMgr()->action(anActionId)->text();
1980 aMgr->startOperation(aDescription.toStdString());
1982 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1983 // It is necessary to clear selection in order to avoid selection changed event during
1984 // moving and negative consequences connected with processing of already moved items
1985 mySelector->clearSelection();
1986 // check whether the object can be moved. There should not be parts which are not loaded
1987 std::set<FeaturePtr> aFeatures;
1988 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1989 if (!XGUI_Tools::canRemoveOrRename(desktop(), aFeatures))
1992 DocumentPtr anActiveDocument = aMgr->activeDocument();
1993 FeaturePtr aCurrentFeature = anActiveDocument->currentFeature(true);
1994 std::set<FeaturePtr>::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
1995 for (; anIt != aLast; anIt++) {
1996 FeaturePtr aFeature = *anIt;
1997 if (!aFeature.get() || !myModule->canApplyAction(aFeature, anActionId))
2000 anActiveDocument->moveFeature(aFeature, aCurrentFeature);
2001 aCurrentFeature = anActiveDocument->currentFeature(true);
2003 aMgr->finishOperation();
2006 //**************************************************************
2007 bool XGUI_Workshop::deleteFeatures(const QObjectPtrList& theObjects)
2009 std::set<FeaturePtr> aFeatures;
2010 ModuleBase_Tools::convertToFeatures(theObjects, aFeatures);
2012 return ModelAPI_Tools::removeFeaturesAndReferences(aFeatures);
2015 //******************************************************
2016 bool hasResults(QObjectPtrList theObjects, const std::set<std::string>& theTypes)
2018 bool isFoundResultType = false;
2019 foreach(ObjectPtr anObj, theObjects)
2021 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
2022 if (aResult.get() == NULL)
2025 isFoundResultType = theTypes.find(aResult->groupName()) != theTypes.end();
2026 if (isFoundResultType)
2029 return isFoundResultType;
2032 //**************************************************************
2033 // Returns the list of all features for theDocument and all features of
2034 // all nested parts.
2035 std::list<FeaturePtr> allFeatures(const DocumentPtr& theDocument)
2037 std::list<FeaturePtr> aResultList;
2038 std::list<FeaturePtr> anAllFeatures = theDocument->allFeatures();
2039 foreach (const FeaturePtr& aFeature, anAllFeatures) {
2040 // The order of appending features of the part and the part itself is important
2042 // Append features from a part feature
2043 std::list<ResultPtr> aResults;
2044 ModelAPI_Tools::allResults(aFeature, aResults);
2045 foreach (const ResultPtr& aResult, aResults) {
2046 ResultPartPtr aResultPart =
2047 std::dynamic_pointer_cast<ModelAPI_ResultPart>(aResult);
2048 if (aResultPart.get() && aResultPart->partDoc().get()) {
2050 std::list<FeaturePtr> anAllFeatures = allFeatures(aResultPart->partDoc());
2051 aResultList.insert(aResultList.end(), anAllFeatures.begin(), anAllFeatures.end());
2055 aResultList.push_back(aFeature);
2060 //**************************************************************
2061 // Returns the list of features placed between theObject and the current feature
2062 // in the same document. Excludes theObject, includes the current feature.
2063 std::list<FeaturePtr> toCurrentFeatures(const ObjectPtr& theObject)
2065 std::list<FeaturePtr> aResult;
2066 DocumentPtr aDocument = theObject->document();
2067 std::list<FeaturePtr> anAllFeatures = allFeatures(aDocument);
2068 // find the object iterator
2069 std::list<FeaturePtr>::iterator aObjectIt =
2070 std::find(anAllFeatures.begin(), anAllFeatures.end(), theObject);
2071 if (aObjectIt == anAllFeatures.end())
2073 // find the current feature iterator
2074 std::list<FeaturePtr>::iterator aCurrentIt =
2075 std::find(anAllFeatures.begin(), anAllFeatures.end(), aDocument->currentFeature(true));
2076 if (aCurrentIt == anAllFeatures.end())
2078 // check the right order
2079 if (std::distance(aObjectIt, anAllFeatures.end()) <=
2080 std::distance(aCurrentIt, anAllFeatures.end()))
2082 // exclude the object
2083 std::advance(aObjectIt, 1);
2084 // include the current feature
2085 std::advance(aCurrentIt, 1);
2086 return std::list<FeaturePtr>(aObjectIt, aCurrentIt);
2089 //******************************************************
2090 bool XGUI_Workshop::canMoveFeature()
2092 QString anActionId = "MOVE_CMD";
2094 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
2095 QObjectPtrList aValidatedObjects;
2096 foreach (ObjectPtr aObject, aObjects) {
2097 if (!myModule->canApplyAction(aObject, anActionId))
2099 // To be moved feature should be in active document
2100 if (aObject->document() != ModelAPI_Session::get()->activeDocument())
2102 aValidatedObjects.append(aObject);
2104 if (aValidatedObjects.size() != aObjects.size())
2105 aObjects = aValidatedObjects;
2107 bool aCanMove = !aObjects.empty();
2109 QObjectPtrList::const_iterator anIt = aObjects.begin(), aLast = aObjects.end();
2110 for (; anIt != aLast && aCanMove; anIt++) {
2111 ObjectPtr aObject = *anIt;
2112 if (!aObject.get() || !aObject->data().get() || !aObject->data()->isValid()) {
2116 FeaturePtr aFeat = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
2117 // only groups can be moved to the end for now (#2451)
2118 if (aFeat.get() && aFeat->getKind() != "Group") {
2123 // 1. Get features placed between selected and current in the document
2124 std::list<FeaturePtr> aFeaturesBetween = toCurrentFeatures(aObject);
2125 // if aFeaturesBetween is empty it means wrong order or aObject is the current feature
2126 if (aFeaturesBetween.empty())
2129 std::set<FeaturePtr> aPlacedFeatures(aFeaturesBetween.begin(), aFeaturesBetween.end());
2130 // 2. Get all reference features to the selected object in the document
2131 std::set<FeaturePtr> aRefFeatures;
2132 ModuleBase_Tools::refsToFeatureInFeatureDocument(aObject, aRefFeatures);
2134 if (aRefFeatures.empty())
2137 // 3. Find any placed features in all reference features
2138 std::set<FeaturePtr> aIntersectionFeatures;
2139 std::set_intersection(aRefFeatures.begin(), aRefFeatures.end(),
2140 aPlacedFeatures.begin(), aPlacedFeatures.end(),
2141 std::inserter(aIntersectionFeatures, aIntersectionFeatures.begin()));
2142 // 4. Return false if any reference feature is placed before current feature
2143 if (!aIntersectionFeatures.empty())
2151 //**************************************************************
2152 bool XGUI_Workshop::canBeShaded(const ObjectPtr& theObject) const
2154 bool aCanBeShaded = myDisplayer->canBeShaded(theObject);
2155 if (!aCanBeShaded) {
2156 ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theObject);
2157 if (aCompRes.get() != NULL) { // change colors for all sub-solids
2158 std::list<ResultPtr> allRes;
2159 ModelAPI_Tools::allSubs(aCompRes, allRes);
2160 std::list<ResultPtr>::iterator aRes = allRes.begin();
2161 for(; aRes != allRes.end() && !aCanBeShaded; aRes++) {
2162 aCanBeShaded = myDisplayer->canBeShaded(*aRes);
2166 return aCanBeShaded;
2169 //**************************************************************
2170 bool XGUI_Workshop::canChangeProperty(const QString& theActionName) const
2172 if (theActionName == "COLOR_CMD" ||
2173 theActionName == "DEFLECTION_CMD"
2174 #ifdef USE_TRANSPARENCY
2175 || theActionName == "TRANSPARENCY_CMD"
2178 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
2180 std::set<std::string> aTypes;
2181 aTypes.insert(ModelAPI_ResultGroup::group());
2182 aTypes.insert(ModelAPI_ResultConstruction::group());
2183 aTypes.insert(ModelAPI_ResultBody::group());
2184 aTypes.insert(ModelAPI_ResultPart::group());
2186 return hasResults(aObjects, aTypes);
2191 //******************************************************
2192 void setColor(ResultPtr theResult, const std::vector<int>& theColor)
2194 if (!theResult.get())
2197 AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
2198 if (aColorAttr.get() != NULL) {
2199 if (!aColorAttr->size()) {
2200 aColorAttr->setSize(3);
2202 aColorAttr->setValue(0, theColor[0]);
2203 aColorAttr->setValue(1, theColor[1]);
2204 aColorAttr->setValue(2, theColor[2]);
2208 //**************************************************************
2209 void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
2212 AttributeIntArrayPtr aColorAttr;
2213 // 1. find the current color of the object. This is a color of AIS presentation
2214 // The objects are iterated until a first valid color is found
2215 std::vector<int> aColor;
2216 foreach(ObjectPtr anObject, theObjects) {
2217 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
2218 if (aResult.get()) {
2219 XGUI_CustomPrs::getResultColor(aResult, aColor);
2222 // TODO: remove the obtaining a color from the AIS object
2223 // this does not happen never because:
2224 // 1. The color can be changed only on results
2225 // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
2226 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
2227 if (anAISObj.get()) {
2229 anAISObj->getColor(aColor[0], aColor[1], aColor[2]);
2232 if (!aColor.empty())
2235 if (aColor.size() != 3)
2238 if (!abortAllOperations())
2240 // 2. show the dialog to change the value
2241 XGUI_ColorDialog* aDlg = new XGUI_ColorDialog(desktop());
2242 aDlg->setColor(aColor);
2243 aDlg->move(QCursor::pos());
2244 bool isDone = aDlg->exec() == QDialog::Accepted;
2248 bool isRandomColor = aDlg->isRandomColor();
2250 // 3. abort the previous operation and start a new one
2251 SessionPtr aMgr = ModelAPI_Session::get();
2252 QString aDescription = contextMenuMgr()->action("COLOR_CMD")->text();
2253 aMgr->startOperation(aDescription.toStdString());
2255 // 4. set the value to all results
2256 std::vector<int> aColorResult = aDlg->getColor();
2257 foreach(ObjectPtr anObj, theObjects) {
2258 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
2259 if (aResult.get() != NULL) {
2260 ResultBodyPtr aBodyResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
2261 if (aBodyResult.get() != NULL) { // change colors for all sub-solids
2262 std::list<ResultPtr> allRes;
2263 ModelAPI_Tools::allSubs(aBodyResult, allRes);
2264 for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
2265 setColor(*aRes, !isRandomColor ? aColorResult : aDlg->getRandomColor());
2268 setColor(aResult, !isRandomColor ? aColorResult : aDlg->getRandomColor());
2271 aMgr->finishOperation();
2272 updateCommandStatus();
2275 //**************************************************************
2276 void setDeflection(ResultPtr theResult, const double theDeflection)
2278 if (!theResult.get())
2281 AttributeDoublePtr aDeflectionAttr = theResult->data()->real(ModelAPI_Result::DEFLECTION_ID());
2282 if (aDeflectionAttr.get() != NULL)
2283 aDeflectionAttr->setValue(theDeflection);
2286 //**************************************************************
2287 void setTransparency(ResultPtr theResult, double theTransparency)
2289 if (!theResult.get())
2292 AttributeDoublePtr anAttribute = theResult->data()->real(ModelAPI_Result::TRANSPARENCY_ID());
2293 if (anAttribute.get() != NULL)
2294 anAttribute->setValue(theTransparency);
2297 //**************************************************************
2298 void setTransparency(double theTransparency, const QObjectPtrList& theObjects)
2300 foreach(ObjectPtr anObj, theObjects) {
2301 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
2302 if (aResult.get() != NULL) {
2303 ResultBodyPtr aBodyResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
2304 if (aBodyResult.get() != NULL) { // change property for all sub-solids
2305 std::list<ResultPtr> allRes;
2306 ModelAPI_Tools::allSubs(aBodyResult, allRes);
2307 for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
2308 setTransparency(*aRes, theTransparency);
2311 setTransparency(aResult, theTransparency);
2316 //**************************************************************
2317 void XGUI_Workshop::changeDeflection(const QObjectPtrList& theObjects)
2319 AttributeDoublePtr aDoubleAttr;
2320 // 1. find the current property of the object. This is a property of AIS presentation
2321 // The objects are iterated until a first valid property is found
2322 double aDeflection = -1;
2323 foreach(ObjectPtr anObject, theObjects) {
2324 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
2325 if (aResult.get()) {
2326 aDeflection = XGUI_CustomPrs::getResultDeflection(aResult);
2329 // TODO: remove the obtaining a property from the AIS object
2330 // this does not happen never because:
2331 // 1. The property can be changed only on results
2332 // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
2333 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
2334 if (anAISObj.get()) {
2335 aDeflection = anAISObj->getDeflection();
2338 if (aDeflection > 0)
2341 if (aDeflection < 0)
2344 if (!abortAllOperations())
2346 // 2. show the dialog to change the value
2347 XGUI_DeflectionDialog* aDlg = new XGUI_DeflectionDialog(desktop());
2348 aDlg->setDeflection(aDeflection);
2349 aDlg->move(QCursor::pos());
2350 bool isDone = aDlg->exec() == QDialog::Accepted;
2354 // 3. abort the previous operation and start a new one
2355 SessionPtr aMgr = ModelAPI_Session::get();
2356 QString aDescription = contextMenuMgr()->action("DEFLECTION_CMD")->text();
2357 aMgr->startOperation(aDescription.toStdString());
2359 // 4. set the value to all results
2360 aDeflection = aDlg->getDeflection();
2361 foreach(ObjectPtr anObj, theObjects) {
2362 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
2363 if (aResult.get() != NULL) {
2364 ResultBodyPtr aBodyResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
2365 if (aBodyResult.get() != NULL) { // change property for all sub-solids
2366 std::list<ResultPtr> allRes;
2367 ModelAPI_Tools::allSubs(aBodyResult, allRes);
2368 for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
2369 setDeflection(*aRes, aDeflection);
2372 setDeflection(aResult, aDeflection);
2375 aMgr->finishOperation();
2376 updateCommandStatus();
2379 //**************************************************************
2380 void XGUI_Workshop::changeTransparency(const QObjectPtrList& theObjects)
2382 AttributeDoublePtr aDoubleAttr;
2383 // 1. find the current property of the object. This is a property of AIS presentation
2384 // The objects are iterated until a first valid property is found
2385 double aCurrentValue = -1;
2386 foreach(ObjectPtr anObject, theObjects) {
2387 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
2388 if (aResult.get()) {
2389 aCurrentValue = XGUI_CustomPrs::getResultTransparency(aResult);
2392 // TODO: remove the obtaining a property from the AIS object
2393 // this does not happen never because:
2394 // 1. The property can be changed only on results
2395 // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
2396 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
2397 if (anAISObj.get()) {
2398 aCurrentValue = anAISObj->getDeflection();
2401 if (aCurrentValue > 0)
2404 if (aCurrentValue < 0)
2407 if (!abortAllOperations())
2410 // 2. show the dialog to change the value
2411 XGUI_PropertyDialog* aDlg = new XGUI_PropertyDialog(desktop());
2412 aDlg->setWindowTitle("Transparency");
2413 XGUI_TransparencyWidget* aTransparencyWidget = new XGUI_TransparencyWidget(aDlg);
2414 connect(aTransparencyWidget, SIGNAL(transparencyValueChanged()),
2415 this, SLOT(onTransparencyValueChanged()));
2416 connect(aTransparencyWidget, SIGNAL(previewStateChanged()),
2417 this, SLOT(onPreviewStateChanged()));
2418 aDlg->setContent(aTransparencyWidget);
2419 aTransparencyWidget->setValue(aCurrentValue);
2421 // 3. abort the previous operation and start a new one
2422 SessionPtr aMgr = ModelAPI_Session::get();
2423 QString aDescription = contextMenuMgr()->action("TRANSPARENCY_CMD")->text();
2424 aMgr->startOperation(aDescription.toStdString());
2426 aDlg->move(QCursor::pos());
2427 bool isDone = aDlg->exec() == QDialog::Accepted;
2431 // 4. set the value to all results
2432 aCurrentValue = aTransparencyWidget->getValue();
2433 setTransparency(aCurrentValue, theObjects);
2435 aMgr->finishOperation();
2436 updateCommandStatus();
2439 //**************************************************************
2440 void XGUI_Workshop::onTransparencyValueChanged()
2442 XGUI_TransparencyWidget* aTransparencyWidget = (XGUI_TransparencyWidget*)sender();
2443 if (!aTransparencyWidget || !aTransparencyWidget->isPreviewNeeded())
2446 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
2447 setTransparency(aTransparencyWidget->getValue(), anObjects);
2448 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2451 //**************************************************************
2452 void XGUI_Workshop::onPreviewStateChanged()
2454 XGUI_TransparencyWidget* aTransparencyWidget = (XGUI_TransparencyWidget*)sender();
2455 if (!aTransparencyWidget || !aTransparencyWidget->isPreviewNeeded())
2458 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
2459 setTransparency(aTransparencyWidget->getValue(), anObjects);
2460 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2463 //**************************************************************
2464 #define SET_DISPLAY_GROUP(aGroupName, aDisplay) \
2465 for (int i = 0; i < aDoc->size(aGroupName); i++) { \
2466 aDoc->object(aGroupName, i)->setDisplayed(aDisplay); \
2469 //******************************************************
2470 void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible)
2473 std::set<ObjectPtr> anObjects;
2474 foreach (ObjectPtr aObj, theList) {
2475 anObjects.insert(aObj);
2477 if (!prepareForDisplay(anObjects))
2481 foreach (ObjectPtr aObj, theList) {
2482 aObj->setDisplayed(isVisible);
2484 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2485 myObjectBrowser->updateAllIndexes();
2488 //**************************************************************
2489 void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList)
2491 QObjectPtrList aSrcList = theList;
2492 // Hide all displayed objects
2493 QObjectPtrList aList = myDisplayer->displayedObjects();
2494 foreach (ObjectPtr aObj, aList) {
2495 if ((!aSrcList.contains(aObj)) && (module()->canEraseObject(aObj)))
2496 aObj->setDisplayed(false);
2498 aSrcList.removeAll(aObj);
2500 //Do not use eraseAll if you didn't send Redisplay event:
2501 //all objects are erased from viewer, but considered as displayed in displayer
2502 // Problem in bug 2218
2503 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2505 //issue #2159 Hide all incomplete behavior
2506 viewer()->eraseAll();
2509 std::set<ObjectPtr> anObjects;
2510 foreach (ObjectPtr aObj, aSrcList) {
2511 anObjects.insert(aObj);
2514 if (!prepareForDisplay(anObjects))
2517 // Show only objects from the list
2518 foreach (ObjectPtr aObj, aSrcList) {
2519 aObj->setDisplayed(true);
2521 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2523 // Necessary for update icons in ObjectBrowser on Linux
2524 myObjectBrowser->updateAllIndexes();
2527 //**************************************************************
2528 void XGUI_Workshop::registerValidators() const
2530 SessionPtr aMgr = ModelAPI_Session::get();
2531 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
2534 //**************************************************************
2535 void XGUI_Workshop::displayDocumentResults(DocumentPtr theDoc)
2539 displayGroupResults(theDoc, ModelAPI_ResultConstruction::group());
2540 displayGroupResults(theDoc, ModelAPI_ResultBody::group());
2543 //**************************************************************
2544 void XGUI_Workshop::displayGroupResults(DocumentPtr theDoc, std::string theGroup)
2546 for (int i = 0; i < theDoc->size(theGroup); i++)
2547 theDoc->object(theGroup, i)->setDisplayed(true);
2548 //displayObject(theDoc->object(theGroup, i));
2549 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2552 //**************************************************************
2553 void XGUI_Workshop::setDisplayMode(const QObjectPtrList& theList, int theMode)
2555 foreach(ObjectPtr anObj, theList) {
2556 myDisplayer->setDisplayMode(anObj, (XGUI_Displayer::DisplayMode)theMode, false);
2558 ResultBodyPtr aBodyResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(anObj);
2559 if (aBodyResult.get() != NULL) { // change display mode for all sub-solids
2560 std::list<ResultPtr> allRes;
2561 ModelAPI_Tools::allSubs(aBodyResult, allRes);
2562 for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
2563 myDisplayer->setDisplayMode(*aRes, (XGUI_Displayer::DisplayMode)theMode, false);
2567 if (theList.size() > 0)
2568 myDisplayer->updateViewer();
2571 //**************************************************************
2572 void XGUI_Workshop::closeDocument()
2574 ModuleBase_Operation* anOperation = operationMgr()->currentOperation();
2575 while (anOperation) {
2576 anOperation->abort();
2577 anOperation = operationMgr()->currentOperation();
2579 //myDisplayer->closeLocalContexts();
2580 myDisplayer->eraseAll();
2581 objectBrowser()->clearContent();
2583 module()->closeDocument();
2584 // we need to clear viewer (with created filters) to do not have problems in 2nd SALOME study
2585 module()->clearViewer();
2588 // data model need not process the document's signals about objects modifications as
2589 // the document is closed
2590 //bool isBlocked = objectBrowser()->dataModel()->blockEventsProcessing(true);
2592 SessionPtr aMgr = ModelAPI_Session::get();
2595 //objectBrowser()->dataModel()->blockEventsProcessing(isBlocked);
2598 //******************************************************
2599 void XGUI_Workshop::addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot)
2601 XGUI_HistoryMenu* aMenu = NULL;
2602 if (isSalomeMode()) {
2603 QAction* anAction = qobject_cast<QAction*>(theObject);
2606 aMenu = new XGUI_HistoryMenu(anAction);
2608 QToolButton* aButton = qobject_cast<QToolButton*>(theObject);
2609 aMenu = new XGUI_HistoryMenu(aButton);
2611 connect(this, theSignal, aMenu, SLOT(setHistory(const QList<ActionInfo>&)));
2612 connect(aMenu, SIGNAL(actionSelected(int)), this, theSlot);
2615 //******************************************************
2616 QList<ActionInfo> XGUI_Workshop::processHistoryList(const std::list<std::string>& theList) const
2618 QList<ActionInfo> aResult;
2619 std::list<std::string>::const_iterator it = theList.cbegin();
2620 for (; it != theList.cend(); it++) {
2621 QString anId = QString::fromStdString(*it);
2622 bool isEditing = anId.endsWith(ModuleBase_OperationFeature::EditSuffix());
2624 anId.chop(ModuleBase_OperationFeature::EditSuffix().size());
2627 QAction* aContextMenuAct = myContextMenuMgr->actionByName(anId);
2628 if (aContextMenuAct) {
2629 anInfo.initFrom(aContextMenuAct);
2631 anInfo = myActionsMgr->actionInfoById(anId);
2634 anInfo.text = anInfo.text.prepend("Modify ");
2641 //******************************************************
2642 void XGUI_Workshop::setStatusBarMessage(const QString& theMessage)
2645 salomeConnector()->putInfo(theMessage, -1);
2647 myMainWindow->putInfo(theMessage, -1);
2652 //******************************************************
2653 void XGUI_Workshop::synchronizeViewer()
2655 SessionPtr aMgr = ModelAPI_Session::get();
2656 QList<DocumentPtr> aDocs;
2657 aDocs.append(aMgr->activeDocument());
2658 aDocs.append(aMgr->moduleDocument());
2660 foreach(DocumentPtr aDoc, aDocs) {
2661 synchronizeGroupInViewer(aDoc, ModelAPI_ResultConstruction::group(), false);
2662 synchronizeGroupInViewer(aDoc, ModelAPI_ResultBody::group(), false);
2663 synchronizeGroupInViewer(aDoc, ModelAPI_ResultPart::group(), false);
2664 synchronizeGroupInViewer(aDoc, ModelAPI_ResultGroup::group(), false);
2668 //******************************************************
2669 void XGUI_Workshop::synchronizeGroupInViewer(const DocumentPtr& theDoc,
2670 const std::string& theGroup,
2671 bool theUpdateViewer)
2674 int aSize = theDoc->size(theGroup);
2675 for (int i = 0; i < aSize; i++) {
2676 aObj = theDoc->object(theGroup, i);
2677 if (aObj->isDisplayed()) {
2678 // Hide the presentation with an empty shape. But isDisplayed state of the object should not
2679 // be changed to the object becomes visible when the shape becomes not empty
2680 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
2681 if (aRes.get() && (!aRes->shape().get() || aRes->shape()->isNull()))
2683 myDisplayer->display(aObj, false);
2686 if (theUpdateViewer)
2687 myDisplayer->updateViewer();
2691 //******************************************************
2692 void XGUI_Workshop::highlightResults(const QObjectPtrList& theObjects)
2694 FeaturePtr aFeature;
2695 QObjectPtrList aSelList = theObjects;
2696 QObjectPtrList aNewSel;
2697 bool aHasHidden = false;
2698 foreach(ObjectPtr aObj, theObjects) {
2699 aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
2700 if (aFeature.get()) {
2701 std::list<ResultPtr> aResults;
2702 ModelAPI_Tools::allResults(aFeature, aResults);
2703 std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aIt;
2704 for(aIt = aResults.cbegin(); aIt != aResults.cend(); aIt++) {
2705 aHasHidden |= (*aIt)->isConcealed();
2706 aSelList.append(*aIt);
2707 aNewSel.append(*aIt);
2711 if (aSelList.count() > theObjects.count()) {
2712 // if something was found
2713 bool aBlocked = objectBrowser()->blockSignals(true);
2714 objectBrowser()->setObjectsSelected(aSelList);
2715 objectBrowser()->blockSignals(aBlocked);
2716 objectBrowser()->ensureVisible(aNewSel.first());
2719 QMessageBox::information(desktop(), tr("Find results"),
2720 tr("Results not found"), QMessageBox::Ok);
2723 //******************************************************
2724 void XGUI_Workshop::highlightFeature(const QObjectPtrList& theObjects)
2727 QObjectPtrList aSelList = theObjects;
2728 QObjectPtrList aNewSel;
2729 FeaturePtr aFeature;
2730 foreach(ObjectPtr aObj, theObjects) {
2731 aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
2732 if (aResult.get()) {
2733 aFeature = ModelAPI_Feature::feature(aResult);
2734 if (aFeature.get()) {
2735 aSelList.append(aFeature);
2736 aNewSel.append(aFeature);
2740 if (aSelList.count() > theObjects.count()) {
2741 // if something was found
2742 bool aBlocked = objectBrowser()->blockSignals(true);
2743 objectBrowser()->setObjectsSelected(aSelList);
2744 objectBrowser()->blockSignals(aBlocked);
2745 objectBrowser()->ensureVisible(aNewSel.first());
2749 void XGUI_Workshop::insertFeatureFolder()
2751 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
2752 if (aObjects.isEmpty())
2754 ObjectPtr aObj = aObjects.first();
2755 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
2756 if (aFeature.get() == NULL)
2758 SessionPtr aMgr = ModelAPI_Session::get();
2759 DocumentPtr aDoc = aMgr->activeDocument();
2761 QString aDescription = contextMenuMgr()->action("INSERT_FOLDER_CMD")->text();
2763 aMgr->startOperation(aDescription.toStdString());
2764 aDoc->addFolder(aFeature);
2765 aMgr->finishOperation();
2767 updateCommandStatus();
2771 void XGUI_Workshop::insertToFolder(bool isBefore)
2773 std::list<FeaturePtr> aFeatures = mySelector->getSelectedFeatures();
2774 if (aFeatures.empty())
2777 SessionPtr aMgr = ModelAPI_Session::get();
2778 DocumentPtr aDoc = aMgr->activeDocument();
2780 FolderPtr aFolder = isBefore? aDoc->findFolderAbove(aFeatures):
2781 aDoc->findFolderBelow(aFeatures);
2785 QString aDescription = contextMenuMgr()->action(
2786 isBefore ? "ADD_TO_FOLDER_BEFORE_CMD" : "ADD_TO_FOLDER_AFTER_CMD")->text();
2788 QMap<ObjectPtr, bool> aStates = myObjectBrowser->getFoldersState(aDoc);
2790 aMgr->startOperation(aDescription.toStdString());
2791 aDoc->moveToFolder(aFeatures, aFolder);
2792 aMgr->finishOperation();
2794 myObjectBrowser->setFoldersState(aStates);
2796 updateCommandStatus();
2799 void XGUI_Workshop::moveOutFolder(bool isBefore)
2801 std::list<FeaturePtr> aFeatures = mySelector->getSelectedFeatures();
2802 if (aFeatures.empty())
2805 SessionPtr aMgr = ModelAPI_Session::get();
2806 DocumentPtr aDoc = aMgr->activeDocument();
2808 QString aDescription = contextMenuMgr()->action(
2809 isBefore ? "ADD_OUT_FOLDER_BEFORE_CMD" : "ADD_OUT_FOLDER_AFTER_CMD")->text();
2811 QMap<ObjectPtr, bool> aStates = myObjectBrowser->getFoldersState(aDoc);
2813 aMgr->startOperation(aDescription.toStdString());
2814 aDoc->removeFromFolder(aFeatures, isBefore);
2815 aMgr->finishOperation();
2817 myObjectBrowser->setFoldersState(aStates);
2819 updateCommandStatus();
2822 void XGUI_Workshop::onAutoApply()
2824 SessionPtr aMgr = ModelAPI_Session::get();
2825 bool isBlocked = aMgr->isAutoUpdateBlocked();
2826 aMgr->blockAutoUpdate(!isBlocked);
2829 void XGUI_Workshop::updateAutoComputeState()
2831 SessionPtr aMgr = ModelAPI_Session::get();
2832 bool isComputeBlocked = aMgr->isAutoUpdateBlocked();
2834 QAction* aUpdateCmd;
2835 QList<QAction*> aCommands = mySalomeConnector->commandList();
2836 foreach(QAction* aCmd, aCommands) {
2837 if (aCmd->data().toString() == "AUTOCOMPUTE_CMD") {
2842 aUpdateCmd->setIcon(isComputeBlocked? QIcon(":pictures/autoapply_stop.png") :
2843 QIcon(":pictures/autoapply_start.png"));
2845 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
2846 AppElements_Command* aUpdateCmd = aMenuBar->feature("AUTOCOMPUTE_CMD");
2847 aUpdateCmd->button()->setIcon(isComputeBlocked? QIcon(":pictures/autoapply_stop.png") :
2848 QIcon(":pictures/autoapply_start.png"));
2853 void XGUI_Workshop::clearTemporaryDir()
2855 QDir aDir(myTmpDir.path());
2856 if (!aDir.isEmpty()) {
2857 QStringList aEntries;
2858 aDir.entryList(aEntries);
2859 foreach(QString aFile, aEntries) {