1 // Copyright (C) 2014-2019 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 email : webmaster.salome@opencascade.com
20 #include "XGUI_Workshop.h"
22 #include "XGUI_ActionsMgr.h"
23 #include "XGUI_ActiveControlMgr.h"
24 #include "XGUI_ActiveControlSelector.h"
25 #include "XGUI_MenuMgr.h"
26 #include "XGUI_ColorDialog.h"
27 #include "XGUI_DeflectionDialog.h"
28 #include "XGUI_TransparencyWidget.h"
29 #include "XGUI_ContextMenuMgr.h"
30 #include "XGUI_Displayer.h"
31 #include "XGUI_ErrorDialog.h"
32 #include "XGUI_ErrorMgr.h"
33 #include "XGUI_FacesPanel.h"
34 #include "XGUI_FacesPanelSelector.h"
35 #include "XGUI_ModuleConnector.h"
36 #include "XGUI_ObjectsBrowser.h"
37 #include "XGUI_OperationMgr.h"
38 #include "XGUI_PropertyPanel.h"
39 #include "XGUI_PropertyPanelSelector.h"
40 #include "XGUI_PropertyDialog.h"
41 #include "XGUI_SalomeConnector.h"
42 #include "XGUI_Selection.h"
43 #include "XGUI_SelectionActivate.h"
44 #include "XGUI_SelectionMgr.h"
45 #include "XGUI_Tools.h"
46 #include "XGUI_ViewerProxy.h"
47 #include "XGUI_WorkshopListener.h"
48 #include <XGUI_CustomPrs.h>
49 #include <XGUI_HistoryMenu.h>
50 #include <XGUI_QtEvents.h>
51 #include <XGUI_DataModel.h>
52 #include <XGUI_InspectionPanel.h>
53 #include <XGUI_CompressFiles.h>
56 #include <AppElements_Button.h>
57 #include <AppElements_Command.h>
58 #include <AppElements_MainMenu.h>
59 #include <AppElements_MainWindow.h>
60 #include <AppElements_MenuGroupPanel.h>
61 #include <AppElements_Viewer.h>
62 #include <AppElements_Workbench.h>
65 #include <Config_XMLReader.h>
67 #include <ModelAPI_AttributeDocRef.h>
68 #include <ModelAPI_AttributeIntArray.h>
69 #include <ModelAPI_AttributeDouble.h>
70 #include <ModelAPI_Data.h>
71 #include <ModelAPI_Events.h>
72 #include <ModelAPI_Feature.h>
73 #include <ModelAPI_Object.h>
74 #include <ModelAPI_ResultBody.h>
75 #include <ModelAPI_ResultConstruction.h>
76 #include <ModelAPI_ResultGroup.h>
77 #include <ModelAPI_ResultParameter.h>
78 #include <ModelAPI_ResultField.h>
79 #include <ModelAPI_Session.h>
80 #include <ModelAPI_Validator.h>
81 #include <ModelAPI_Tools.h>
83 //#include <PartSetPlugin_Part.h>
85 #include <Events_Loop.h>
86 #include <Events_InfoMessage.h>
87 #include <Events_LongOp.h>
89 #include <ModuleBase_IModule.h>
90 #include <ModuleBase_IViewer.h>
91 #include <ModuleBase_Operation.h>
92 #include <ModuleBase_OperationDescription.h>
93 #include <ModuleBase_PageBase.h>
94 #include <ModuleBase_Preferences.h>
95 #include <ModuleBase_SelectionValidator.h>
96 #include <ModuleBase_Tools.h>
97 #include <ModuleBase_WidgetFactory.h>
98 #include <ModuleBase_OperationFeature.h>
99 #include <ModuleBase_OperationAction.h>
100 #include <ModuleBase_PagedContainer.h>
101 #include <ModuleBase_WidgetValidated.h>
102 #include <ModuleBase_ModelWidget.h>
103 #include <ModuleBase_ResultPrs.h>
104 #include <ModuleBase_ActionIntParameter.h>
106 #include <Config_Common.h>
107 #include <Config_FeatureMessage.h>
108 #include <Config_ModuleReader.h>
109 #include <Config_PointerMessage.h>
110 #include <Config_PropManager.h>
111 #include <Config_DataModelReader.h>
112 #include <Config_Translator.h>
113 #include <Config_WidgetAPI.h>
114 #include <Config_Keywords.h>
116 #include <SUIT_ResourceMgr.h>
118 #include <AIS_Trihedron.hxx>
119 #ifdef BEFORE_TRIHEDRON_PATCH
120 #include <AIS_Point.hxx>
121 #include <AIS_Axis.hxx>
124 #include <QApplication>
125 #include <QFileDialog>
126 #include <QMessageBox>
127 #include <QMdiSubWindow>
128 #include <QMainWindow>
129 #include <QPushButton>
130 #include <QDockWidget>
135 #include <QToolButton>
137 #include <QDesktopWidget>
139 #include <QDesktopServices>
144 #include <CDF_Session.hxx>
145 #include <CDF_Application.hxx>
146 #include <inspector/TInspector_Communicator.hxx>
147 #include <inspector/VInspector_CallBack.hxx>
148 static TInspector_Communicator* MyTCommunicator;
149 static Handle(VInspector_CallBack) MyVCallBack;
164 //#define DEBUG_WITH_MESSAGE_REPORT
166 QString XGUI_Workshop::MOVE_TO_END_COMMAND = QObject::tr("Move to the end");
168 //#define DEBUG_DELETE
169 //#define DEBUG_FEATURE_NAME
170 //#define DEBUG_CLEAN_HISTORY
173 static QString MyFilter(QObject::tr("SHAPER files (*.shaper *.opp)"));
174 static QString MyFilter2(QObject::tr("SHAPER files (*.shaper)"));
175 static QString MyExtension(".shaper");
177 static QString MyFilter(QObject::tr("OpenParts files (*.opp);;All files (*.*)"));
178 static QString MyFilter2(QObject::tr("OpenParts files (*.opp)"));
179 static QString MyExtension(".opp");
183 //******************************************************
184 XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
187 mySalomeConnector(theConnector),
189 myInspectionPanel(0),
193 //myViewerSelMode(TopAbs_FACE)
195 mySelector = new XGUI_SelectionMgr(this);
196 myModuleConnector = new XGUI_ModuleConnector(this);
197 myOperationMgr = new XGUI_OperationMgr(this, 0);
198 ModuleBase_IWorkshop* aWorkshop = moduleConnector();
199 // Has to be defined first in order to get errors and messages from other components
200 myEventsListener = new XGUI_WorkshopListener(this);
201 mySelectionActivate = new XGUI_SelectionActivate(aWorkshop);
203 SUIT_ResourceMgr* aResMgr = ModuleBase_Preferences::resourceMgr();
205 myMainWindow = new AppElements_MainWindow();
207 bool aCloc = aResMgr->booleanValue("language", "locale", true);
209 QLocale::setDefault( QLocale::c() );
211 QLocale::setDefault( QLocale::system() );
213 QString aPath = Config_XMLReader::pluginConfigFile().c_str();
218 aLangs << "*_en.ts"; // load by default eng translations
219 QString aCurrLang = aResMgr->stringValue("language", "language", "en");
220 if(aCurrLang != "en") {
221 aLangs << "*_" + aCurrLang + ".ts"; // then replace with translated files
224 foreach(QString aLang, aLangs) {
225 QStringList aFilters;
227 QStringList aTsFiles = aDir.entryList(aFilters, QDir::Files);
228 foreach(QString aFileName, aTsFiles) {
229 Config_Translator::load(aFileName.toStdString());
233 myDataModelXMLReader = new Config_DataModelReader();
234 //myDataModelXMLReader->readAll();
236 myDisplayer = new XGUI_Displayer(this);
238 connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(updateCommandStatus()));
240 myActionsMgr = new XGUI_ActionsMgr(this);
241 myActiveControlMgr = new XGUI_ActiveControlMgr(myModuleConnector);
242 myMenuMgr = new XGUI_MenuMgr(this);
243 myErrorDlg = new XGUI_ErrorDialog(QApplication::desktop());
244 myContextMenuMgr = new XGUI_ContextMenuMgr(this);
245 connect(myContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), this,
246 SLOT(onContextMenuCommand(const QString&, bool)));
248 myViewerProxy = new XGUI_ViewerProxy(this);
249 //connect(myViewerProxy, SIGNAL(selectionChanged()),
250 // myActionsMgr, SLOT(updateOnViewSelection()));
252 myOperationMgr->setWorkshop(aWorkshop);
254 myErrorMgr = new XGUI_ErrorMgr(this, aWorkshop);
256 connect(myOperationMgr, SIGNAL(operationResumed(ModuleBase_Operation*)),
257 SLOT(onOperationResumed(ModuleBase_Operation*)));
258 connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
259 SLOT(onOperationStopped(ModuleBase_Operation*)));
260 connect(myOperationMgr, SIGNAL(operationCommitted(ModuleBase_Operation*)),
261 SLOT(onOperationCommitted(ModuleBase_Operation*)));
262 connect(myOperationMgr, SIGNAL(operationAborted(ModuleBase_Operation*)),
263 SLOT(onOperationAborted(ModuleBase_Operation*)));
266 connect(myMainWindow, SIGNAL(exitKeySequence()), SLOT(onExit()));
267 onTrihedronVisibilityChanged(true);
270 connect(myEventsListener, SIGNAL(errorOccurred(std::shared_ptr<Events_InfoMessage>)),
271 myErrorDlg, SLOT(addError(std::shared_ptr<Events_InfoMessage>)));
273 //Config_PropManager::registerProp("Visualization", "object_default_color", "Object color",
274 // Config_Prop::Color, "225,225,225");
276 Config_PropManager::registerProp("Visualization", "result_body_color", "Result color",
277 Config_Prop::Color, ModelAPI_ResultBody::DEFAULT_COLOR());
278 Config_PropManager::registerProp("Visualization", "result_group_color", "Group color",
279 Config_Prop::Color, ModelAPI_ResultGroup::DEFAULT_COLOR());
280 Config_PropManager::registerProp("Visualization", "result_construction_color",
281 "Construction color",
283 ModelAPI_ResultConstruction::DEFAULT_COLOR());
284 Config_PropManager::registerProp("Visualization", "result_part_color", "Part color",
285 Config_Prop::Color, ModelAPI_ResultPart::DEFAULT_COLOR());
286 Config_PropManager::registerProp("Visualization", "result_field_color", "Field color",
287 Config_Prop::Color, ModelAPI_ResultField::DEFAULT_COLOR());
289 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "face-selection", true))
290 myViewerSelMode.append(TopAbs_FACE);
291 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "edge-selection", true))
292 myViewerSelMode.append(TopAbs_EDGE);
293 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "vertex-selection", true))
294 myViewerSelMode.append(TopAbs_VERTEX);
295 //IMP: an attempt to use result selection with other selection modes
296 myViewerSelMode.append(ModuleBase_ResultPrs::Sel_Result);//TopAbs_VERTEX);
297 myViewerSelMode.append(TopAbs_COMPSOLID);
300 //******************************************************
301 XGUI_Workshop::~XGUI_Workshop(void)
304 #ifdef MISSED_TRANSLATION
305 // Save Missed translations
306 Config_Translator::saveMissedTranslations();
311 delete myDataModelXMLReader;
312 delete mySelectionActivate;
317 //******************************************************
318 void XGUI_Workshop::startApplication()
320 //Initialize event listening
321 myEventsListener->initializeEventListening();
323 myDataModelXMLReader->readAll();
326 Config_PropManager::registerProp("Plugins", "default_path", "Default Path",
327 Config_Prop::Directory, "");
329 std::string aDir = Config_XMLReader::resourcesConfigFile();
330 Config_PropManager::registerProp("Plugins", "import_initial_path", "Import initial directory",
331 Config_Prop::Directory, aDir);
334 Config_PropManager::registerProp("Plugins", "create_part_by_start", "Create Part by Start",
335 Config_Prop::Boolean, "false");
337 Config_PropManager::registerProp("Plugins", "show_hide_faces", "Show Hide Faces (on the right)",
338 Config_Prop::Boolean, "false");
340 registerValidators();
342 // Calling of loadCustomProps before activating module is required
343 // by Config_PropManger to restore user-defined path to plugins
344 ModuleBase_Preferences::loadCustomProps();
348 myMainWindow->show();
349 updateCommandStatus();
354 myViewerProxy->connectViewProxy();
355 connect(myViewerProxy, SIGNAL(trihedronVisibilityChanged(bool)),
356 SLOT(onTrihedronVisibilityChanged(bool)));
358 emit applicationStarted();
361 bool aNewPart = Config_PropManager::boolean("Plugins", "create_part_by_start");
363 module()->launchOperation("Part", false); // PartSetPlugin_Part::ID()
368 //******************************************************
369 void XGUI_Workshop::activateModule()
371 selectionActivate()->updateSelectionFilters();
373 connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
374 myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
375 connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
376 myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
378 updateCommandStatus();
380 // TODO: get default selection mode
382 // activate visualized objects in the viewer
383 activateObjectsSelection(displayer()->displayedObjects());
384 myOperationMgr->activate();
387 //******************************************************
388 void XGUI_Workshop::deactivateModule()
390 // remove internal displayer filter
391 displayer()->deactivateSelectionFilters(false);
393 disconnect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
394 myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
395 disconnect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
396 myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
398 XGUI_Displayer* aDisplayer = displayer();
399 QObjectPtrList aDisplayed = aDisplayer->displayedObjects();
400 aDisplayer->deactivateObjects(aDisplayed, true);
401 selectionActivate()->deactivateTrihedronInSelectionModes();
403 #ifdef BEFORE_TRIHEDRON_PATCH
404 //Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(aDisplayer->getTrihedron());
405 /// Trihedron problem: objects stayed in the viewer, should be removed manually
406 /// otherwise in SALOME happens crash by HideAll in the viewer
407 aContext->Remove(aTrihedron->Position(), true);
408 aContext->Remove(aTrihedron->Axis(), true);
409 aContext->Remove(aTrihedron->XAxis(), true);
410 aContext->Remove(aTrihedron->YAxis(), true);
413 myOperationMgr->deactivate();
416 //******************************************************
417 void XGUI_Workshop::initMenu()
419 myContextMenuMgr->createActions();
422 // Create only Undo, Redo commands
423 QAction* aAction = salomeConnector()->addDesktopCommand("UNDO_CMD", tr("Undo"),
424 tr("Undo last command"),
425 QIcon(":pictures/undo.png"),
426 QKeySequence::Undo, false,
428 QString aToolBarTitle = tr( "INF_DESK_TOOLBAR_STANDARD" );
429 salomeConnector()->addActionInToolbar( aAction,aToolBarTitle );
431 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onUndo()));
432 addHistoryMenu(aAction, SIGNAL(updateUndoHistory(const QList<ActionInfo>&)), SLOT(onUndo(int)));
434 aAction = salomeConnector()->addDesktopCommand("REDO_CMD", tr("Redo"), tr("Redo last command"),
435 QIcon(":pictures/redo.png"), QKeySequence::Redo,
436 false, "MEN_DESK_EDIT");
437 salomeConnector()->addActionInToolbar( aAction, aToolBarTitle );
439 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo()));
440 addHistoryMenu(aAction, SIGNAL(updateRedoHistory(const QList<ActionInfo>&)), SLOT(onRedo(int)));
442 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
444 //aAction = salomeConnector()->addDesktopCommand("AUTOCOMPUTE_CMD", tr("Auto rebuild"),
445 // tr("Blocks immediate apply of modifications"),
446 // QIcon(":pictures/autoapply.png"), QKeySequence(),
447 // false, "MEN_DESK_EDIT");
448 //salomeConnector()->addActionInToolbar( aAction, aToolBarTitle );
450 //connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onAutoApply()));
452 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
455 // Add commands to a file menu
456 aAction = salomeConnector()->addDesktopCommand("SAVEAS_CMD", tr("Export native..."),
457 tr("Export the current document into a native file"),
458 QIcon(), QKeySequence(),
459 false, "MEN_DESK_FILE");
460 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onSaveAs()));
462 aAction = salomeConnector()->addDesktopCommand("OPEN_CMD", tr("Import native..."),
463 tr("Import native file"),
464 QIcon(), QKeySequence(),
465 false, "MEN_DESK_FILE");
466 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onOpen()));
467 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_FILE");
470 // File commands group
471 AppElements_MenuGroupPanel* aGroup = myMainWindow->menuObject()->generalPage();
473 AppElements_Command* aCommand;
475 aCommand = aGroup->addFeature("SAVE_CMD", tr("Save"), tr("Save the document"),
476 QIcon(":pictures/save.png"), QKeySequence::Save);
477 aCommand->connectTo(this, SLOT(onSave()));
478 //aCommand->disable();
480 aCommand = aGroup->addFeature("SAVEAS_CMD", tr("Save as..."), tr("Save the document into a file"),
481 QIcon(":pictures/save.png"), QKeySequence());
482 aCommand->connectTo(this, SLOT(onSaveAs()));
484 QString aUndoId = "UNDO_CMD";
485 aCommand = aGroup->addFeature(aUndoId, tr("Undo"), tr("Undo last command"),
486 QIcon(":pictures/undo.png"), QKeySequence::Undo);
487 aCommand->connectTo(this, SLOT(onUndo()));
488 AppElements_Button* aUndoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aUndoId));
489 addHistoryMenu(aUndoButton,
490 SIGNAL(updateUndoHistory(const QList<ActionInfo>&)),
493 QString aRedoId = "REDO_CMD";
494 aCommand = aGroup->addFeature(aRedoId, tr("Redo"), tr("Redo last command"),
495 QIcon(":pictures/redo.png"), QKeySequence::Redo);
496 aCommand->connectTo(this, SLOT(onRedo()));
497 AppElements_Button* aRedoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aRedoId));
498 addHistoryMenu(aRedoButton,
499 SIGNAL(updateRedoHistory(const QList<ActionInfo>&)),
502 aCommand = aGroup->addFeature("OPEN_CMD", tr("Open..."), tr("Open a new document"),
503 QIcon(":pictures/open.png"), QKeySequence::Open);
504 aCommand->connectTo(this, SLOT(onOpen()));
507 aCommand = aGroup->addFeature("AUTOCOMPUTE_CMD", tr("Auto rebuild"),
508 tr("Blocks immediate apply of modifications"),
509 QIcon(":pictures/autoapply_start.png"), QKeySequence());
510 aCommand->setChecked(ModelAPI_Session::get()->isAutoUpdateBlocked());
511 aCommand->connectTo(this, SLOT(onAutoApply()));
513 aCommand = aGroup->addFeature("PREF_CMD", tr("Preferences"), tr("Edit preferences"),
514 QIcon(":pictures/preferences.png"), QKeySequence::Preferences);
515 aCommand->connectTo(this, SLOT(onPreferences()));
517 aCommand = aGroup->addFeature("EXIT_CMD", tr("Exit"), tr("Exit application"),
518 QIcon(":pictures/close.png"), QKeySequence::Close);
519 aCommand->connectTo(this, SLOT(onExit()));
524 //******************************************************
525 AppElements_Workbench* XGUI_Workshop::addWorkbench(const QString& theName)
527 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
528 return aMenuBar->addWorkbench(theName);
532 //******************************************************
533 QMainWindow* XGUI_Workshop::desktop() const
536 return salomeConnector()->desktop();
542 //******************************************************
543 void XGUI_Workshop::onStartWaiting()
545 if (Events_LongOp::isPerformed()) {
546 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
550 //******************************************************
551 void XGUI_Workshop::onAcceptActionClicked()
553 QAction* anAction = dynamic_cast<QAction*>(sender());
554 XGUI_OperationMgr* anOperationMgr = operationMgr();
555 if (anOperationMgr) {
556 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
557 (anOperationMgr->currentOperation());
559 //if (errorMgr()->canProcessClick(anAction, aFOperation->feature()))
560 myOperationMgr->commitOperation();
565 //******************************************************
566 void XGUI_Workshop::onAcceptPlusActionClicked()
568 QAction* anAction = dynamic_cast<QAction*>(sender());
569 XGUI_OperationMgr* anOperationMgr = operationMgr();
570 if (anOperationMgr) {
571 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
572 (anOperationMgr->currentOperation());
574 if (myOperationMgr->commitOperation())
575 module()->launchOperation(aFOperation->id(), false);
580 //******************************************************
581 void XGUI_Workshop::onPreviewActionClicked()
583 ModuleBase_IPropertyPanel* aPanel = propertyPanel();
585 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
586 if (anActiveWidget && anActiveWidget->getValueState() == ModuleBase_ModelWidget::ModifiedInPP) {
587 anActiveWidget->storeValue();
590 std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
591 new Events_Message(Events_Loop::eventByName(EVENT_PREVIEW_REQUESTED)));
592 Events_Loop::loop()->send(aMsg);
596 //******************************************************
597 void XGUI_Workshop::onHelpActionClicked()
599 XGUI_OperationMgr* anOperationMgr = operationMgr();
600 if (anOperationMgr) {
601 ModuleBase_Operation* aOperation = anOperationMgr->currentOperation();
603 QString aHelpPage = aOperation->helpFileName();
604 if (!aHelpPage.isEmpty()) {
606 const QChar aSep = QDir::separator();
608 // SUIT_ResourceMgr* aResMgr = ModuleBase_Preferences::resourceMgr();
610 // platform = "winapplication";
612 // platform = "application";
614 // QString aBrowserName = aResMgr->stringValue("ExternalBrowser", platform);
617 QString aDir(getenv("SHAPER_ROOT_DIR"));
618 if (!aDir.isEmpty()) {
619 aDocDir = aDir + aSep + "share" + aSep + "doc" + aSep +
620 "salome" + aSep + "gui" + aSep + "SHAPER";
623 QString aDir(getenv("OPENPARTS_ROOT_DIR"));
624 aDocDir = aDir + aSep + "doc" + aSep + "gui";
626 QString aFileName = aDocDir + aSep + aHelpPage;
627 if (QFile::exists(aFileName)) {
628 QUrl aUrl = QUrl::fromLocalFile(aFileName);
629 QDesktopServices::openUrl(aUrl);
637 //******************************************************
638 void XGUI_Workshop::deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer)
640 if (!myModule->canActivateSelection(theObject)) {
641 if (selectionActivate()->isActive(theObject)) {
642 QObjectPtrList anObjects;
643 anObjects.append(theObject);
644 myDisplayer->deactivateObjects(anObjects, theUpdateViewer);
649 //******************************************************
650 bool XGUI_Workshop::isFeatureOfNested(const FeaturePtr& theFeature)
652 bool aHasNested = false;
653 std::string aFeatureKind = theFeature->getKind();
655 XGUI_SalomeConnector* aSalomeConnector = salomeConnector();
656 if (aSalomeConnector->isFeatureOfNested(actionsMgr()->action(aFeatureKind.c_str())))
659 AppElements_MainMenu* aMenuBar = mainWindow()->menuObject();
660 AppElements_Command* aCommand = aMenuBar->feature(aFeatureKind.c_str());
661 if (aCommand && aCommand->button()->additionalButtonWidget())
667 //******************************************************
668 void XGUI_Workshop::fillPropertyPanel(ModuleBase_Operation* theOperation)
670 ModuleBase_OperationFeature* aFOperation =
671 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
675 showPanel(myPropertyPanel);
676 myPropertyPanel->cleanContent();
678 QList<ModuleBase_ModelWidget*> aWidgets;
679 if (!module()->createWidgets(theOperation, aWidgets)) {
680 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
681 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), myModuleConnector);
682 aFactory.createWidget(myPropertyPanel->contentWidget());
683 aWidgets = aFactory.getModelWidgets();
686 // check compatibility of feature and widgets
687 FeaturePtr aFeature = aFOperation->feature();
688 std::string aFeatureKind = aFeature->getKind();
689 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
690 if (aWidget->usesAttribute()) {
691 if (!aWidget->attributeID().empty() && !aFeature->attribute(aWidget->attributeID()).get()) {
692 std::string anErrorMsg = "The feature '%1' has no attribute '%2' used by widget '%3'.";
693 Events_InfoMessage("XGUI_Workshop", anErrorMsg)
694 .arg(aFeatureKind).arg(aWidget->attributeID())
695 .arg(aWidget->metaObject()->className()).send();
696 myPropertyPanel->cleanContent();
701 // for performance purpose, flush should be done after all controls are filled
702 bool isUpdateFlushed = false;
703 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
704 bool isStoreValue = !aFOperation->isEditOperation() &&
705 !aWidget->getDefaultValue().empty() &&
706 !aWidget->isComputedDefault();
707 aWidget->setFeature(aFeature, isStoreValue, isUpdateFlushed);
709 aWidget->restoreValue();
710 aWidget->enableFocusProcessing();
712 // update visible state of Preview button
713 std::shared_ptr<Config_FeatureMessage> aFeatureInfo;
715 aFeatureInfo = mySalomeConnector->featureInfo(aFeatureKind.c_str());
717 AppElements_MainMenu* aMenuBar = mainWindow()->menuObject();
718 AppElements_Command* aCommand = aMenuBar->feature(aFeatureKind.c_str());
720 aFeatureInfo = aCommand->featureMessage();
722 bool anIsAutoPreview = true;
723 if (aFeatureInfo.get()) {
724 anIsAutoPreview = aFeatureInfo->isAutoPreview();
725 theOperation->setHelpFileName(aFeatureInfo->helpFileName().c_str());
727 std::string aXmlCfg, aDescription;
728 module()->getXMLRepresentation(aFeatureKind, aXmlCfg, aDescription);
729 ModuleBase_WidgetFactory aFactory(aXmlCfg, moduleConnector());
730 anIsAutoPreview = aFactory.widgetAPI()->getBooleanAttribute(FEATURE_AUTO_PREVIEW, true);
733 if (!anIsAutoPreview) {
734 myPropertyPanel->findButton(PROP_PANEL_PREVIEW)->setVisible(true);
735 // send signal about preview should not be computed automatically, click on preview
736 // button should initiate it
737 std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
738 new Events_Message(Events_Loop::eventByName(EVENT_PREVIEW_BLOCKED)));
739 Events_Loop::loop()->send(aMsg);
741 // if update happens after preview is blocked, it does nothing when blocked
742 // it improves performance for valid objects on feature start
743 ModuleBase_Tools::flushUpdated(aFeature);
745 myPropertyPanel->setModelWidgets(aWidgets);
746 aFOperation->setPropertyPanel(myPropertyPanel);
748 myModule->propertyPanelDefined(theOperation);
750 #ifndef DEBUG_FEATURE_NAME
751 myPropertyPanel->setWindowTitle(theOperation->getDescription()->description());
753 std::string aFeatureName = aFeature->name();
754 myPropertyPanel->setWindowTitle(QString("%1: %2")
755 .arg(theOperation->getDescription()->description())
756 .arg(aFeatureName.c_str()));
759 myErrorMgr->setPropertyPanel(myPropertyPanel);
762 //******************************************************
763 void XGUI_Workshop::connectToPropertyPanel(const bool isToConnect)
765 XGUI_PropertyPanel* aPropertyPanel = propertyPanel();
766 if (aPropertyPanel) {
767 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
768 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
769 myModule->connectToPropertyPanel(aWidget, isToConnect);
771 connect(aWidget, SIGNAL(valueStateChanged(int)), this, SLOT(onWidgetStateChanged(int)));
772 connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
773 connect(aWidget, SIGNAL(objectUpdated()), this, SLOT(onWidgetObjectUpdated()));
776 disconnect(aWidget, SIGNAL(valueStateChanged(int)), this, SLOT(onWidgetStateChanged(int)));
777 disconnect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
778 disconnect(aWidget, SIGNAL(objectUpdated()), this, SLOT(onWidgetObjectUpdated()));
784 //******************************************************
785 void XGUI_Workshop::onOperationResumed(ModuleBase_Operation* theOperation)
787 setGrantedFeatures(theOperation);
789 if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
790 fillPropertyPanel(theOperation);
791 connectToPropertyPanel(true);
792 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
795 myPropertyPanel->updateApplyPlusButton(aFOperation->feature());
797 myPropertyPanel->updateApplyPlusButton(FeaturePtr());
799 updateCommandStatus();
801 myModule->operationResumed(theOperation);
804 //******************************************************
805 void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
807 updateCommandStatus();
809 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
814 ModuleBase_ISelection* aSel = mySelector->selection();
815 QObjectPtrList aObj = aSel->selectedPresentations();
816 //!< No need for property panel
817 hidePanel(myPropertyPanel);
818 myPropertyPanel->cleanContent();
820 connectToPropertyPanel(false);
821 myModule->operationStopped(aFOperation);
823 // the deactivated objects of the current operation should be activated back.
824 // They were deactivated on operation start or an object redisplay
825 QObjectPtrList anObjects;
826 FeaturePtr aFeature = aFOperation->feature();
827 if (aFeature.get()) { // feature may be not created (plugin load fail)
828 if (myDisplayer->isVisible(aFeature) && !selectionActivate()->isActive(aFeature))
829 anObjects.append(aFeature);
830 std::list<ResultPtr> aResults;
831 ModelAPI_Tools::allResults(aFeature, aResults);
832 std::list<ResultPtr>::const_iterator aIt;
833 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
834 ResultPtr anObject = *aIt;
835 if (myDisplayer->isVisible(anObject) && !selectionActivate()->isActive(anObject)) {
836 anObjects.append(anObject);
840 activateObjectsSelection(anObjects);
843 //******************************************************
844 void XGUI_Workshop::onOperationCommitted(ModuleBase_Operation* theOperation)
846 myModule->operationCommitted(theOperation);
849 //******************************************************
850 void XGUI_Workshop::onOperationAborted(ModuleBase_Operation* theOperation)
852 myModule->operationAborted(theOperation);
855 //******************************************************
856 void XGUI_Workshop::setGrantedFeatures(ModuleBase_Operation* theOperation)
858 ModuleBase_OperationFeature* aFOperation =
859 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
863 QStringList aGrantedIds;
864 if (isSalomeMode()) {
865 const std::shared_ptr<Config_FeatureMessage>& anInfo =
866 mySalomeConnector->featureInfo(theOperation->id());
868 aGrantedIds = QString::fromStdString(anInfo->nestedFeatures())
869 .split(" ", QString::SkipEmptyParts);
872 aGrantedIds = myActionsMgr->nestedCommands(theOperation->id());
874 ModuleBase_IModule* aModule = module();
876 aModule->grantedOperationIds(theOperation, aGrantedIds);
878 aFOperation->setGrantedOperationIds(aGrantedIds);
881 //******************************************************
882 void XGUI_Workshop::saveDocument(const QString& theName, std::list<std::string>& theFileNames)
884 QApplication::restoreOverrideCursor();
885 SessionPtr aMgr = ModelAPI_Session::get();
887 std::list<DocumentPtr> aDocList = aMgr->allOpenedDocuments();
888 std::list<DocumentPtr>::const_iterator aIt;
889 for (aIt = aDocList.cbegin(); aIt != aDocList.cend(); aIt++) {
890 std::list<bool> aState = myObjectBrowser->getStateForDoc(*aIt);
891 (*aIt)->storeNodesState(aState);
894 aMgr->save(theName.toLatin1().constData(), theFileNames);
896 QApplication::restoreOverrideCursor();
899 //******************************************************
900 bool XGUI_Workshop::abortAllOperations()
902 return myOperationMgr->abortAllOperations();
905 //******************************************************
906 void XGUI_Workshop::operationStarted(ModuleBase_Operation* theOperation)
908 setGrantedFeatures(theOperation);
909 if (!theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
910 updateCommandStatus();
913 myModule->operationStarted(theOperation);
917 //******************************************************
918 void XGUI_Workshop::onOpen()
920 if(!abortAllOperations())
922 //save current file before close if modified
923 SessionPtr aSession = ModelAPI_Session::get();
924 if (aSession->isModified()) {
925 //TODO(sbh): re-launch the app?
926 int anAnswer = QMessageBox::question(
927 desktop(), tr("Save current file"),
928 tr("The document is modified, save before opening another?"),
929 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
930 if (anAnswer == QMessageBox::Save) {
932 } else if (anAnswer == QMessageBox::Cancel) {
935 myCurrentFile = QString();
938 //show file dialog, check if readable and open
939 QString aFile = QFileDialog::getOpenFileName(desktop(), tr("Open file"), QString(), MyFilter);
944 //******************************************************
945 void XGUI_Workshop::openFile(const QString& theDirectory)
947 myCurrentFile = theDirectory;
948 if (myCurrentFile.isEmpty())
951 QFileInfo aFileInfo(myCurrentFile);
952 if (!aFileInfo.exists() || !aFileInfo.isReadable()) {
953 QMessageBox::critical(desktop(), tr("Warning"), tr("Unable to open the file."));
954 myCurrentFile = QString();
958 QApplication::setOverrideCursor(Qt::WaitCursor);
959 module()->closeDocument();
960 SessionPtr aSession = ModelAPI_Session::get();
961 aSession->closeAll();
964 if (!XGUI_CompressFiles::uncompress(myCurrentFile, myTmpDir.path()))
967 aSession->load(myTmpDir.path().toLatin1().constData());
968 myObjectBrowser->rebuildDataTree();
970 // Open first level of data tree
971 DocumentPtr aRootDoc = aSession->moduleDocument();
972 std::list<bool> aStates;
973 aRootDoc->restoreNodesState(aStates);
974 myObjectBrowser->setStateForDoc(aRootDoc, aStates);
976 updateCommandStatus();
978 myMainWindow->setCurrentDir(myCurrentFile, true);
982 bool aNewPart = Config_PropManager::boolean("Plugins", "create_part_by_start");
985 DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
986 int aSize = aRootDoc->size(ModelAPI_ResultPart::group());
988 ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), 0);
989 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
996 QApplication::restoreOverrideCursor();
999 //******************************************************
1000 void XGUI_Workshop::onNew()
1002 QApplication::setOverrideCursor(Qt::WaitCursor);
1003 if (objectBrowser() == 0) {
1004 createDockWidgets();
1005 mySelector->connectViewers();
1007 myViewerProxy->connectToViewer();
1008 showObjectBrowser();
1010 myMainWindow->showPythonConsole();
1011 QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
1012 aWnd->showMaximized();
1013 updateCommandStatus();
1015 myContextMenuMgr->connectViewer();
1016 QApplication::restoreOverrideCursor();
1020 //******************************************************
1021 void XGUI_Workshop::onExit()
1023 SessionPtr aMgr = ModelAPI_Session::get();
1024 if (aMgr->isModified()) {
1025 int anAnswer = QMessageBox::question(
1026 myMainWindow, tr("Save current file"), tr("The document is modified, save before exit?"),
1027 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
1028 if (anAnswer == QMessageBox::Save) {
1029 bool saved = onSave();
1033 } else if (anAnswer == QMessageBox::Cancel) {
1040 //******************************************************
1041 void XGUI_Workshop::onPreferences()
1043 ModuleBase_Prefs aModif;
1044 ModuleBase_Preferences::editPreferences(aModif);
1045 if (aModif.size() > 0) {
1047 foreach (ModuleBase_Pref aPref, aModif)
1049 aSection = aPref.first;
1050 if (aSection == ModuleBase_Preferences::VIEWER_SECTION) {
1051 myMainWindow->viewer()->updateFromResources();
1052 } else if (aSection == ModuleBase_Preferences::MENU_SECTION) {
1053 myMainWindow->menuObject()->updateFromResources();
1056 displayer()->redisplayObjects();
1061 //******************************************************
1062 void XGUI_Workshop::onTrihedronVisibilityChanged(bool theState)
1064 XGUI_Displayer* aDisplayer = displayer();
1066 aDisplayer->displayTrihedron(theState);
1069 //******************************************************
1070 bool XGUI_Workshop::onSave()
1072 if(!myOperationMgr->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
1074 if (myCurrentFile.isEmpty()) {
1077 SessionPtr aMgr = ModelAPI_Session::get();
1078 if (aMgr->isAutoUpdateBlocked())
1079 aMgr->blockAutoUpdate(false);
1081 std::list<std::string> aFiles;
1082 // issue #2899: create a temporary directory, save and then remove it
1084 std::string aTmpDir = XGUI_Tools::getTmpDirByEnv("SALOME_TMP_DIR");
1086 std::string aTmpDir = XGUI_Tools::getTmpDirByEnv("");
1088 saveDocument(QString(aTmpDir.c_str()), aFiles);
1089 bool aResult = XGUI_CompressFiles::compress(myCurrentFile, aFiles);
1090 XGUI_Tools::removeTemporaryFiles(aTmpDir, aFiles);
1093 updateCommandStatus();
1095 myMainWindow->setModifiedState(false);
1101 //******************************************************
1102 bool XGUI_Workshop::onSaveAs()
1104 if(!myOperationMgr->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
1106 myCurrentFile = QFileDialog::getSaveFileName(desktop(), tr("Select name to save file..."),
1107 QString(), MyFilter2);
1108 if (!myCurrentFile.isNull()) {
1109 if (!myCurrentFile.endsWith(MyExtension)) {
1110 myCurrentFile += MyExtension;
1116 myMainWindow->setCurrentDir(myCurrentFile, false);
1117 myMainWindow->setModifiedState(false);
1122 //******************************************************
1123 void XGUI_Workshop::onUndo(int theTimes)
1125 processUndoRedo(ActionUndo, theTimes);
1126 myObjectBrowser->updateAllIndexes(1);
1129 //******************************************************
1130 void XGUI_Workshop::onRedo(int theTimes)
1132 processUndoRedo(ActionRedo, theTimes);
1133 myObjectBrowser->updateAllIndexes(1);
1136 //******************************************************
1137 void XGUI_Workshop::processUndoRedo(const ModuleBase_ActionType theActionType, int theTimes)
1139 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1140 if (anActiveWidget) {
1141 ActionIntParamPtr aParam(new ModuleBase_ActionIntParameter(theTimes));
1142 if (anActiveWidget->processAction(theActionType, aParam))
1145 // the viewer update should be blocked in order to avoid the features blinking. For the created
1146 // feature a results are created, the flush of the created signal caused the viewer redisplay for
1147 // each created result. After a redisplay signal is flushed. So, the viewer update is blocked
1148 // until redo of all possible objects happens
1149 bool isUpdateEnabled = myDisplayer->enableUpdateViewer(false);
1151 SessionPtr aMgr = ModelAPI_Session::get();
1152 if (aMgr->isOperation()) {
1153 XGUI_OperationMgr* aOpMgr = operationMgr();
1154 /// this is important for nested operations
1155 /// when sketch operation is active, this condition is false and
1156 /// the sketch operation is not aborted
1157 if (aOpMgr->canStopOperation(aOpMgr->currentOperation()))
1158 aOpMgr->abortOperation(aOpMgr->currentOperation());
1161 myDisplayer->enableUpdateViewer(isUpdateEnabled);
1165 objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
1166 std::list<std::string> anActionList = theActionType == ActionUndo ? aMgr->undoList()
1168 std::list<std::string>::const_iterator aIt = anActionList.cbegin();
1169 for (int i = 0; (i < theTimes) && (aIt != anActionList.cend()); ++i, ++aIt) {
1170 if (theActionType == ActionUndo)
1175 if (QString((*aIt).c_str()) == MOVE_TO_END_COMMAND)
1176 myObjectBrowser->rebuildDataTree();
1178 operationMgr()->updateApplyOfOperations();
1179 facesPanel()->reset(true);
1180 updateCommandStatus();
1182 // unblock the viewer update functionality and make update on purpose
1183 myDisplayer->enableUpdateViewer(isUpdateEnabled);
1184 myDisplayer->updateViewer();
1185 // Clear messages in status bar from previous operations if exists
1186 setStatusBarMessage("");
1189 //******************************************************
1190 void XGUI_Workshop::onWidgetStateChanged(int thePreviousState)
1192 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1193 //ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
1194 //if (anOperation) {
1195 // ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1197 // anActiveWidget = aPanel->activeWidget();
1200 operationMgr()->onValidateOperation();
1202 myModule->widgetStateChanged(thePreviousState);
1205 //******************************************************
1206 void XGUI_Workshop::onValuesChanged()
1208 ModuleBase_ModelWidget* aSenderWidget = (ModuleBase_ModelWidget*)(sender());
1209 if (!aSenderWidget || aSenderWidget->canAcceptFocus())
1212 ModuleBase_ModelWidget* anActiveWidget = 0;
1213 ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
1215 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1217 anActiveWidget = aPanel->activeWidget();
1219 if (anActiveWidget) {
1220 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1222 if (aWidgetValidated)
1223 aWidgetValidated->clearValidatedCash();
1227 //******************************************************
1228 void XGUI_Workshop::onWidgetObjectUpdated()
1230 operationMgr()->onValidateOperation();
1233 //******************************************************
1234 ModuleBase_IModule* XGUI_Workshop::loadModule(const QString& theModule)
1236 QString libName = QString::fromStdString(library(theModule.toStdString()));
1237 if (libName.isEmpty()) {
1238 qWarning(qPrintable(tr("Information about module \"%1\" doesn't exist.").arg(theModule)));
1243 CREATE_FUNC crtInst = 0;
1246 HINSTANCE modLib = ::LoadLibraryA(qPrintable(libName));
1250 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
1251 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
1252 QString aMsg((char*) &lpMsgBuf);
1253 err = QString("Failed to load %1. %2").arg(libName).arg(aMsg);
1254 ::LocalFree(lpMsgBuf);
1256 crtInst = (CREATE_FUNC) ::GetProcAddress(modLib, CREATE_MODULE);
1260 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
1261 | FORMAT_MESSAGE_IGNORE_INSERTS,
1262 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
1263 QString aMsg((char*) &lpMsgBuf);
1264 err = QString("Failed to find %1 function. %2").arg( CREATE_MODULE).arg(aMsg);
1265 ::LocalFree(lpMsgBuf);
1269 void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY | RTLD_GLOBAL );
1271 err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
1273 crtInst = (CREATE_FUNC)dlsym( modLib, CREATE_MODULE );
1275 err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() );
1280 ModuleBase_IModule* aModule = crtInst ? crtInst(myModuleConnector) : 0;
1282 if (!err.isEmpty()) {
1284 Events_InfoMessage("XGUI_Workshop", err.toStdString()).send();
1286 qWarning(qPrintable(err));
1292 //******************************************************
1293 bool XGUI_Workshop::createModule()
1295 Config_ModuleReader aModuleReader;
1296 QString moduleName = QString::fromStdString(aModuleReader.getModuleName());
1297 myModule = loadModule(moduleName);
1301 //connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
1302 // myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
1303 //connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
1304 // myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
1306 myModule->createFeatures();
1308 salomeConnector()->createFeatureActions();
1310 //myActionsMgr->update();
1314 //******************************************************
1315 void XGUI_Workshop::updateCommandStatus()
1317 QList<QAction*> aCommands;
1319 aCommands = salomeConnector()->commandList();
1321 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
1322 foreach (AppElements_Command* aCmd, aMenuBar->features())
1323 aCommands.append(aCmd);
1325 SessionPtr aMgr = ModelAPI_Session::get();
1326 if (aMgr->hasModuleDocument()) {
1327 foreach(QAction* aCmd, aCommands) {
1328 QString aId = aCmd->data().toString();
1329 if (aId == "UNDO_CMD") {
1330 bool isActionEnabled = false;
1331 // if ultimate is true -> using result of operation only, or using OR combination
1332 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1333 if (anActiveWidget && anActiveWidget->canProcessAction(ActionUndo, isActionEnabled))
1334 aCmd->setEnabled(isActionEnabled);
1336 aCmd->setEnabled(myModule->canUndo());
1338 else if (aId == "REDO_CMD") {
1339 bool isActionEnabled = false;
1340 // if ultimate is true -> using result of operation only, or using OR combination
1341 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1342 if (anActiveWidget && anActiveWidget->canProcessAction(ActionRedo, isActionEnabled))
1343 aCmd->setEnabled(isActionEnabled);
1345 aCmd->setEnabled(myModule->canRedo());
1347 else if (aId == "AUTOCOMPUTE_CMD") {
1348 aCmd->setIcon(aMgr->isAutoUpdateBlocked() ?
1349 QIcon(":pictures/autoapply_stop.png") :
1350 QIcon(":pictures/autoapply_start.png"));
1353 // Enable all commands
1354 aCmd->setEnabled(true);
1358 foreach(QAction* aCmd, aCommands) {
1359 QString aId = aCmd->data().toString();
1360 if (aId == "NEW_CMD")
1361 aCmd->setEnabled(true);
1362 else if (aId == "EXIT_CMD")
1363 aCmd->setEnabled(true);
1365 aCmd->setEnabled(false);
1368 myActionsMgr->updateCommandsStatus();
1369 emit commandStatusUpdated();
1372 //******************************************************
1373 void XGUI_Workshop::updateHistory()
1375 bool isActionEnabled = false;
1376 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1377 QList<ActionInfo> aUndoRes;
1378 QList<ActionInfo> aRedoRes;
1379 if (anActiveWidget && anActiveWidget->canProcessAction(ActionUndo, isActionEnabled)) {
1380 aUndoRes = anActiveWidget->actionsList(ActionUndo);
1381 aRedoRes = anActiveWidget->actionsList(ActionRedo);
1383 std::list<std::string> aUndoList = ModelAPI_Session::get()->undoList();
1384 aUndoRes = processHistoryList(aUndoList);
1386 std::list<std::string> aRedoList = ModelAPI_Session::get()->redoList();
1387 aRedoRes = processHistoryList(aRedoList);
1389 emit updateUndoHistory(aUndoRes);
1390 emit updateRedoHistory(aRedoRes);
1393 //******************************************************
1394 QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
1396 QDockWidget* aObjDock = new QDockWidget(theParent);
1397 aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea |
1398 Qt::RightDockWidgetArea |
1399 Qt::BottomDockWidgetArea);
1400 aObjDock->setWindowTitle(tr("Object browser"));
1401 aObjDock->setStyleSheet(
1402 "::title { position: relative; padding-left: 5px; text-align: left center }");
1403 myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock, this);
1404 myObjectBrowser->initialize(myModule->rootNode());
1405 myModule->customizeObjectBrowser(myObjectBrowser);
1406 aObjDock->setWidget(myObjectBrowser);
1408 myContextMenuMgr->connectObjectBrowser();
1412 //******************************************************
1414 * Creates dock widgets, places them in corresponding area
1415 * and tabifies if necessary.
1417 void XGUI_Workshop::createDockWidgets()
1419 QMainWindow* aDesktop = desktop();
1420 QDockWidget* aObjDock = createObjectBrowser(aDesktop);
1421 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
1422 myPropertyPanel = new XGUI_PropertyPanel(aDesktop, myOperationMgr);
1423 myActiveControlMgr->addSelector(new XGUI_PropertyPanelSelector(myPropertyPanel));
1425 myPropertyPanel->setupActions(myActionsMgr);
1426 myPropertyPanel->setAllowedAreas(Qt::LeftDockWidgetArea |
1427 Qt::RightDockWidgetArea |
1428 Qt::BottomDockWidgetArea);
1429 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel);
1430 hidePanel(myPropertyPanel); ///<! Invisible by default
1432 myFacesPanel = new XGUI_FacesPanel(aDesktop, myModuleConnector);
1433 myActiveControlMgr->addSelector(new XGUI_FacesPanelSelector(myFacesPanel));
1434 myFacesPanel->setAllowedAreas(Qt::LeftDockWidgetArea |
1435 Qt::RightDockWidgetArea |
1436 Qt::BottomDockWidgetArea);
1437 connect(myFacesPanel, SIGNAL(closed()), myFacesPanel, SLOT(onClosed()));
1439 myInspectionPanel = new XGUI_InspectionPanel(aDesktop, mySelector);
1440 myInspectionPanel->setAllowedAreas(Qt::LeftDockWidgetArea |
1441 Qt::RightDockWidgetArea);
1442 aDesktop->addDockWidget(Qt::RightDockWidgetArea, myInspectionPanel);
1444 myInspectionPanel->hide();
1446 aDesktop->addDockWidget(
1448 Qt::RightDockWidgetArea,
1450 Qt::LeftDockWidgetArea,
1453 hidePanel(myFacesPanel); ///<! Invisible by default
1456 bool aShowOnTheRight = Config_PropManager::boolean("Plugins", "show_hide_faces");
1457 if (aShowOnTheRight) {
1458 aDesktop->addDockWidget(Qt::RightDockWidgetArea, myFacesPanel);
1459 showPanel(myFacesPanel);
1462 hideObjectBrowser();
1466 if (!aShowOnTheRight)
1469 aDesktop->tabifyDockWidget(myFacesPanel, aObjDock);
1474 #endif // HAVE_SALOME
1476 aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
1477 myPropertyPanel->installEventFilter(myOperationMgr);
1479 QAction* aOkAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept);
1480 connect(aOkAct, SIGNAL(triggered()), this, SLOT(onAcceptActionClicked()));
1482 QAction* aOkContAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptPlus);
1483 connect(aOkContAct, SIGNAL(triggered()), this, SLOT(onAcceptPlusActionClicked()));
1485 QAction* aCancelAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Abort);
1486 connect(aCancelAct, SIGNAL(triggered()), myOperationMgr, SLOT(onAbortOperation()));
1488 QAction* aPreviewAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Preview);
1489 connect(aPreviewAct, SIGNAL(triggered()), this, SLOT(onPreviewActionClicked()));
1491 QAction* aHelpAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Help);
1492 connect(aHelpAct, SIGNAL(triggered()), this, SLOT(onHelpActionClicked()));
1494 connect(myPropertyPanel, SIGNAL(keyReleased(QObject*, QKeyEvent*)),
1495 myOperationMgr, SLOT(onKeyReleased(QObject*, QKeyEvent*)));
1496 connect(myPropertyPanel, SIGNAL(enterClicked(QObject*)),
1497 myOperationMgr, SLOT(onProcessEnter(QObject*)));
1500 //******************************************************
1501 void XGUI_Workshop::showPanel(QDockWidget* theDockWidget)
1503 if (theDockWidget == myPropertyPanel) {
1504 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1505 ///<! Restore ability to close panel from the window's menu
1506 aViewAct->setEnabled(true);
1508 theDockWidget->show();
1509 theDockWidget->raise();
1511 // The next code is necessary to made the property panel the active window
1512 // in order to operation manager could process key events of the panel.
1513 // otherwise they are ignored. It happens only if the same(activateWindow) is
1514 // not happened by property panel activation(e.g. resume operation of Sketch)
1515 ModuleBase_Tools::setFocus(theDockWidget, "XGUI_Workshop::showPanel()");
1518 //******************************************************
1519 void XGUI_Workshop::hidePanel(QDockWidget* theDockWidget)
1521 if (theDockWidget && theDockWidget == myPropertyPanel) {
1522 QAction* aViewAct = theDockWidget->toggleViewAction();
1523 ///<! Do not allow to show empty property panel
1524 aViewAct->setEnabled(false);
1526 theDockWidget->hide();
1528 // the property panel is active window of the desktop, when it is
1529 // hidden, it is undefined which window becomes active. By this reason
1530 // it is defined to perform the desktop as the active window.
1531 // in SALOME mode, workstack made the PyConsole the active window,
1532 // set the focus on it. As a result, shortcuts of the application, like
1533 // are processed by this console. For example Undo actions.
1534 // It is possible that this code is to be moved to SHAPER package
1535 QMainWindow* aDesktop = desktop();
1536 ModuleBase_Tools::setFocus(aDesktop, "XGUI_Workshop::hidePanel()");
1539 //******************************************************
1540 void XGUI_Workshop::showObjectBrowser()
1542 if (!isSalomeMode()) {
1543 myObjectBrowser->parentWidget()->show();
1547 //******************************************************
1548 void XGUI_Workshop::hideObjectBrowser()
1550 if (!isSalomeMode())
1551 myObjectBrowser->parentWidget()->hide();
1554 //******************************************************
1555 void XGUI_Workshop::salomeViewerSelectionChanged()
1557 emit salomeViewerSelection();
1560 //**************************************************************
1561 ModuleBase_IViewer* XGUI_Workshop::salomeViewer() const
1563 return mySalomeConnector->viewer();
1566 //**************************************************************
1567 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
1569 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1570 if (theId == "DELETE_CMD")
1572 else if (theId == "CLEAN_HISTORY_CMD")
1574 else if (theId == "MOVE_CMD")
1576 else if (theId == "COLOR_CMD")
1577 changeColor(aObjects);
1578 else if (theId == "DEFLECTION_CMD")
1579 changeDeflection(aObjects);
1580 #ifdef USE_TRANSPARENCY
1581 else if (theId == "TRANSPARENCY_CMD")
1582 changeTransparency(aObjects);
1584 else if (theId == "SHOW_CMD") {
1585 showObjects(aObjects, true);
1586 mySelector->updateSelectionBy(ModuleBase_ISelection::Browser);
1587 updateCommandStatus();
1589 else if (theId == "HIDE_CMD") {
1590 showObjects(aObjects, false);
1591 updateCommandStatus();
1593 else if (theId == "SHOW_ONLY_CMD") {
1594 showOnlyObjects(aObjects);
1595 mySelector->updateSelectionBy(ModuleBase_ISelection::Browser);
1596 updateCommandStatus();
1598 else if (theId == "SHADING_CMD")
1599 setDisplayMode(aObjects, XGUI_Displayer::Shading);
1600 else if (theId == "WIREFRAME_CMD")
1601 setDisplayMode(aObjects, XGUI_Displayer::Wireframe);
1602 else if (theId == "HIDEALL_CMD") {
1603 QObjectPtrList aList = myDisplayer->displayedObjects();
1604 foreach (ObjectPtr aObj, aList) {
1605 if (module()->canEraseObject(aObj))
1606 aObj->setDisplayed(false);
1608 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1610 //issue #2159 Hide all incomplete behavior
1611 viewer()->eraseAll();
1613 updateCommandStatus();
1614 // Necessary for update icons in ObjectBrowser on Linux
1615 myObjectBrowser->updateAllIndexes();
1616 } else if (theId == "SELECT_VERTEX_CMD") {
1617 setViewerSelectionMode(TopAbs_VERTEX);
1618 } else if (theId == "SELECT_EDGE_CMD") {
1619 setViewerSelectionMode(TopAbs_EDGE);
1620 } else if (theId == "SELECT_FACE_CMD") {
1621 setViewerSelectionMode(TopAbs_FACE);
1622 } else if (theId == "INSERT_FOLDER_CMD") {
1623 insertFeatureFolder();
1624 } else if (theId == "ADD_TO_FOLDER_BEFORE_CMD") {
1625 insertToFolder(true);
1626 } else if (theId == "ADD_TO_FOLDER_AFTER_CMD") {
1627 insertToFolder(false);
1628 } else if (theId == "ADD_OUT_FOLDER_BEFORE_CMD") {
1629 moveOutFolder(true);
1630 } else if (theId == "ADD_OUT_FOLDER_AFTER_CMD") {
1631 moveOutFolder(false);
1632 } else if (theId == "SELECT_RESULT_CMD") {
1633 //setViewerSelectionMode(-1);
1634 //IMP: an attempt to use result selection with other selection modes
1635 setViewerSelectionMode(ModuleBase_ResultPrs::Sel_Result);
1636 setViewerSelectionMode(TopAbs_COMPSOLID);
1637 } else if (theId == "SHOW_RESULTS_CMD") {
1638 highlightResults(aObjects);
1639 } else if (theId == "SHOW_FEATURE_CMD") {
1640 highlightFeature(aObjects);
1643 else if (theId == "TINSPECTOR_VIEW") {
1644 Handle(CDF_Application) anApplication = CDF_Session::CurrentSession()->CurrentApplication();
1645 if (!anApplication.IsNull())
1647 if (!MyTCommunicator)
1649 MyTCommunicator = new TInspector_Communicator();
1651 NCollection_List<Handle(Standard_Transient)> aParameters;
1652 aParameters.Append(anApplication);
1653 Handle(AIS_InteractiveContext) aContext = viewer()->AISContext();
1654 if (!aContext.IsNull())
1655 aParameters.Append(aContext);
1657 #ifdef DEBUG_WITH_MESSAGE_REPORT
1658 Handle(Message_Report) aContextReport = aContext->GetReport();
1659 aContext->SetReportActive (Standard_True);
1660 aContextReport->SetLimit (1000);
1661 if (!aContextReport.IsNull())
1662 aParameters.Append(aContextReport);
1664 MyVCallBack = new VInspector_CallBack();
1665 myDisplayer->setCallBack(MyVCallBack);
1667 AppElements_Viewer* aViewer = mainWindow()->viewer();
1669 aViewer->setCallBack(MyVCallBack);
1671 aParameters.Append(MyVCallBack);
1673 MyTCommunicator->RegisterPlugin("TKDFBrowser");
1674 MyTCommunicator->RegisterPlugin("TKShapeView");
1675 MyTCommunicator->RegisterPlugin("TKVInspector");
1676 #ifdef DEBUG_WITH_MESSAGE_REPORT
1677 MyTCommunicator->RegisterPlugin("TKMessageView");
1679 //MyTCommunicator->RegisterPlugin("SMBrowser"); // custom plugin to view ModelAPI
1680 //MyTCommunicator->RegisterPlugin("TKSMBrowser"); // custom plugin to view ModelAPI
1682 MyTCommunicator->Init(aParameters);
1683 MyTCommunicator->Activate("TKSMBrowser"); // to have button in TInspector
1684 #ifndef DEBUG_WITH_MESSAGE_REPORT
1685 MyTCommunicator->Activate("TKVInspector"); // to have filled callback by model
1687 MyTCommunicator->Activate("TKDFBrowser");
1689 #ifdef DEBUG_WITH_MESSAGE_REPORT
1690 MyTCommunicator->Activate("TKMessageView"); // temporary
1691 MyTCommunicator->Activate("TKVInspector"); // to have filled callback by model
1694 MyTCommunicator->SetVisible(true);
1700 //**************************************************************
1701 void XGUI_Workshop::setViewerSelectionMode(int theMode)
1704 myViewerSelMode.clear();
1706 if (myViewerSelMode.contains(theMode))
1707 myViewerSelMode.removeAll(theMode);
1709 myViewerSelMode.append(theMode);
1711 selectionActivate()->updateSelectionModes();
1714 //**************************************************************
1715 void XGUI_Workshop::activateObjectsSelection(const QObjectPtrList& theList)
1718 module()->activeSelectionModes(aModes);
1719 if (aModes.isEmpty() && (myViewerSelMode.length() > 0))
1720 aModes.append(myViewerSelMode);
1721 selectionActivate()->activateObjects(aModes, theList);
1724 //**************************************************************
1725 bool XGUI_Workshop::prepareForDisplay(const std::set<ObjectPtr>& theObjects) const
1727 if (facesPanel()->isEmpty())
1730 // generate container of objects taking into account sub elments of compsolid
1731 std::set<ObjectPtr> anAllProcessedObjects;
1732 for (std::set<ObjectPtr>::const_iterator anObjectsIt = theObjects.begin();
1733 anObjectsIt != theObjects.end(); anObjectsIt++) {
1734 ObjectPtr anObject = *anObjectsIt;
1735 ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(anObject);
1736 if (aCompRes.get()) {
1737 std::list<ResultPtr> allRes;
1738 ModelAPI_Tools::allSubs(aCompRes, allRes);
1739 if (allRes.empty()) {
1740 anAllProcessedObjects.insert(anObject);
1742 for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
1743 ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aRes);
1744 if (aBody.get() && aBody->numberOfSubs() == 0)
1745 anAllProcessedObjects.insert(aBody);
1749 anAllProcessedObjects.insert(anObject);
1752 // find hidden objects in faces panel
1753 std::set<ObjectPtr> aHiddenObjects;
1754 QStringList aHiddenObjectNames;
1755 for (std::set<ObjectPtr>::const_iterator anObjectsIt = anAllProcessedObjects.begin();
1756 anObjectsIt != anAllProcessedObjects.end(); anObjectsIt++) {
1757 if (!facesPanel()->isObjectHiddenByPanel(*anObjectsIt))
1759 aHiddenObjects.insert(*anObjectsIt);
1760 aHiddenObjectNames.append((*anObjectsIt)->data()->name().c_str());
1762 if (aHiddenObjects.empty()) // in parameter objects there are no hidden objects in hide face
1765 int anAnswer = QMessageBox::question(
1766 desktop(), tr("Show object"),
1767 tr("'%1'\n are hidden by %2:\nRemove objects from the panel to be displayed?")
1768 .arg(aHiddenObjectNames.join(", ")).arg(facesPanel()->windowTitle()),
1769 QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
1771 bool aToBeDisplayed = anAnswer == QMessageBox::Yes;
1773 facesPanel()->restoreObjects(aHiddenObjects);
1775 return aToBeDisplayed;
1778 //**************************************************************
1779 void XGUI_Workshop::deleteObjects()
1781 ModuleBase_IModule* aModule = module();
1782 // allow the module to delete objects, do nothing if it has succeed
1783 if (aModule->deleteObjects()) {
1784 updateCommandStatus();
1788 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1789 if (!abortAllOperations())
1792 bool hasResult = false;
1793 bool hasFeature = false;
1794 bool hasParameter = false;
1795 bool hasCompositeOwner = false;
1796 bool hasResultInHistory = false;
1797 bool hasFolder = false;
1798 ModuleBase_Tools::checkObjects(anObjects, hasResult, hasFeature, hasParameter, hasCompositeOwner,
1799 hasResultInHistory, hasFolder);
1800 if (!(hasFeature || hasParameter || hasFolder))
1804 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1805 std::set<FeaturePtr> aFeatures;
1806 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1807 ModelAPI_Tools::findAllReferences(aFeatures, aReferences);
1809 std::set<FolderPtr> aFolders;
1810 ModuleBase_Tools::convertToFolders(anObjects, aFolders);
1813 QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text() + " %1";
1814 aDescription = aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
1815 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, module());
1817 operationMgr()->startOperation(anOpAction);
1819 std::set<FeaturePtr> aFeatureRefsToDelete;
1820 if (ModuleBase_Tools::askToDelete(aFeatures, aReferences, desktop(), aFeatureRefsToDelete)) {
1821 // WORKAROUND, should be done before each object remove, if it presents in XGUI_DataModel tree
1822 // It is necessary to clear selection in order to avoid selection changed event during
1823 // deletion and negative consequences connected with processing of already deleted items
1824 mySelector->clearSelection();
1826 if (!aFeatureRefsToDelete.empty())
1827 aFeatures.insert(aFeatureRefsToDelete.begin(), aFeatureRefsToDelete.end());
1828 aDone = ModelAPI_Tools::removeFeatures(aFeatures, false);
1830 if (aFolders.size() > 0) {
1831 std::set<FolderPtr>::const_iterator anIt = aFolders.begin(),
1832 aLast = aFolders.end();
1833 for (; anIt != aLast; anIt++) {
1834 FolderPtr aFolder = *anIt;
1835 if (aFolder.get()) {
1836 DocumentPtr aDoc = aFolder->document();
1837 aDoc->removeFolder(aFolder);
1843 operationMgr()->commitOperation();
1845 operationMgr()->abortOperation(operationMgr()->currentOperation());
1848 //**************************************************************
1849 void addRefsToFeature(const FeaturePtr& theFeature,
1850 const std::map<FeaturePtr, std::set<FeaturePtr> >& theMainList,
1851 std::set<FeaturePtr>& theReferences)
1853 //if (theReferences.find(theFeature) != theReferences.end())
1855 if (theMainList.find(theFeature) == theMainList.end())
1856 return; // this feature is not in the selection list, so exists without references to it
1857 std::set<FeaturePtr> aMainReferences = theMainList.at(theFeature);
1859 std::set<FeaturePtr>::const_iterator anIt = aMainReferences.begin(),
1860 aLast = aMainReferences.end();
1861 for (; anIt != aLast; anIt++) {
1862 FeaturePtr aRefFeature = *anIt;
1863 if (theReferences.find(aRefFeature) == theReferences.end())
1864 theReferences.insert(aRefFeature);
1865 addRefsToFeature(aRefFeature, theMainList, theReferences);
1869 //**************************************************************
1870 void XGUI_Workshop::cleanHistory()
1872 if (!abortAllOperations())
1875 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1876 std::set<FeaturePtr> aFeatures;
1877 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1879 #ifdef DEBUG_CLEAN_HISTORY
1881 std::set<FeaturePtr>::const_iterator aFIt;
1882 for (aFIt = aFeatures.begin(); aFIt != aFeatures.end(); ++aFIt) {
1883 FeaturePtr aFeature = ModelAPI_Feature::feature(*aFIt);
1884 anInfo.append(aFeature->name().c_str());
1886 QString anInfoStr = anInfo.join(";\t");
1887 qDebug(QString("cleanHistory for: [%1] - %2").
1888 arg(aFeatures.size()).arg(anInfoStr).toStdString().c_str());
1891 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1892 ModelAPI_Tools::findAllReferences(aFeatures, aReferences, true, false);
1893 // find for each object whether all reference values are in the map as key, that means that there
1894 // is no other reference in the model to this object, so it might be removed by cleaning history
1895 // sk_1(ext_1, vertex_1) + (sk_3, bool_1) - cann't be deleted, dependency to bool_1
1896 // ext_1(bool_1, sk_3) - cann't be deleted, dependency to bool_1
1898 // sk_2(ext_2) + (bool_1) - cann't be deleted, dependency to bool_1
1899 // ext_2(bool_1) - cann't be deleted, dependency to bool_1
1901 // Information: bool_1 is not selected
1902 std::set<FeaturePtr> anUnusedObjects;
1903 std::map<FeaturePtr, std::set<FeaturePtr> >::const_iterator aMainIt = aReferences.begin(),
1904 aMainLast = aReferences.end();
1905 for (; aMainIt != aMainLast; aMainIt++) {
1906 FeaturePtr aMainListFeature = aMainIt->first;
1907 std::set<FeaturePtr> aMainRefList = aMainIt->second;
1908 std::set<FeaturePtr>::const_iterator aRefIt = aMainRefList.begin(),
1909 aRefLast = aMainRefList.end();
1910 bool aFeatureOutOfTheList = false;
1911 for (; aRefIt != aRefLast && !aFeatureOutOfTheList; aRefIt++) {
1912 FeaturePtr aRefFeature = *aRefIt;
1913 aFeatureOutOfTheList = aReferences.find(aRefFeature) == aReferences.end();
1915 if (!aFeatureOutOfTheList)
1916 anUnusedObjects.insert(aMainListFeature);
1919 #ifdef DEBUG_CLEAN_HISTORY
1921 for (aFIt = anUnusedObjects.begin(); aFIt != anUnusedObjects.end(); ++aFIt) {
1922 FeaturePtr aFeature = *aFIt;
1923 anInfo.append(aFeature->name().c_str());
1925 qDebug(QString("unused objects: [%1] - %2").
1926 arg(anInfo.size()).arg(anInfo.join(";\t")).toStdString().c_str());
1929 // warn about the references remove, break the delete operation if the user chose it
1930 if (!anUnusedObjects.empty()) {
1932 foreach (const FeaturePtr& aFeature, anUnusedObjects) {
1933 aNames.append(aFeature->name().c_str());
1936 QString anUnusedNames = aNames.join(", ");
1938 QString anActionId = "CLEAN_HISTORY_CMD";
1939 QString aDescription = contextMenuMgr()->action(anActionId)->text();
1941 QMessageBox aMessageBox(desktop());
1942 aMessageBox.setWindowTitle(aDescription);
1943 aMessageBox.setIcon(QMessageBox::Warning);
1944 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
1945 aMessageBox.setDefaultButton(QMessageBox::No);
1947 const char* aKeyStr = "Unused features are the following: "
1948 "%1.\nThese features will be deleted.\nWould you like to continue?";
1949 QString aText = QString(tr(aKeyStr).arg(anUnusedNames));
1950 aMessageBox.setText(aText);
1951 if (aMessageBox.exec() == QMessageBox::No)
1954 // 1. start operation
1955 aDescription += "by deleting of " +
1956 aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
1957 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, module());
1958 operationMgr()->startOperation(anOpAction);
1960 // WORKAROUND, should be done before each object remove, if it presents in XGUI_DataModel tree
1961 // It is necessary to clear selection in order to avoid selection changed event during
1962 // deletion and negative consequences connected with processing of already deleted items
1963 mySelector->clearSelection();
1965 std::set<FeaturePtr> anIgnoredFeatures;
1966 if (ModelAPI_Tools::removeFeatures(anUnusedObjects, true)) {
1967 operationMgr()->commitOperation();
1970 operationMgr()->abortOperation(operationMgr()->currentOperation());
1974 QString anActionId = "CLEAN_HISTORY_CMD";
1975 QString aDescription = contextMenuMgr()->action(anActionId)->text();
1977 QMessageBox aMessageBox(desktop());
1978 aMessageBox.setWindowTitle(aDescription);
1979 aMessageBox.setIcon(QMessageBox::Warning);
1980 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
1981 aMessageBox.setDefaultButton(QMessageBox::No);
1984 aMessageBox.setStandardButtons(QMessageBox::Ok);
1985 aMessageBox.setDefaultButton(QMessageBox::Ok);
1987 aText = QString(tr("All features are relevant, there is nothing to be deleted"));
1988 aMessageBox.setText(aText);
1990 if (aMessageBox.exec() == QMessageBox::No)
1995 //**************************************************************
1996 void XGUI_Workshop::moveObjects()
1998 if (!abortAllOperations())
2001 SessionPtr aMgr = ModelAPI_Session::get();
2003 QString anActionId = "MOVE_CMD";
2004 QString aDescription = contextMenuMgr()->action(anActionId)->text();
2005 aMgr->startOperation(aDescription.toStdString());
2007 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
2008 // It is necessary to clear selection in order to avoid selection changed event during
2009 // moving and negative consequences connected with processing of already moved items
2010 mySelector->clearSelection();
2011 // check whether the object can be moved. There should not be parts which are not loaded
2012 std::set<FeaturePtr> aFeatures;
2013 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
2014 if (!XGUI_Tools::canRemoveOrRename(desktop(), aFeatures))
2017 DocumentPtr anActiveDocument = aMgr->activeDocument();
2018 FeaturePtr aCurrentFeature = anActiveDocument->currentFeature(true);
2019 std::set<FeaturePtr>::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
2020 for (; anIt != aLast; anIt++) {
2021 FeaturePtr aFeature = *anIt;
2022 if (!aFeature.get() || !myModule->canApplyAction(aFeature, anActionId))
2025 anActiveDocument->moveFeature(aFeature, aCurrentFeature);
2026 aCurrentFeature = anActiveDocument->currentFeature(true);
2028 aMgr->finishOperation();
2031 //**************************************************************
2032 bool XGUI_Workshop::deleteFeatures(const QObjectPtrList& theObjects)
2034 std::set<FeaturePtr> aFeatures;
2035 ModuleBase_Tools::convertToFeatures(theObjects, aFeatures);
2037 return ModelAPI_Tools::removeFeaturesAndReferences(aFeatures);
2040 //******************************************************
2041 bool hasResults(QObjectPtrList theObjects, const std::set<std::string>& theTypes)
2043 bool isFoundResultType = false;
2044 foreach(ObjectPtr anObj, theObjects)
2046 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
2047 if (aResult.get() == NULL)
2050 isFoundResultType = theTypes.find(aResult->groupName()) != theTypes.end();
2051 if (isFoundResultType)
2054 return isFoundResultType;
2057 //**************************************************************
2058 // Returns the list of all features for theDocument and all features of
2059 // all nested parts.
2060 std::list<FeaturePtr> allFeatures(const DocumentPtr& theDocument)
2062 std::list<FeaturePtr> aResultList;
2063 std::list<FeaturePtr> anAllFeatures = theDocument->allFeatures();
2064 foreach (const FeaturePtr& aFeature, anAllFeatures) {
2065 // The order of appending features of the part and the part itself is important
2067 // Append features from a part feature
2068 std::list<ResultPtr> aResults;
2069 ModelAPI_Tools::allResults(aFeature, aResults);
2070 foreach (const ResultPtr& aResult, aResults) {
2071 ResultPartPtr aResultPart =
2072 std::dynamic_pointer_cast<ModelAPI_ResultPart>(aResult);
2073 if (aResultPart.get() && aResultPart->partDoc().get()) {
2075 std::list<FeaturePtr> anAllFeatures = allFeatures(aResultPart->partDoc());
2076 aResultList.insert(aResultList.end(), anAllFeatures.begin(), anAllFeatures.end());
2080 aResultList.push_back(aFeature);
2085 //**************************************************************
2086 // Returns the list of features placed between theObject and the current feature
2087 // in the same document. Excludes theObject, includes the current feature.
2088 std::list<FeaturePtr> toCurrentFeatures(const ObjectPtr& theObject)
2090 std::list<FeaturePtr> aResult;
2091 DocumentPtr aDocument = theObject->document();
2092 std::list<FeaturePtr> anAllFeatures = allFeatures(aDocument);
2093 // find the object iterator
2094 std::list<FeaturePtr>::iterator aObjectIt =
2095 std::find(anAllFeatures.begin(), anAllFeatures.end(), theObject);
2096 if (aObjectIt == anAllFeatures.end())
2098 // find the current feature iterator
2099 std::list<FeaturePtr>::iterator aCurrentIt =
2100 std::find(anAllFeatures.begin(), anAllFeatures.end(), aDocument->currentFeature(true));
2101 if (aCurrentIt == anAllFeatures.end())
2103 // check the right order
2104 if (std::distance(aObjectIt, anAllFeatures.end()) <=
2105 std::distance(aCurrentIt, anAllFeatures.end()))
2107 // exclude the object
2108 std::advance(aObjectIt, 1);
2109 // include the current feature
2110 std::advance(aCurrentIt, 1);
2111 return std::list<FeaturePtr>(aObjectIt, aCurrentIt);
2114 //******************************************************
2115 bool XGUI_Workshop::canMoveFeature()
2117 QString anActionId = "MOVE_CMD";
2119 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
2120 QObjectPtrList aValidatedObjects;
2121 foreach (ObjectPtr aObject, aObjects) {
2122 if (!myModule->canApplyAction(aObject, anActionId))
2124 // To be moved feature should be in active document
2125 if (aObject->document() != ModelAPI_Session::get()->activeDocument())
2127 aValidatedObjects.append(aObject);
2129 if (aValidatedObjects.size() != aObjects.size())
2130 aObjects = aValidatedObjects;
2132 bool aCanMove = !aObjects.empty();
2134 QObjectPtrList::const_iterator anIt = aObjects.begin(), aLast = aObjects.end();
2135 for (; anIt != aLast && aCanMove; anIt++) {
2136 ObjectPtr aObject = *anIt;
2137 if (!aObject.get() || !aObject->data().get() || !aObject->data()->isValid()) {
2141 FeaturePtr aFeat = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
2142 // only groups can be moved to the end for now (#2451)
2143 if (aFeat.get() && aFeat->getKind() != "Group") {
2148 // 1. Get features placed between selected and current in the document
2149 std::list<FeaturePtr> aFeaturesBetween = toCurrentFeatures(aObject);
2150 // if aFeaturesBetween is empty it means wrong order or aObject is the current feature
2151 if (aFeaturesBetween.empty())
2154 std::set<FeaturePtr> aPlacedFeatures(aFeaturesBetween.begin(), aFeaturesBetween.end());
2155 // 2. Get all reference features to the selected object in the document
2156 std::set<FeaturePtr> aRefFeatures;
2157 ModuleBase_Tools::refsToFeatureInFeatureDocument(aObject, aRefFeatures);
2159 if (aRefFeatures.empty())
2162 // 3. Find any placed features in all reference features
2163 std::set<FeaturePtr> aIntersectionFeatures;
2164 std::set_intersection(aRefFeatures.begin(), aRefFeatures.end(),
2165 aPlacedFeatures.begin(), aPlacedFeatures.end(),
2166 std::inserter(aIntersectionFeatures, aIntersectionFeatures.begin()));
2167 // 4. Return false if any reference feature is placed before current feature
2168 if (!aIntersectionFeatures.empty())
2176 //**************************************************************
2177 bool XGUI_Workshop::canBeShaded(const ObjectPtr& theObject) const
2179 bool aCanBeShaded = myDisplayer->canBeShaded(theObject);
2180 if (!aCanBeShaded) {
2181 ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theObject);
2182 if (aCompRes.get() != NULL) { // change colors for all sub-solids
2183 std::list<ResultPtr> allRes;
2184 ModelAPI_Tools::allSubs(aCompRes, allRes);
2185 std::list<ResultPtr>::iterator aRes = allRes.begin();
2186 for(; aRes != allRes.end() && !aCanBeShaded; aRes++) {
2187 aCanBeShaded = myDisplayer->canBeShaded(*aRes);
2191 return aCanBeShaded;
2194 //**************************************************************
2195 bool XGUI_Workshop::canChangeProperty(const QString& theActionName) const
2197 if (theActionName == "COLOR_CMD" ||
2198 theActionName == "DEFLECTION_CMD"
2199 #ifdef USE_TRANSPARENCY
2200 || theActionName == "TRANSPARENCY_CMD"
2203 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
2205 std::set<std::string> aTypes;
2206 aTypes.insert(ModelAPI_ResultGroup::group());
2207 aTypes.insert(ModelAPI_ResultConstruction::group());
2208 aTypes.insert(ModelAPI_ResultBody::group());
2209 aTypes.insert(ModelAPI_ResultPart::group());
2211 return hasResults(aObjects, aTypes);
2216 //******************************************************
2217 void setColor(ResultPtr theResult, const std::vector<int>& theColor)
2219 if (!theResult.get())
2222 AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
2223 if (aColorAttr.get() != NULL) {
2224 if (!aColorAttr->size()) {
2225 aColorAttr->setSize(3);
2227 aColorAttr->setValue(0, theColor[0]);
2228 aColorAttr->setValue(1, theColor[1]);
2229 aColorAttr->setValue(2, theColor[2]);
2231 static const Events_ID kRedisplayEvent =
2232 Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
2233 ModelAPI_EventCreator::get()->sendUpdated(theResult, kRedisplayEvent);
2236 //**************************************************************
2237 void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
2240 AttributeIntArrayPtr aColorAttr;
2241 // 1. find the current color of the object. This is a color of AIS presentation
2242 // The objects are iterated until a first valid color is found
2243 std::vector<int> aColor;
2244 foreach(ObjectPtr anObject, theObjects) {
2245 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
2246 if (aResult.get()) {
2247 XGUI_CustomPrs::getResultColor(aResult, aColor);
2250 // TODO: remove the obtaining a color from the AIS object
2251 // this does not happen never because:
2252 // 1. The color can be changed only on results
2253 // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
2254 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
2255 if (anAISObj.get()) {
2257 anAISObj->getColor(aColor[0], aColor[1], aColor[2]);
2260 if (!aColor.empty())
2263 if (aColor.size() != 3)
2266 if (!abortAllOperations())
2268 // 2. show the dialog to change the value
2269 XGUI_ColorDialog* aDlg = new XGUI_ColorDialog(desktop());
2270 aDlg->setColor(aColor);
2271 aDlg->move(QCursor::pos());
2272 bool isDone = aDlg->exec() == QDialog::Accepted;
2276 bool isRandomColor = aDlg->isRandomColor();
2278 // 3. abort the previous operation and start a new one
2279 SessionPtr aMgr = ModelAPI_Session::get();
2280 QString aDescription = contextMenuMgr()->action("COLOR_CMD")->text();
2281 aMgr->startOperation(aDescription.toStdString());
2283 // 4. set the value to all results
2284 std::vector<int> aColorResult = aDlg->getColor();
2285 foreach(ObjectPtr anObj, theObjects) {
2286 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
2287 if (aResult.get() != NULL) {
2288 ResultBodyPtr aBodyResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
2289 if (aBodyResult.get() != NULL) { // change colors for all sub-solids
2290 std::list<ResultPtr> allRes;
2291 ModelAPI_Tools::allSubs(aBodyResult, allRes);
2292 for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
2293 setColor(*aRes, !isRandomColor ? aColorResult : aDlg->getRandomColor());
2296 setColor(aResult, !isRandomColor ? aColorResult : aDlg->getRandomColor());
2299 aMgr->finishOperation();
2300 updateCommandStatus();
2303 //**************************************************************
2304 void setDeflection(ResultPtr theResult, const double theDeflection)
2306 if (!theResult.get())
2309 AttributeDoublePtr aDeflectionAttr = theResult->data()->real(ModelAPI_Result::DEFLECTION_ID());
2310 if (aDeflectionAttr.get() != NULL)
2311 aDeflectionAttr->setValue(theDeflection);
2312 static const Events_ID kRedisplayEvent =
2313 Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
2314 ModelAPI_EventCreator::get()->sendUpdated(theResult, kRedisplayEvent);
2317 //**************************************************************
2318 void setTransparency(ResultPtr theResult, double theTransparency)
2320 if (!theResult.get())
2323 AttributeDoublePtr anAttribute = theResult->data()->real(ModelAPI_Result::TRANSPARENCY_ID());
2324 if (anAttribute.get() != NULL)
2325 anAttribute->setValue(theTransparency);
2326 static const Events_ID kRedisplayEvent =
2327 Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
2328 ModelAPI_EventCreator::get()->sendUpdated(theResult, kRedisplayEvent);
2331 //**************************************************************
2332 void setTransparency(double theTransparency, const QObjectPtrList& theObjects)
2334 foreach(ObjectPtr anObj, theObjects) {
2335 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
2336 if (aResult.get() != NULL) {
2337 ResultBodyPtr aBodyResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
2338 if (aBodyResult.get() != NULL) { // change property for all sub-solids
2339 std::list<ResultPtr> allRes;
2340 ModelAPI_Tools::allSubs(aBodyResult, allRes);
2341 for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
2342 setTransparency(*aRes, theTransparency);
2345 setTransparency(aResult, theTransparency);
2350 //**************************************************************
2351 void XGUI_Workshop::changeDeflection(const QObjectPtrList& theObjects)
2353 AttributeDoublePtr aDoubleAttr;
2354 // 1. find the current property of the object. This is a property of AIS presentation
2355 // The objects are iterated until a first valid property is found
2356 double aDeflection = -1;
2357 foreach(ObjectPtr anObject, theObjects) {
2358 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
2359 if (aResult.get()) {
2360 aDeflection = XGUI_CustomPrs::getResultDeflection(aResult);
2363 // TODO: remove the obtaining a property from the AIS object
2364 // this does not happen never because:
2365 // 1. The property can be changed only on results
2366 // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
2367 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
2368 if (anAISObj.get()) {
2369 aDeflection = anAISObj->getDeflection();
2372 if (aDeflection > 0)
2375 if (aDeflection < 0)
2378 if (!abortAllOperations())
2380 // 2. show the dialog to change the value
2381 XGUI_DeflectionDialog* aDlg = new XGUI_DeflectionDialog(desktop());
2382 aDlg->setDeflection(aDeflection);
2383 aDlg->move(QCursor::pos());
2384 bool isDone = aDlg->exec() == QDialog::Accepted;
2388 // 3. abort the previous operation and start a new one
2389 SessionPtr aMgr = ModelAPI_Session::get();
2390 QString aDescription = contextMenuMgr()->action("DEFLECTION_CMD")->text();
2391 aMgr->startOperation(aDescription.toStdString());
2393 // 4. set the value to all results
2394 aDeflection = aDlg->getDeflection();
2395 foreach(ObjectPtr anObj, theObjects) {
2396 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
2397 if (aResult.get() != NULL) {
2398 ResultBodyPtr aBodyResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
2399 if (aBodyResult.get() != NULL) { // change property for all sub-solids
2400 std::list<ResultPtr> allRes;
2401 ModelAPI_Tools::allSubs(aBodyResult, allRes);
2402 for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
2403 setDeflection(*aRes, aDeflection);
2406 setDeflection(aResult, aDeflection);
2409 aMgr->finishOperation();
2410 updateCommandStatus();
2413 //**************************************************************
2414 void XGUI_Workshop::changeTransparency(const QObjectPtrList& theObjects)
2416 AttributeDoublePtr aDoubleAttr;
2417 // 1. find the current property of the object. This is a property of AIS presentation
2418 // The objects are iterated until a first valid property is found
2419 double aCurrentValue = -1;
2420 foreach(ObjectPtr anObject, theObjects) {
2421 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
2422 if (aResult.get()) {
2423 aCurrentValue = XGUI_CustomPrs::getResultTransparency(aResult);
2426 // TODO: remove the obtaining a property from the AIS object
2427 // this does not happen never because:
2428 // 1. The property can be changed only on results
2429 // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
2430 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
2431 if (anAISObj.get()) {
2432 aCurrentValue = anAISObj->getDeflection();
2435 if (aCurrentValue > 0)
2438 if (aCurrentValue < 0)
2441 if (!abortAllOperations())
2444 // 2. show the dialog to change the value
2445 XGUI_PropertyDialog* aDlg = new XGUI_PropertyDialog(desktop());
2446 aDlg->setWindowTitle("Transparency");
2447 XGUI_TransparencyWidget* aTransparencyWidget = new XGUI_TransparencyWidget(aDlg);
2448 connect(aTransparencyWidget, SIGNAL(transparencyValueChanged()),
2449 this, SLOT(onTransparencyValueChanged()));
2450 connect(aTransparencyWidget, SIGNAL(previewStateChanged()),
2451 this, SLOT(onPreviewStateChanged()));
2452 aDlg->setContent(aTransparencyWidget);
2453 aTransparencyWidget->setValue(aCurrentValue);
2455 // 3. abort the previous operation and start a new one
2456 SessionPtr aMgr = ModelAPI_Session::get();
2457 QString aDescription = contextMenuMgr()->action("TRANSPARENCY_CMD")->text();
2458 aMgr->startOperation(aDescription.toStdString());
2460 aDlg->move(QCursor::pos());
2461 bool isDone = aDlg->exec() == QDialog::Accepted;
2465 // 4. set the value to all results
2466 aCurrentValue = aTransparencyWidget->getValue();
2467 setTransparency(aCurrentValue, theObjects);
2469 aMgr->finishOperation();
2470 updateCommandStatus();
2473 //**************************************************************
2474 void XGUI_Workshop::onTransparencyValueChanged()
2476 XGUI_TransparencyWidget* aTransparencyWidget = (XGUI_TransparencyWidget*)sender();
2477 if (!aTransparencyWidget || !aTransparencyWidget->isPreviewNeeded())
2480 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
2481 setTransparency(aTransparencyWidget->getValue(), anObjects);
2482 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2485 //**************************************************************
2486 void XGUI_Workshop::onPreviewStateChanged()
2488 XGUI_TransparencyWidget* aTransparencyWidget = (XGUI_TransparencyWidget*)sender();
2489 if (!aTransparencyWidget || !aTransparencyWidget->isPreviewNeeded())
2492 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
2493 setTransparency(aTransparencyWidget->getValue(), anObjects);
2494 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2497 //**************************************************************
2498 #define SET_DISPLAY_GROUP(aGroupName, aDisplay) \
2499 for (int i = 0; i < aDoc->size(aGroupName); i++) { \
2500 aDoc->object(aGroupName, i)->setDisplayed(aDisplay); \
2503 //******************************************************
2504 void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible)
2507 std::set<ObjectPtr> anObjects;
2508 foreach (ObjectPtr aObj, theList) {
2509 anObjects.insert(aObj);
2511 if (!prepareForDisplay(anObjects))
2515 foreach (ObjectPtr aObj, theList) {
2516 aObj->setDisplayed(isVisible);
2518 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2519 myObjectBrowser->updateAllIndexes();
2522 //**************************************************************
2523 void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList)
2525 QObjectPtrList aSrcList = theList;
2526 // Hide all displayed objects
2527 QObjectPtrList aList = myDisplayer->displayedObjects();
2528 foreach (ObjectPtr aObj, aList) {
2529 if ((!aSrcList.contains(aObj)) && (module()->canEraseObject(aObj)))
2530 aObj->setDisplayed(false);
2532 aSrcList.removeAll(aObj);
2534 //Do not use eraseAll if you didn't send Redisplay event:
2535 //all objects are erased from viewer, but considered as displayed in displayer
2536 // Problem in bug 2218
2537 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2539 //issue #2159 Hide all incomplete behavior
2540 viewer()->eraseAll();
2543 std::set<ObjectPtr> anObjects;
2544 foreach (ObjectPtr aObj, aSrcList) {
2545 anObjects.insert(aObj);
2548 if (!prepareForDisplay(anObjects))
2551 // Show only objects from the list
2552 foreach (ObjectPtr aObj, aSrcList) {
2553 aObj->setDisplayed(true);
2555 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2557 // Necessary for update icons in ObjectBrowser on Linux
2558 myObjectBrowser->updateAllIndexes();
2561 //**************************************************************
2562 void XGUI_Workshop::registerValidators() const
2564 SessionPtr aMgr = ModelAPI_Session::get();
2565 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
2568 //**************************************************************
2569 void XGUI_Workshop::displayDocumentResults(DocumentPtr theDoc)
2573 displayGroupResults(theDoc, ModelAPI_ResultConstruction::group());
2574 displayGroupResults(theDoc, ModelAPI_ResultBody::group());
2577 //**************************************************************
2578 void XGUI_Workshop::displayGroupResults(DocumentPtr theDoc, std::string theGroup)
2580 for (int i = 0; i < theDoc->size(theGroup); i++)
2581 theDoc->object(theGroup, i)->setDisplayed(true);
2582 //displayObject(theDoc->object(theGroup, i));
2583 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2586 //**************************************************************
2587 void XGUI_Workshop::setDisplayMode(const QObjectPtrList& theList, int theMode)
2589 foreach(ObjectPtr anObj, theList) {
2590 myDisplayer->setDisplayMode(anObj, (XGUI_Displayer::DisplayMode)theMode, false);
2592 ResultBodyPtr aBodyResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(anObj);
2593 if (aBodyResult.get() != NULL) { // change display mode for all sub-solids
2594 std::list<ResultPtr> allRes;
2595 ModelAPI_Tools::allSubs(aBodyResult, allRes);
2596 for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
2597 myDisplayer->setDisplayMode(*aRes, (XGUI_Displayer::DisplayMode)theMode, false);
2601 if (theList.size() > 0)
2602 myDisplayer->updateViewer();
2605 //**************************************************************
2606 void XGUI_Workshop::closeDocument()
2608 ModuleBase_Operation* anOperation = operationMgr()->currentOperation();
2609 while (anOperation) {
2610 anOperation->abort();
2611 anOperation = operationMgr()->currentOperation();
2613 //myDisplayer->closeLocalContexts();
2614 myDisplayer->eraseAll();
2615 objectBrowser()->clearContent();
2617 module()->closeDocument();
2618 // we need to clear viewer (with created filters) to do not have problems in 2nd SALOME study
2619 module()->clearViewer();
2622 // data model need not process the document's signals about objects modifications as
2623 // the document is closed
2624 //bool isBlocked = objectBrowser()->dataModel()->blockEventsProcessing(true);
2626 SessionPtr aMgr = ModelAPI_Session::get();
2629 //objectBrowser()->dataModel()->blockEventsProcessing(isBlocked);
2632 //******************************************************
2633 void XGUI_Workshop::addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot)
2635 XGUI_HistoryMenu* aMenu = NULL;
2636 if (isSalomeMode()) {
2637 QAction* anAction = qobject_cast<QAction*>(theObject);
2640 aMenu = new XGUI_HistoryMenu(anAction);
2642 QToolButton* aButton = qobject_cast<QToolButton*>(theObject);
2643 aMenu = new XGUI_HistoryMenu(aButton);
2645 connect(this, theSignal, aMenu, SLOT(setHistory(const QList<ActionInfo>&)));
2646 connect(aMenu, SIGNAL(actionSelected(int)), this, theSlot);
2649 //******************************************************
2650 QList<ActionInfo> XGUI_Workshop::processHistoryList(const std::list<std::string>& theList) const
2652 QList<ActionInfo> aResult;
2653 std::list<std::string>::const_iterator it = theList.cbegin();
2654 for (; it != theList.cend(); it++) {
2655 QString anId = QString::fromStdString(*it);
2656 bool isEditing = anId.endsWith(ModuleBase_OperationFeature::EditSuffix());
2658 anId.chop(ModuleBase_OperationFeature::EditSuffix().size());
2661 QAction* aContextMenuAct = myContextMenuMgr->actionByName(anId);
2662 if (aContextMenuAct) {
2663 anInfo.initFrom(aContextMenuAct);
2665 anInfo = myActionsMgr->actionInfoById(anId);
2668 anInfo.text = anInfo.text.prepend("Modify ");
2675 //******************************************************
2676 void XGUI_Workshop::setStatusBarMessage(const QString& theMessage)
2679 salomeConnector()->putInfo(theMessage, -1);
2681 myMainWindow->putInfo(theMessage, -1);
2686 //******************************************************
2687 void XGUI_Workshop::synchronizeViewer()
2689 SessionPtr aMgr = ModelAPI_Session::get();
2690 QList<DocumentPtr> aDocs;
2691 aDocs.append(aMgr->activeDocument());
2692 aDocs.append(aMgr->moduleDocument());
2694 foreach(DocumentPtr aDoc, aDocs) {
2695 synchronizeGroupInViewer(aDoc, ModelAPI_ResultConstruction::group(), false);
2696 synchronizeGroupInViewer(aDoc, ModelAPI_ResultBody::group(), false);
2697 synchronizeGroupInViewer(aDoc, ModelAPI_ResultPart::group(), false);
2698 synchronizeGroupInViewer(aDoc, ModelAPI_ResultGroup::group(), false);
2702 //******************************************************
2703 void XGUI_Workshop::synchronizeGroupInViewer(const DocumentPtr& theDoc,
2704 const std::string& theGroup,
2705 bool theUpdateViewer)
2708 int aSize = theDoc->size(theGroup);
2709 for (int i = 0; i < aSize; i++) {
2710 aObj = theDoc->object(theGroup, i);
2711 if (aObj->isDisplayed()) {
2712 // Hide the presentation with an empty shape. But isDisplayed state of the object should not
2713 // be changed to the object becomes visible when the shape becomes not empty
2714 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
2715 if (aRes.get() && (!aRes->shape().get() || aRes->shape()->isNull()))
2717 ResultBodyPtr aResBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aObj);
2719 synchronizeResultTree(aResBody, false);
2721 myDisplayer->display(aObj, false);
2724 if (theUpdateViewer)
2725 myDisplayer->updateViewer();
2728 void XGUI_Workshop::synchronizeResultTree(const ResultBodyPtr& theRes, bool theUpdateViewer)
2730 if (theRes->numberOfSubs() > 0)
2731 for (int i = 0; i < theRes->numberOfSubs(); i++) {
2732 ResultBodyPtr aRes = theRes->subResult(i);
2734 synchronizeResultTree(aRes, theUpdateViewer);
2737 myDisplayer->display(theRes, theUpdateViewer);
2741 //******************************************************
2742 void XGUI_Workshop::highlightResults(const QObjectPtrList& theObjects)
2744 FeaturePtr aFeature;
2745 QObjectPtrList aSelList = theObjects;
2746 QObjectPtrList aNewSel;
2747 bool aHasHidden = false;
2748 foreach(ObjectPtr aObj, theObjects) {
2749 aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
2750 if (aFeature.get()) {
2751 std::list<ResultPtr> aResults;
2752 ModelAPI_Tools::allResults(aFeature, aResults);
2753 std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aIt;
2754 for(aIt = aResults.cbegin(); aIt != aResults.cend(); aIt++) {
2755 aHasHidden |= (*aIt)->isConcealed();
2756 aSelList.append(*aIt);
2757 aNewSel.append(*aIt);
2761 if (aSelList.count() > theObjects.count()) {
2762 // if something was found
2763 objectBrowser()->setObjectsSelected(aSelList);
2764 objectBrowser()->ensureVisible(aNewSel.first());
2767 QMessageBox::information(desktop(), tr("Find results"),
2768 tr("Results not found"), QMessageBox::Ok);
2771 //******************************************************
2772 void XGUI_Workshop::highlightFeature(const QObjectPtrList& theObjects)
2775 QObjectPtrList aSelList = theObjects;
2776 QObjectPtrList aNewSel;
2777 FeaturePtr aFeature;
2778 foreach(ObjectPtr aObj, theObjects) {
2779 aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
2780 if (aResult.get()) {
2781 aFeature = ModelAPI_Feature::feature(aResult);
2782 if (aFeature.get()) {
2783 aSelList.append(aFeature);
2784 aNewSel.append(aFeature);
2788 if (aSelList.count() > theObjects.count()) {
2789 // if something was found
2790 objectBrowser()->setObjectsSelected(aSelList);
2791 objectBrowser()->ensureVisible(aNewSel.first());
2795 void XGUI_Workshop::insertFeatureFolder()
2797 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
2798 if (aObjects.isEmpty())
2800 ObjectPtr aObj = aObjects.first();
2801 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
2802 if (aFeature.get() == NULL)
2804 SessionPtr aMgr = ModelAPI_Session::get();
2805 DocumentPtr aDoc = aMgr->activeDocument();
2807 QString aDescription = contextMenuMgr()->action("INSERT_FOLDER_CMD")->text();
2809 aMgr->startOperation(aDescription.toStdString());
2810 aDoc->addFolder(aFeature);
2811 aMgr->finishOperation();
2813 updateCommandStatus();
2817 void XGUI_Workshop::insertToFolder(bool isBefore)
2819 std::list<FeaturePtr> aFeatures = mySelector->getSelectedFeatures();
2820 if (aFeatures.empty())
2823 SessionPtr aMgr = ModelAPI_Session::get();
2824 DocumentPtr aDoc = aMgr->activeDocument();
2826 FolderPtr aFolder = isBefore? aDoc->findFolderAbove(aFeatures):
2827 aDoc->findFolderBelow(aFeatures);
2831 QString aDescription = contextMenuMgr()->action(
2832 isBefore ? "ADD_TO_FOLDER_BEFORE_CMD" : "ADD_TO_FOLDER_AFTER_CMD")->text();
2834 QMap<ObjectPtr, bool> aStates = myObjectBrowser->getFoldersState(aDoc);
2836 aMgr->startOperation(aDescription.toStdString());
2837 aDoc->moveToFolder(aFeatures, aFolder);
2838 aMgr->finishOperation();
2840 myObjectBrowser->setFoldersState(aStates);
2842 updateCommandStatus();
2845 void XGUI_Workshop::moveOutFolder(bool isBefore)
2847 std::list<FeaturePtr> aFeatures = mySelector->getSelectedFeatures();
2848 if (aFeatures.empty())
2851 SessionPtr aMgr = ModelAPI_Session::get();
2852 DocumentPtr aDoc = aMgr->activeDocument();
2854 QString aDescription = contextMenuMgr()->action(
2855 isBefore ? "ADD_OUT_FOLDER_BEFORE_CMD" : "ADD_OUT_FOLDER_AFTER_CMD")->text();
2857 QMap<ObjectPtr, bool> aStates = myObjectBrowser->getFoldersState(aDoc);
2859 aMgr->startOperation(aDescription.toStdString());
2860 aDoc->removeFromFolder(aFeatures, isBefore);
2861 aMgr->finishOperation();
2863 myObjectBrowser->setFoldersState(aStates);
2865 updateCommandStatus();
2868 void XGUI_Workshop::onAutoApply()
2870 SessionPtr aMgr = ModelAPI_Session::get();
2871 bool isBlocked = aMgr->isAutoUpdateBlocked();
2872 aMgr->blockAutoUpdate(!isBlocked);
2875 void XGUI_Workshop::updateAutoComputeState()
2877 SessionPtr aMgr = ModelAPI_Session::get();
2878 bool isComputeBlocked = aMgr->isAutoUpdateBlocked();
2880 // QAction* aUpdateCmd;
2881 // QList<QAction*> aCommands = mySalomeConnector->commandList();
2882 // foreach(QAction* aCmd, aCommands) {
2883 // if (aCmd->data().toString() == "AUTOCOMPUTE_CMD") {
2884 // aUpdateCmd = aCmd;
2888 // aUpdateCmd->setIcon(isComputeBlocked? QIcon(":pictures/autoapply_stop.png") :
2889 // QIcon(":pictures/autoapply_start.png"));
2891 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
2892 AppElements_Command* aUpdateCmd = aMenuBar->feature("AUTOCOMPUTE_CMD");
2893 aUpdateCmd->button()->setIcon(isComputeBlocked? QIcon(":pictures/autoapply_stop.png") :
2894 QIcon(":pictures/autoapply_start.png"));
2899 void XGUI_Workshop::clearTemporaryDir()
2901 QDir aDir(myTmpDir.path());
2902 if (!aDir.isEmpty()) {
2903 QStringList aEntries;
2904 aDir.entryList(aEntries);
2905 foreach(QString aFile, aEntries) {