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_HistoryMenu.h>
49 #include <XGUI_QtEvents.h>
50 #include <XGUI_DataModel.h>
51 #include <XGUI_InspectionPanel.h>
52 #include <XGUI_CompressFiles.h>
55 #include <AppElements_Button.h>
56 #include <AppElements_Command.h>
57 #include <AppElements_MainMenu.h>
58 #include <AppElements_MainWindow.h>
59 #include <AppElements_MenuGroupPanel.h>
60 #include <AppElements_Viewer.h>
61 #include <AppElements_Workbench.h>
64 #include <Config_XMLReader.h>
66 #include <ModelAPI_AttributeDocRef.h>
67 #include <ModelAPI_AttributeIntArray.h>
68 #include <ModelAPI_AttributeDouble.h>
69 #include <ModelAPI_Data.h>
70 #include <ModelAPI_Events.h>
71 #include <ModelAPI_Feature.h>
72 #include <ModelAPI_Object.h>
73 #include <ModelAPI_ResultBody.h>
74 #include <ModelAPI_ResultConstruction.h>
75 #include <ModelAPI_ResultGroup.h>
76 #include <ModelAPI_ResultParameter.h>
77 #include <ModelAPI_ResultField.h>
78 #include <ModelAPI_Session.h>
79 #include <ModelAPI_Validator.h>
80 #include <ModelAPI_Tools.h>
81 #include <ModelAPI_ResultField.h>
83 //#include <PartSetPlugin_Part.h>
85 #include <Events_Loop.h>
86 #include <Events_InfoMessage.h>
87 #include <Events_LongOp.h>
89 #include <GeomAPI_Pnt.h>
91 #include <ModuleBase_IModule.h>
92 #include <ModuleBase_IViewer.h>
93 #include <ModuleBase_Operation.h>
94 #include <ModuleBase_OperationDescription.h>
95 #include <ModuleBase_PageBase.h>
96 #include <ModuleBase_Preferences.h>
97 #include <ModuleBase_SelectionValidator.h>
98 #include <ModuleBase_Tools.h>
99 #include <ModuleBase_WidgetFactory.h>
100 #include <ModuleBase_OperationFeature.h>
101 #include <ModuleBase_OperationAction.h>
102 #include <ModuleBase_PagedContainer.h>
103 #include <ModuleBase_WidgetValidated.h>
104 #include <ModuleBase_ModelWidget.h>
105 #include <ModuleBase_ResultPrs.h>
106 #include <ModuleBase_ActionIntParameter.h>
107 #include <ModuleBase_IStepPrs.h>
109 #include <Config_Common.h>
110 #include <Config_FeatureMessage.h>
111 #include <Config_ModuleReader.h>
112 #include <Config_PointerMessage.h>
113 #include <Config_PropManager.h>
114 #include <Config_DataModelReader.h>
115 #include <Config_Translator.h>
116 #include <Config_WidgetAPI.h>
117 #include <Config_Keywords.h>
119 #include <SUIT_ResourceMgr.h>
121 #include <AIS_Trihedron.hxx>
122 #ifdef BEFORE_TRIHEDRON_PATCH
123 #include <AIS_Point.hxx>
124 #include <AIS_Axis.hxx>
127 #include <QApplication>
128 #include <QFileDialog>
129 #include <QMessageBox>
130 #include <QMdiSubWindow>
131 #include <QMainWindow>
132 #include <QPushButton>
133 #include <QDockWidget>
138 #include <QToolButton>
140 #include <QDesktopWidget>
142 #include <QDesktopServices>
147 #include <CDF_Session.hxx>
148 #include <CDF_Application.hxx>
149 #include <inspector/TInspector_Communicator.hxx>
150 #include <inspector/VInspector_CallBack.hxx>
151 static TInspector_Communicator* MyTCommunicator;
152 static Handle(VInspector_CallBack) MyVCallBack;
167 //#define DEBUG_WITH_MESSAGE_REPORT
169 QString XGUI_Workshop::MOVE_TO_END_COMMAND = QObject::tr("Move to the end");
171 //#define DEBUG_DELETE
172 //#define DEBUG_FEATURE_NAME
173 //#define DEBUG_CLEAN_HISTORY
176 static QString MyFilter(QObject::tr("SHAPER files (*.shaper *.cadbld)"));
177 static QString MyFilter2(QObject::tr("SHAPER files (*.shaper)"));
178 static QString MyExtension(".shaper");
180 static QString MyFilter(QObject::tr("CAD Builder files (*.cadbld);;All files (*.*)"));
181 static QString MyFilter2(QObject::tr("CAD Builder files (*.cadbld)"));
182 static QString MyExtension(".cadbld");
186 //******************************************************
187 XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
190 mySalomeConnector(theConnector),
192 myInspectionPanel(0),
196 //myViewerSelMode(TopAbs_FACE)
198 mySelector = new XGUI_SelectionMgr(this);
199 myModuleConnector = new XGUI_ModuleConnector(this);
200 myOperationMgr = new XGUI_OperationMgr(this, 0);
201 ModuleBase_IWorkshop* aWorkshop = moduleConnector();
202 // Has to be defined first in order to get errors and messages from other components
203 myEventsListener = new XGUI_WorkshopListener(this);
204 mySelectionActivate = new XGUI_SelectionActivate(aWorkshop);
206 SUIT_ResourceMgr* aResMgr = ModuleBase_Preferences::resourceMgr();
208 myMainWindow = new AppElements_MainWindow();
210 bool aCloc = aResMgr->booleanValue("language", "locale", true);
212 QLocale::setDefault( QLocale::c() );
214 QLocale::setDefault( QLocale::system() );
216 QString aPath = Config_XMLReader::pluginConfigFile().c_str();
221 #ifdef MAKE_TRANSLATION
222 QString aCurrLang = aResMgr->stringValue("language", "language", "en");
223 if(aCurrLang == "en") {
226 aLangs << "*_" + aCurrLang + ".ts"; // then replace with translated files
229 aLangs << "*_en.ts"; // load by default eng translations
232 foreach(QString aLang, aLangs) {
233 QStringList aFilters;
235 QStringList aTsFiles = aDir.entryList(aFilters, QDir::Files);
236 foreach(QString aFileName, aTsFiles) {
237 Config_Translator::load(aFileName.toStdString());
241 myDataModelXMLReader = new Config_DataModelReader();
242 //myDataModelXMLReader->readAll();
244 myDisplayer = new XGUI_Displayer(this);
246 connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(updateCommandStatus()));
248 myActionsMgr = new XGUI_ActionsMgr(this);
249 myActiveControlMgr = new XGUI_ActiveControlMgr(myModuleConnector);
250 myMenuMgr = new XGUI_MenuMgr(this);
251 myErrorDlg = new XGUI_ErrorDialog(QApplication::desktop());
252 myContextMenuMgr = new XGUI_ContextMenuMgr(this);
253 connect(myContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), this,
254 SLOT(onContextMenuCommand(const QString&, bool)));
256 myViewerProxy = new XGUI_ViewerProxy(this);
257 //connect(myViewerProxy, SIGNAL(selectionChanged()),
258 // myActionsMgr, SLOT(updateOnViewSelection()));
260 myOperationMgr->setWorkshop(aWorkshop);
262 myErrorMgr = new XGUI_ErrorMgr(this, aWorkshop);
264 connect(myOperationMgr, SIGNAL(operationResumed(ModuleBase_Operation*)),
265 SLOT(onOperationResumed(ModuleBase_Operation*)));
266 connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
267 SLOT(onOperationStopped(ModuleBase_Operation*)));
268 connect(myOperationMgr, SIGNAL(operationCommitted(ModuleBase_Operation*)),
269 SLOT(onOperationCommitted(ModuleBase_Operation*)));
270 connect(myOperationMgr, SIGNAL(operationAborted(ModuleBase_Operation*)),
271 SLOT(onOperationAborted(ModuleBase_Operation*)));
274 connect(myMainWindow, SIGNAL(exitKeySequence()), SLOT(onExit()));
275 myDisplayer->displayTrihedron(true);
278 connect(myEventsListener, SIGNAL(errorOccurred(std::shared_ptr<Events_InfoMessage>)),
279 myErrorDlg, SLOT(addError(std::shared_ptr<Events_InfoMessage>)));
281 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "face-selection", true))
282 myViewerSelMode.append(TopAbs_FACE);
283 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "edge-selection", true))
284 myViewerSelMode.append(TopAbs_EDGE);
285 if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "vertex-selection", true))
286 myViewerSelMode.append(TopAbs_VERTEX);
287 //IMP: an attempt to use result selection with other selection modes
288 myViewerSelMode.append(ModuleBase_ResultPrs::Sel_Result);//TopAbs_VERTEX);
289 myViewerSelMode.append(TopAbs_COMPSOLID);
292 //******************************************************
293 XGUI_Workshop::~XGUI_Workshop(void)
296 #ifdef MISSED_TRANSLATION
297 // Save Missed translations
298 Config_Translator::saveMissedTranslations();
303 delete myDataModelXMLReader;
304 delete mySelectionActivate;
309 //******************************************************
310 void XGUI_Workshop::startApplication()
312 //Initialize event listening
313 myEventsListener->initializeEventListening();
315 myDataModelXMLReader->readAll();
318 Config_PropManager::registerProp("Plugins", "default_path", "Default Path",
319 Config_Prop::Directory, "");
321 std::string aDir = Config_XMLReader::resourcesConfigFile();
322 Config_PropManager::registerProp("Plugins", "import_initial_path", "Import initial directory",
323 Config_Prop::Directory, aDir);
326 Config_PropManager::registerProp("Plugins", "create_part_by_start", "Create Part by Start",
327 Config_Prop::Boolean, "false");
329 Config_PropManager::registerProp("Plugins", "show_hide_faces", "Show Hide Faces (on the right)",
330 Config_Prop::Boolean, "false");
332 registerValidators();
334 // Calling of loadCustomProps before activating module is required
335 // by Config_PropManger to restore user-defined path to plugins
336 ModuleBase_Preferences::loadCustomProps();
340 myMainWindow->show();
341 updateCommandStatus();
346 myViewerProxy->connectViewProxy();
347 connect(myViewerProxy, SIGNAL(trihedronVisibilityChanged(bool)),
348 SLOT(onTrihedronVisibilityChanged(bool)));
350 emit applicationStarted();
353 bool aNewPart = Config_PropManager::boolean("Plugins", "create_part_by_start");
355 module()->launchOperation("Part", false); // PartSetPlugin_Part::ID()
360 //******************************************************
361 void XGUI_Workshop::activateModule()
363 selectionActivate()->updateSelectionFilters();
365 connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
366 myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
367 connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
368 myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
370 updateCommandStatus();
372 // TODO: get default selection mode
374 // activate visualized objects in the viewer
375 activateObjectsSelection(displayer()->displayedObjects());
376 myOperationMgr->activate();
379 //******************************************************
380 void XGUI_Workshop::deactivateModule()
382 // remove internal displayer filter
383 displayer()->deactivateSelectionFilters(false);
385 disconnect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
386 myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
387 disconnect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
388 myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
390 XGUI_Displayer* aDisplayer = displayer();
391 QObjectPtrList aDisplayed = aDisplayer->displayedObjects();
392 aDisplayer->deactivateObjects(aDisplayed, true);
393 selectionActivate()->deactivateTrihedronInSelectionModes();
395 #ifdef BEFORE_TRIHEDRON_PATCH
396 //Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(aDisplayer->getTrihedron());
397 /// Trihedron problem: objects stayed in the viewer, should be removed manually
398 /// otherwise in SALOME happens crash by HideAll in the viewer
399 aContext->Remove(aTrihedron->Position(), true);
400 aContext->Remove(aTrihedron->Axis(), true);
401 aContext->Remove(aTrihedron->XAxis(), true);
402 aContext->Remove(aTrihedron->YAxis(), true);
405 myOperationMgr->deactivate();
408 //******************************************************
409 void XGUI_Workshop::initMenu()
411 myContextMenuMgr->createActions();
414 // Create only Undo, Redo commands
415 QAction* aAction = salomeConnector()->addDesktopCommand("UNDO_CMD", tr("Undo"),
416 tr("Undo last command"),
417 QIcon(":pictures/undo.png"),
418 QKeySequence::Undo, false,
420 QString aToolBarTitle = tr( "INF_DESK_TOOLBAR_STANDARD" );
421 salomeConnector()->addActionInToolbar( aAction,aToolBarTitle );
423 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onUndo()));
424 addHistoryMenu(aAction, SIGNAL(updateUndoHistory(const QList<ActionInfo>&)), SLOT(onUndo(int)));
426 aAction = salomeConnector()->addDesktopCommand("REDO_CMD", tr("Redo"), tr("Redo last command"),
427 QIcon(":pictures/redo.png"), QKeySequence::Redo,
428 false, "MEN_DESK_EDIT");
429 salomeConnector()->addActionInToolbar( aAction, aToolBarTitle );
431 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo()));
432 addHistoryMenu(aAction, SIGNAL(updateRedoHistory(const QList<ActionInfo>&)), SLOT(onRedo(int)));
434 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
436 //aAction = salomeConnector()->addDesktopCommand("AUTOCOMPUTE_CMD", tr("Auto rebuild"),
437 // tr("Blocks immediate apply of modifications"),
438 // QIcon(":pictures/autoapply.png"), QKeySequence(),
439 // false, "MEN_DESK_EDIT");
440 //salomeConnector()->addActionInToolbar( aAction, aToolBarTitle );
442 //connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onAutoApply()));
444 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
447 // Add commands to a file menu
448 aAction = salomeConnector()->addDesktopCommand("SAVEAS_CMD", tr("Export native..."),
449 tr("Export the current document into a native file"),
450 QIcon(), QKeySequence(),
451 false, "MEN_DESK_FILE");
452 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onSaveAs()));
454 aAction = salomeConnector()->addDesktopCommand("OPEN_CMD", tr("Import native..."),
455 tr("Import native file"),
456 QIcon(), QKeySequence(),
457 false, "MEN_DESK_FILE");
458 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onOpen()));
459 salomeConnector()->addDesktopMenuSeparator("MEN_DESK_FILE");
462 // File commands group
463 AppElements_MenuGroupPanel* aGroup = myMainWindow->menuObject()->generalPage();
465 AppElements_Command* aCommand;
467 aCommand = aGroup->addFeature("SAVE_CMD", tr("Save"), tr("Save the document"),
468 QIcon(":pictures/save.png"), QKeySequence::Save);
469 aCommand->connectTo(this, SLOT(onSave()));
470 //aCommand->disable();
472 aCommand = aGroup->addFeature("SAVEAS_CMD", tr("Save as..."), tr("Save the document into a file"),
473 QIcon(":pictures/save.png"), QKeySequence());
474 aCommand->connectTo(this, SLOT(onSaveAs()));
476 QString aUndoId = "UNDO_CMD";
477 aCommand = aGroup->addFeature(aUndoId, tr("Undo"), tr("Undo last command"),
478 QIcon(":pictures/undo.png"), QKeySequence::Undo);
479 aCommand->connectTo(this, SLOT(onUndo()));
480 AppElements_Button* aUndoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aUndoId));
481 addHistoryMenu(aUndoButton,
482 SIGNAL(updateUndoHistory(const QList<ActionInfo>&)),
485 QString aRedoId = "REDO_CMD";
486 aCommand = aGroup->addFeature(aRedoId, tr("Redo"), tr("Redo last command"),
487 QIcon(":pictures/redo.png"), QKeySequence::Redo);
488 aCommand->connectTo(this, SLOT(onRedo()));
489 AppElements_Button* aRedoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aRedoId));
490 addHistoryMenu(aRedoButton,
491 SIGNAL(updateRedoHistory(const QList<ActionInfo>&)),
494 aCommand = aGroup->addFeature("OPEN_CMD", tr("Open..."), tr("Open a new document"),
495 QIcon(":pictures/open.png"), QKeySequence::Open);
496 aCommand->connectTo(this, SLOT(onOpen()));
499 aCommand = aGroup->addFeature("AUTOCOMPUTE_CMD", tr("Auto rebuild"),
500 tr("Blocks immediate apply of modifications"),
501 QIcon(":pictures/autoapply_start.png"), QKeySequence());
502 aCommand->setChecked(ModelAPI_Session::get()->isAutoUpdateBlocked());
503 aCommand->connectTo(this, SLOT(onAutoApply()));
505 aCommand = aGroup->addFeature("PREF_CMD", tr("Preferences"), tr("Edit preferences"),
506 QIcon(":pictures/preferences.png"), QKeySequence::Preferences);
507 aCommand->connectTo(this, SLOT(onPreferences()));
509 aCommand = aGroup->addFeature("EXIT_CMD", tr("Exit"), tr("Exit application"),
510 QIcon(":pictures/close.png"), QKeySequence::Close);
511 aCommand->connectTo(this, SLOT(onExit()));
516 //******************************************************
517 AppElements_Workbench* XGUI_Workshop::addWorkbench(const QString& theName)
519 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
520 return aMenuBar->addWorkbench(theName);
524 //******************************************************
525 QMainWindow* XGUI_Workshop::desktop() const
528 return salomeConnector()->desktop();
534 //******************************************************
535 void XGUI_Workshop::onStartWaiting()
537 if (Events_LongOp::isPerformed()) {
538 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
542 //******************************************************
543 void XGUI_Workshop::onAcceptActionClicked()
545 QAction* anAction = dynamic_cast<QAction*>(sender());
546 XGUI_OperationMgr* anOperationMgr = operationMgr();
547 if (anOperationMgr) {
548 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
549 (anOperationMgr->currentOperation());
551 //if (errorMgr()->canProcessClick(anAction, aFOperation->feature()))
552 myOperationMgr->commitOperation();
557 //******************************************************
558 void XGUI_Workshop::onAcceptPlusActionClicked()
560 QAction* anAction = dynamic_cast<QAction*>(sender());
561 XGUI_OperationMgr* anOperationMgr = operationMgr();
562 if (anOperationMgr) {
563 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
564 (anOperationMgr->currentOperation());
566 if (myOperationMgr->commitOperation())
567 module()->launchOperation(aFOperation->id(), false);
572 //******************************************************
573 void XGUI_Workshop::onPreviewActionClicked()
575 ModuleBase_IPropertyPanel* aPanel = propertyPanel();
577 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
578 if (anActiveWidget && anActiveWidget->getValueState() == ModuleBase_ModelWidget::ModifiedInPP) {
579 anActiveWidget->storeValue();
582 std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
583 new Events_Message(Events_Loop::eventByName(EVENT_PREVIEW_REQUESTED)));
584 Events_Loop::loop()->send(aMsg);
588 //******************************************************
589 void XGUI_Workshop::onHelpActionClicked()
591 XGUI_OperationMgr* anOperationMgr = operationMgr();
592 if (anOperationMgr) {
593 ModuleBase_Operation* aOperation = anOperationMgr->currentOperation();
595 QString aHelpPage = aOperation->helpFileName();
596 if (!aHelpPage.isEmpty()) {
598 const QChar aSep = QDir::separator();
600 // SUIT_ResourceMgr* aResMgr = ModuleBase_Preferences::resourceMgr();
602 // platform = "winapplication";
604 // platform = "application";
606 // QString aBrowserName = aResMgr->stringValue("ExternalBrowser", platform);
609 QString aDir(getenv("SHAPER_ROOT_DIR"));
610 if (!aDir.isEmpty()) {
611 aDocDir = aDir + aSep + "share" + aSep + "doc" + aSep +
612 "salome" + aSep + "gui" + aSep + "SHAPER";
615 QString aDir(getenv("CADBUILDER_ROOT_DIR"));
616 aDocDir = aDir + aSep + "doc" + aSep + "gui";
618 QString aFileName = aDocDir + aSep + aHelpPage;
619 if (QFile::exists(aFileName)) {
620 QUrl aUrl = QUrl::fromLocalFile(aFileName);
621 QDesktopServices::openUrl(aUrl);
629 //******************************************************
630 void XGUI_Workshop::deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer)
632 if (!myModule->canActivateSelection(theObject)) {
633 if (selectionActivate()->isActive(theObject)) {
634 QObjectPtrList anObjects;
635 anObjects.append(theObject);
636 myDisplayer->deactivateObjects(anObjects, theUpdateViewer);
641 //******************************************************
642 bool XGUI_Workshop::isFeatureOfNested(const FeaturePtr& theFeature)
644 bool aHasNested = false;
645 std::string aFeatureKind = theFeature->getKind();
647 XGUI_SalomeConnector* aSalomeConnector = salomeConnector();
648 if (aSalomeConnector->isFeatureOfNested(actionsMgr()->action(aFeatureKind.c_str())))
651 AppElements_MainMenu* aMenuBar = mainWindow()->menuObject();
652 AppElements_Command* aCommand = aMenuBar->feature(aFeatureKind.c_str());
653 if (aCommand && aCommand->button()->additionalButtonWidget())
659 //******************************************************
660 void XGUI_Workshop::fillPropertyPanel(ModuleBase_Operation* theOperation)
662 ModuleBase_OperationFeature* aFOperation =
663 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
667 showPanel(myPropertyPanel);
668 myPropertyPanel->cleanContent();
670 QList<ModuleBase_ModelWidget*> aWidgets;
671 if (!module()->createWidgets(theOperation, aWidgets)) {
672 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
673 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), myModuleConnector);
674 aFactory.createWidget(myPropertyPanel->contentWidget());
675 aWidgets = aFactory.getModelWidgets();
678 // check compatibility of feature and widgets
679 FeaturePtr aFeature = aFOperation->feature();
680 std::string aFeatureKind = aFeature->getKind();
681 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
682 if (aWidget->usesAttribute()) {
683 if (!aWidget->attributeID().empty() && !aFeature->attribute(aWidget->attributeID()).get()) {
684 std::string anErrorMsg = "The feature '%1' has no attribute '%2' used by widget '%3'.";
685 Events_InfoMessage("XGUI_Workshop", anErrorMsg)
686 .arg(aFeatureKind).arg(aWidget->attributeID())
687 .arg(aWidget->metaObject()->className()).send();
688 myPropertyPanel->cleanContent();
693 // for performance purpose, flush should be done after all controls are filled
694 bool isUpdateFlushed = false;
695 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
696 bool isStoreValue = !aFOperation->isEditOperation() &&
697 !aWidget->getDefaultValue().empty() &&
698 !aWidget->isComputedDefault();
699 aWidget->setFeature(aFeature, isStoreValue, isUpdateFlushed);
701 aWidget->restoreValue();
702 aWidget->enableFocusProcessing();
704 // update visible state of Preview button
705 std::shared_ptr<Config_FeatureMessage> aFeatureInfo;
707 aFeatureInfo = mySalomeConnector->featureInfo(aFeatureKind.c_str());
709 AppElements_MainMenu* aMenuBar = mainWindow()->menuObject();
710 AppElements_Command* aCommand = aMenuBar->feature(aFeatureKind.c_str());
712 aFeatureInfo = aCommand->featureMessage();
714 bool anIsAutoPreview = true;
715 if (aFeatureInfo.get()) {
716 anIsAutoPreview = aFeatureInfo->isAutoPreview();
717 theOperation->setHelpFileName(aFeatureInfo->helpFileName().c_str());
719 std::string aXmlCfg, aDescription;
720 module()->getXMLRepresentation(aFeatureKind, aXmlCfg, aDescription);
721 ModuleBase_WidgetFactory aFactory(aXmlCfg, moduleConnector());
722 anIsAutoPreview = aFactory.widgetAPI()->getBooleanAttribute(FEATURE_AUTO_PREVIEW, true);
725 if (!anIsAutoPreview) {
726 myPropertyPanel->findButton(PROP_PANEL_PREVIEW)->setVisible(true);
727 // send signal about preview should not be computed automatically, click on preview
728 // button should initiate it
729 std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
730 new Events_Message(Events_Loop::eventByName(EVENT_PREVIEW_BLOCKED)));
731 Events_Loop::loop()->send(aMsg);
733 // if update happens after preview is blocked, it does nothing when blocked
734 // it improves performance for valid objects on feature start
735 ModuleBase_Tools::flushUpdated(aFeature);
737 myPropertyPanel->setModelWidgets(aWidgets);
738 aFOperation->setPropertyPanel(myPropertyPanel);
740 myModule->propertyPanelDefined(theOperation);
742 #ifndef DEBUG_FEATURE_NAME
743 myPropertyPanel->setWindowTitle(ModuleBase_Tools::translate("workshop",
744 theOperation->getDescription()->description().toStdString()));
746 std::string aFeatureName = aFeature->name();
747 myPropertyPanel->setWindowTitle(QString("%1: %2")
748 .arg(translate(theOperation->getDescription()->description()))
749 .arg(translate(aFeatureName.c_str())));
752 myErrorMgr->setPropertyPanel(myPropertyPanel);
755 //******************************************************
756 void XGUI_Workshop::connectToPropertyPanel(const bool isToConnect)
758 XGUI_PropertyPanel* aPropertyPanel = propertyPanel();
759 if (aPropertyPanel) {
760 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
761 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
762 myModule->connectToPropertyPanel(aWidget, isToConnect);
764 connect(aWidget, SIGNAL(valueStateChanged(int)), this, SLOT(onWidgetStateChanged(int)));
765 connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
766 connect(aWidget, SIGNAL(objectUpdated()), this, SLOT(onWidgetObjectUpdated()));
769 disconnect(aWidget, SIGNAL(valueStateChanged(int)), this, SLOT(onWidgetStateChanged(int)));
770 disconnect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
771 disconnect(aWidget, SIGNAL(objectUpdated()), this, SLOT(onWidgetObjectUpdated()));
777 //******************************************************
778 void XGUI_Workshop::onOperationResumed(ModuleBase_Operation* theOperation)
780 setGrantedFeatures(theOperation);
782 if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
783 fillPropertyPanel(theOperation);
784 connectToPropertyPanel(true);
785 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
788 myPropertyPanel->updateApplyPlusButton(aFOperation->feature());
790 myPropertyPanel->updateApplyPlusButton(FeaturePtr());
792 updateCommandStatus();
794 myModule->operationResumed(theOperation);
797 //******************************************************
798 void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
800 updateCommandStatus();
802 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
807 ModuleBase_ISelection* aSel = mySelector->selection();
808 QObjectPtrList aObj = aSel->selectedPresentations();
809 //!< No need for property panel
810 hidePanel(myPropertyPanel);
811 myPropertyPanel->cleanContent();
813 connectToPropertyPanel(false);
814 myModule->operationStopped(aFOperation);
816 // the deactivated objects of the current operation should be activated back.
817 // They were deactivated on operation start or an object redisplay
818 QObjectPtrList anObjects;
819 FeaturePtr aFeature = aFOperation->feature();
820 if (aFeature.get()) { // feature may be not created (plugin load fail)
821 if (myDisplayer->isVisible(aFeature) && !selectionActivate()->isActive(aFeature))
822 anObjects.append(aFeature);
823 std::list<ResultPtr> aResults;
824 ModelAPI_Tools::allResults(aFeature, aResults);
825 std::list<ResultPtr>::const_iterator aIt;
826 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
827 ResultPtr anObject = *aIt;
828 if (myDisplayer->isVisible(anObject) && !selectionActivate()->isActive(anObject)) {
829 anObjects.append(anObject);
833 activateObjectsSelection(anObjects);
836 //******************************************************
837 void XGUI_Workshop::onOperationCommitted(ModuleBase_Operation* theOperation)
839 myModule->operationCommitted(theOperation);
842 //******************************************************
843 void XGUI_Workshop::onOperationAborted(ModuleBase_Operation* theOperation)
845 myModule->operationAborted(theOperation);
848 //******************************************************
849 void XGUI_Workshop::setGrantedFeatures(ModuleBase_Operation* theOperation)
851 ModuleBase_OperationFeature* aFOperation =
852 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
856 QStringList aGrantedIds;
857 if (isSalomeMode()) {
858 const std::shared_ptr<Config_FeatureMessage>& anInfo =
859 mySalomeConnector->featureInfo(theOperation->id());
861 aGrantedIds = QString::fromStdString(anInfo->nestedFeatures())
862 .split(" ", QString::SkipEmptyParts);
865 aGrantedIds = myActionsMgr->nestedCommands(theOperation->id());
867 ModuleBase_IModule* aModule = module();
869 aModule->grantedOperationIds(theOperation, aGrantedIds);
871 aFOperation->setGrantedOperationIds(aGrantedIds);
874 //******************************************************
875 void XGUI_Workshop::saveDocument(const QString& theName, std::list<std::string>& theFileNames)
877 QApplication::restoreOverrideCursor();
878 SessionPtr aMgr = ModelAPI_Session::get();
880 std::list<DocumentPtr> aDocList = aMgr->allOpenedDocuments();
881 std::list<DocumentPtr>::const_iterator aIt;
882 for (aIt = aDocList.cbegin(); aIt != aDocList.cend(); aIt++) {
883 std::list<bool> aState = myObjectBrowser->getStateForDoc(*aIt);
884 (*aIt)->storeNodesState(aState);
887 aMgr->save(theName.toLatin1().constData(), theFileNames);
889 QApplication::restoreOverrideCursor();
892 //******************************************************
893 bool XGUI_Workshop::abortAllOperations()
895 return myOperationMgr->abortAllOperations();
898 //******************************************************
899 void XGUI_Workshop::operationStarted(ModuleBase_Operation* theOperation)
901 setGrantedFeatures(theOperation);
902 if (!theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
903 updateCommandStatus();
906 myModule->operationStarted(theOperation);
910 //******************************************************
911 void XGUI_Workshop::onOpen()
913 if(!abortAllOperations())
915 //save current file before close if modified
916 SessionPtr aSession = ModelAPI_Session::get();
917 if (aSession->isModified()) {
918 int anAnswer = QMessageBox::question(
919 desktop(), tr("Save current file"),
920 tr("The document is modified, save before opening another?"),
921 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
922 if (anAnswer == QMessageBox::Save) {
924 } else if (anAnswer == QMessageBox::Cancel) {
927 myCurrentFile = QString();
930 //show file dialog, check if readable and open
931 qreal aRatio = ModuleBase_Tools::currentPixelRatio();
932 // If the ratio is > 1 (HD screen) then QT has a bug in
933 // displaying of system open file dialog (too small)
934 QString aFile = QFileDialog::getOpenFileName(desktop(), tr("Open file"), QString(), MyFilter,
935 Q_NULLPTR, ((aRatio > 1)? QFileDialog::DontUseNativeDialog : QFileDialog::Options()));
940 //******************************************************
941 void XGUI_Workshop::openFile(const QString& theDirectory)
943 myCurrentFile = theDirectory;
944 if (myCurrentFile.isEmpty())
947 QFileInfo aFileInfo(myCurrentFile);
948 if (!aFileInfo.exists() || !aFileInfo.isReadable()) {
949 QMessageBox::critical(desktop(), tr("Warning"), tr("Unable to open the file."));
950 myCurrentFile = QString();
954 QApplication::setOverrideCursor(Qt::WaitCursor);
955 module()->closeDocument();
956 SessionPtr aSession = ModelAPI_Session::get();
957 aSession->closeAll();
960 if (!XGUI_CompressFiles::uncompress(myCurrentFile, myTmpDir.path()))
963 aSession->load(myTmpDir.path().toLatin1().constData());
964 myObjectBrowser->rebuildDataTree();
966 // Open first level of data tree
967 DocumentPtr aRootDoc = aSession->moduleDocument();
968 std::list<bool> aStates;
969 aRootDoc->restoreNodesState(aStates);
970 myObjectBrowser->setStateForDoc(aRootDoc, aStates);
972 updateCommandStatus();
974 myMainWindow->setCurrentDir(myCurrentFile, true);
978 bool aNewPart = Config_PropManager::boolean("Plugins", "create_part_by_start");
981 DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
982 int aSize = aRootDoc->size(ModelAPI_ResultPart::group());
984 ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), 0);
985 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
992 QApplication::restoreOverrideCursor();
995 //******************************************************
996 void XGUI_Workshop::onNew()
998 QApplication::setOverrideCursor(Qt::WaitCursor);
999 if (objectBrowser() == 0) {
1000 createDockWidgets();
1001 mySelector->connectViewers();
1003 myViewerProxy->connectToViewer();
1004 showObjectBrowser();
1006 myMainWindow->showPythonConsole();
1007 QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
1008 aWnd->showMaximized();
1009 updateCommandStatus();
1011 myContextMenuMgr->connectViewer();
1012 QApplication::restoreOverrideCursor();
1016 //******************************************************
1017 void XGUI_Workshop::onExit()
1019 SessionPtr aMgr = ModelAPI_Session::get();
1020 if (aMgr->isModified()) {
1021 int anAnswer = QMessageBox::question(
1022 myMainWindow, tr("Save current file"), tr("The document is modified, save before exit?"),
1023 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
1024 if (anAnswer == QMessageBox::Save) {
1025 bool saved = onSave();
1029 } else if (anAnswer == QMessageBox::Cancel) {
1036 //******************************************************
1037 void XGUI_Workshop::onPreferences()
1039 ModuleBase_Prefs aModif;
1040 ModuleBase_Preferences::editPreferences(aModif);
1041 if (aModif.size() > 0) {
1043 foreach (ModuleBase_Pref aPref, aModif)
1045 aSection = aPref.first;
1046 if (aSection == ModuleBase_Preferences::VIEWER_SECTION) {
1047 myMainWindow->viewer()->updateFromResources();
1048 } else if (aSection == ModuleBase_Preferences::MENU_SECTION) {
1049 myMainWindow->menuObject()->updateFromResources();
1052 displayer()->redisplayObjects();
1057 //******************************************************
1058 void XGUI_Workshop::onTrihedronVisibilityChanged(bool theState)
1060 XGUI_Displayer* aDisplayer = displayer();
1062 aDisplayer->displayTrihedron(theState);
1063 aDisplayer->updateViewer();
1067 //******************************************************
1068 bool XGUI_Workshop::onSave()
1070 if(!myOperationMgr->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
1072 if (myCurrentFile.isEmpty()) {
1075 SessionPtr aMgr = ModelAPI_Session::get();
1076 if (aMgr->isAutoUpdateBlocked())
1077 aMgr->blockAutoUpdate(false);
1079 std::list<std::string> aFiles;
1080 // issue #2899: create a temporary directory, save and then remove it
1082 std::string aTmpDir = XGUI_Tools::getTmpDirByEnv("SALOME_TMP_DIR");
1084 std::string aTmpDir = XGUI_Tools::getTmpDirByEnv("");
1086 saveDocument(QString(aTmpDir.c_str()), aFiles);
1087 bool aResult = XGUI_CompressFiles::compress(myCurrentFile, aFiles);
1088 XGUI_Tools::removeTemporaryFiles(aTmpDir, aFiles);
1091 updateCommandStatus();
1093 myMainWindow->setModifiedState(false);
1099 //******************************************************
1100 bool XGUI_Workshop::onSaveAs()
1102 if(!myOperationMgr->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
1104 qreal aRatio = ModuleBase_Tools::currentPixelRatio();
1105 myCurrentFile = QFileDialog::getSaveFileName(desktop(), tr("Select name to save file..."),
1106 QString(), MyFilter2,
1107 Q_NULLPTR, ((aRatio > 1) ? QFileDialog::DontUseNativeDialog : QFileDialog::Options()));
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();
1231 myDisplayer->updateViewer();
1234 //******************************************************
1235 ModuleBase_IModule* XGUI_Workshop::loadModule(const QString& theModule)
1237 QString libName = QString::fromStdString(library(theModule.toStdString()));
1238 if (libName.isEmpty()) {
1239 qWarning(qPrintable(tr("Information about module \"%1\" doesn't exist.").arg(theModule)));
1244 CREATE_FUNC crtInst = 0;
1247 HINSTANCE modLib = ::LoadLibraryA(qPrintable(libName));
1251 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
1252 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
1253 QString aMsg((char*) &lpMsgBuf);
1254 err = QString("Failed to load %1. %2").arg(libName).arg(aMsg);
1255 ::LocalFree(lpMsgBuf);
1257 crtInst = (CREATE_FUNC) ::GetProcAddress(modLib, CREATE_MODULE);
1261 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
1262 | FORMAT_MESSAGE_IGNORE_INSERTS,
1263 0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
1264 QString aMsg((char*) &lpMsgBuf);
1265 err = QString("Failed to find %1 function. %2").arg( CREATE_MODULE).arg(aMsg);
1266 ::LocalFree(lpMsgBuf);
1270 void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY | RTLD_GLOBAL );
1272 err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
1274 crtInst = (CREATE_FUNC)dlsym( modLib, CREATE_MODULE );
1276 err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() );
1281 ModuleBase_IModule* aModule = crtInst ? crtInst(myModuleConnector) : 0;
1283 if (!err.isEmpty()) {
1285 Events_InfoMessage("XGUI_Workshop", err.toStdString()).send();
1287 qWarning(qPrintable(err));
1293 //******************************************************
1294 bool XGUI_Workshop::createModule()
1296 Config_ModuleReader aModuleReader;
1297 QString moduleName = QString::fromStdString(aModuleReader.getModuleName());
1298 myModule = loadModule(moduleName);
1302 //connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
1303 // myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
1304 //connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
1305 // myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
1307 myModule->createFeatures();
1309 salomeConnector()->createFeatureActions();
1311 //myActionsMgr->update();
1315 //******************************************************
1316 void XGUI_Workshop::updateCommandStatus()
1318 QList<QAction*> aCommands;
1320 aCommands = salomeConnector()->commandList();
1322 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
1323 foreach (AppElements_Command* aCmd, aMenuBar->features())
1324 aCommands.append(aCmd);
1326 SessionPtr aMgr = ModelAPI_Session::get();
1327 if (aMgr->hasModuleDocument()) {
1328 foreach(QAction* aCmd, aCommands) {
1329 QString aId = aCmd->data().toString();
1330 if (aId == "UNDO_CMD") {
1331 bool isActionEnabled = false;
1332 // if ultimate is true -> using result of operation only, or using OR combination
1333 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1334 if (anActiveWidget && anActiveWidget->canProcessAction(ActionUndo, isActionEnabled))
1335 aCmd->setEnabled(isActionEnabled);
1337 aCmd->setEnabled(myModule->canUndo());
1339 else if (aId == "REDO_CMD") {
1340 bool isActionEnabled = false;
1341 // if ultimate is true -> using result of operation only, or using OR combination
1342 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1343 if (anActiveWidget && anActiveWidget->canProcessAction(ActionRedo, isActionEnabled))
1344 aCmd->setEnabled(isActionEnabled);
1346 aCmd->setEnabled(myModule->canRedo());
1348 else if (aId == "AUTOCOMPUTE_CMD") {
1349 aCmd->setIcon(aMgr->isAutoUpdateBlocked() ?
1350 QIcon(":pictures/autoapply_stop.png") :
1351 QIcon(":pictures/autoapply_start.png"));
1354 // Enable all commands
1355 aCmd->setEnabled(true);
1359 foreach(QAction* aCmd, aCommands) {
1360 QString aId = aCmd->data().toString();
1361 if (aId == "NEW_CMD")
1362 aCmd->setEnabled(true);
1363 else if (aId == "EXIT_CMD")
1364 aCmd->setEnabled(true);
1366 aCmd->setEnabled(false);
1369 myActionsMgr->updateCommandsStatus();
1370 emit commandStatusUpdated();
1373 //******************************************************
1374 void XGUI_Workshop::updateHistory()
1376 bool isActionEnabled = false;
1377 ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
1378 QList<ActionInfo> aUndoRes;
1379 QList<ActionInfo> aRedoRes;
1380 if (anActiveWidget && anActiveWidget->canProcessAction(ActionUndo, isActionEnabled)) {
1381 aUndoRes = anActiveWidget->actionsList(ActionUndo);
1382 aRedoRes = anActiveWidget->actionsList(ActionRedo);
1384 std::list<std::string> aUndoList = ModelAPI_Session::get()->undoList();
1385 aUndoRes = processHistoryList(aUndoList);
1387 std::list<std::string> aRedoList = ModelAPI_Session::get()->redoList();
1388 aRedoRes = processHistoryList(aRedoList);
1390 emit updateUndoHistory(aUndoRes);
1391 emit updateRedoHistory(aRedoRes);
1394 //******************************************************
1395 QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
1397 QDockWidget* aObjDock = new QDockWidget(theParent);
1398 aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea |
1399 Qt::RightDockWidgetArea);
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 connect(myObjectBrowser, SIGNAL(sizeChanged()), SLOT(onDockSizeChanged()));
1410 myContextMenuMgr->connectObjectBrowser();
1414 //******************************************************
1416 * Creates dock widgets, places them in corresponding area
1417 * and tabifies if necessary.
1419 void XGUI_Workshop::createDockWidgets()
1421 QMainWindow* aDesktop = desktop();
1422 QDockWidget* aObjDock = createObjectBrowser(aDesktop);
1423 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
1424 myPropertyPanel = new XGUI_PropertyPanel(aDesktop, myOperationMgr);
1425 myActiveControlMgr->addSelector(new XGUI_PropertyPanelSelector(myPropertyPanel));
1427 myPropertyPanel->setupActions(myActionsMgr);
1428 myPropertyPanel->setAllowedAreas(Qt::LeftDockWidgetArea |
1429 Qt::RightDockWidgetArea);
1430 aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel);
1432 hidePanel(myPropertyPanel); ///<! Invisible by default
1434 myFacesPanel = new XGUI_FacesPanel(aDesktop, myModuleConnector);
1435 myActiveControlMgr->addSelector(new XGUI_FacesPanelSelector(myFacesPanel));
1436 myFacesPanel->setAllowedAreas(Qt::LeftDockWidgetArea |
1437 Qt::RightDockWidgetArea |
1438 Qt::BottomDockWidgetArea);
1439 connect(myFacesPanel, SIGNAL(closed()), myFacesPanel, SLOT(onClosed()));
1441 myInspectionPanel = new XGUI_InspectionPanel(aDesktop, mySelector);
1442 myInspectionPanel->setAllowedAreas(Qt::LeftDockWidgetArea |
1443 Qt::RightDockWidgetArea);
1444 aDesktop->addDockWidget(Qt::RightDockWidgetArea, myInspectionPanel);
1446 myInspectionPanel->hide();
1448 aDesktop->addDockWidget(
1450 Qt::RightDockWidgetArea,
1452 Qt::LeftDockWidgetArea,
1455 hidePanel(myFacesPanel); ///<! Invisible by default
1458 bool aShowOnTheRight = Config_PropManager::boolean("Plugins", "show_hide_faces");
1459 if (aShowOnTheRight) {
1460 aDesktop->addDockWidget(Qt::RightDockWidgetArea, myFacesPanel);
1461 showPanel(myFacesPanel);
1464 hideObjectBrowser();
1468 if (!aShowOnTheRight)
1471 aDesktop->tabifyDockWidget(myFacesPanel, aObjDock);
1476 #endif // HAVE_SALOME
1478 aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
1479 myPropertyPanel->installEventFilter(myOperationMgr);
1481 QAction* aOkAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept);
1482 connect(aOkAct, SIGNAL(triggered()), this, SLOT(onAcceptActionClicked()));
1484 QAction* aOkContAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptPlus);
1485 connect(aOkContAct, SIGNAL(triggered()), this, SLOT(onAcceptPlusActionClicked()));
1487 QAction* aCancelAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Abort);
1488 connect(aCancelAct, SIGNAL(triggered()), myOperationMgr, SLOT(onAbortOperation()));
1490 QAction* aPreviewAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Preview);
1491 connect(aPreviewAct, SIGNAL(triggered()), this, SLOT(onPreviewActionClicked()));
1493 QAction* aHelpAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Help);
1494 connect(aHelpAct, SIGNAL(triggered()), this, SLOT(onHelpActionClicked()));
1496 connect(myPropertyPanel, SIGNAL(keyReleased(QObject*, QKeyEvent*)),
1497 myOperationMgr, SLOT(onKeyReleased(QObject*, QKeyEvent*)));
1498 connect(myPropertyPanel, SIGNAL(enterClicked(QObject*)),
1499 myOperationMgr, SLOT(onProcessEnter(QObject*)));
1502 //******************************************************
1503 void XGUI_Workshop::showPanel(QDockWidget* theDockWidget)
1505 if (theDockWidget == myPropertyPanel) {
1506 QAction* aViewAct = myPropertyPanel->toggleViewAction();
1507 ///<! Restore ability to close panel from the window's menu
1508 aViewAct->setEnabled(true);
1510 theDockWidget->show();
1511 theDockWidget->raise();
1513 // The next code is necessary to made the property panel the active window
1514 // in order to operation manager could process key events of the panel.
1515 // otherwise they are ignored. It happens only if the same(activateWindow) is
1516 // not happened by property panel activation(e.g. resume operation of Sketch)
1517 ModuleBase_Tools::setFocus(theDockWidget, "XGUI_Workshop::showPanel()");
1520 //******************************************************
1521 void XGUI_Workshop::hidePanel(QDockWidget* theDockWidget)
1523 if (theDockWidget && theDockWidget == myPropertyPanel) {
1524 QAction* aViewAct = theDockWidget->toggleViewAction();
1525 ///<! Do not allow to show empty property panel
1526 aViewAct->setEnabled(false);
1528 theDockWidget->hide();
1530 // the property panel is active window of the desktop, when it is
1531 // hidden, it is undefined which window becomes active. By this reason
1532 // it is defined to perform the desktop as the active window.
1533 // in SALOME mode, work-stack made the PyConsole the active window,
1534 // set the focus on it. As a result, shortcuts of the application, like
1535 // are processed by this console. For example Undo actions.
1536 // It is possible that this code is to be moved to SHAPER package
1537 QMainWindow* aDesktop = desktop();
1538 ModuleBase_Tools::setFocus(aDesktop, "XGUI_Workshop::hidePanel()");
1541 //******************************************************
1542 void XGUI_Workshop::showObjectBrowser()
1544 if (!isSalomeMode()) {
1545 myObjectBrowser->parentWidget()->show();
1549 //******************************************************
1550 void XGUI_Workshop::hideObjectBrowser()
1552 if (!isSalomeMode())
1553 myObjectBrowser->parentWidget()->hide();
1556 //******************************************************
1557 void XGUI_Workshop::salomeViewerSelectionChanged()
1559 emit salomeViewerSelection();
1562 //**************************************************************
1563 ModuleBase_IViewer* XGUI_Workshop::salomeViewer() const
1565 return mySalomeConnector->viewer();
1568 //**************************************************************
1569 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
1571 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1572 if (theId == "DELETE_CMD")
1574 else if (theId == "CLEAN_HISTORY_CMD")
1576 else if (theId == "MOVE_CMD")
1578 else if (theId == "COLOR_CMD")
1579 changeColor(aObjects);
1580 else if (theId == "DEFLECTION_CMD")
1581 changeDeflection(aObjects);
1582 else if (theId == "TRANSPARENCY_CMD")
1583 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);
1641 } else if (theId == "SET_VIEW_NORMAL_CMD") {
1643 } else if (theId == "SET_VIEW_INVERTEDNORMAL_CMD") {
1644 setNormalView(true);
1647 else if (theId == "TINSPECTOR_VIEW") {
1648 Handle(CDF_Application) anApplication = CDF_Session::CurrentSession()->CurrentApplication();
1649 if (!anApplication.IsNull())
1651 if (!MyTCommunicator)
1653 MyTCommunicator = new TInspector_Communicator();
1655 NCollection_List<Handle(Standard_Transient)> aParameters;
1656 aParameters.Append(anApplication);
1657 Handle(AIS_InteractiveContext) aContext = viewer()->AISContext();
1658 if (!aContext.IsNull())
1659 aParameters.Append(aContext);
1661 #ifdef DEBUG_WITH_MESSAGE_REPORT
1662 Handle(Message_Report) aContextReport = aContext->GetReport();
1663 aContext->SetReportActive (Standard_True);
1664 aContextReport->SetLimit (1000);
1665 if (!aContextReport.IsNull())
1666 aParameters.Append(aContextReport);
1668 MyVCallBack = new VInspector_CallBack();
1669 myDisplayer->setCallBack(MyVCallBack);
1671 AppElements_Viewer* aViewer = mainWindow()->viewer();
1673 aViewer->setCallBack(MyVCallBack);
1675 aParameters.Append(MyVCallBack);
1677 MyTCommunicator->RegisterPlugin("TKDFBrowser");
1678 MyTCommunicator->RegisterPlugin("TKShapeView");
1679 MyTCommunicator->RegisterPlugin("TKVInspector");
1680 #ifdef DEBUG_WITH_MESSAGE_REPORT
1681 MyTCommunicator->RegisterPlugin("TKMessageView");
1683 //MyTCommunicator->RegisterPlugin("SMBrowser"); // custom plugin to view ModelAPI
1684 //MyTCommunicator->RegisterPlugin("TKSMBrowser"); // custom plugin to view ModelAPI
1686 MyTCommunicator->Init(aParameters);
1687 MyTCommunicator->Activate("TKSMBrowser"); // to have button in TInspector
1688 #ifndef DEBUG_WITH_MESSAGE_REPORT
1689 MyTCommunicator->Activate("TKVInspector"); // to have filled callback by model
1691 MyTCommunicator->Activate("TKDFBrowser");
1693 #ifdef DEBUG_WITH_MESSAGE_REPORT
1694 MyTCommunicator->Activate("TKMessageView"); // temporary
1695 MyTCommunicator->Activate("TKVInspector"); // to have filled callback by model
1698 MyTCommunicator->SetVisible(true);
1704 //**************************************************************
1705 void XGUI_Workshop::setViewerSelectionMode(int theMode)
1708 myViewerSelMode.clear();
1710 if (myViewerSelMode.contains(theMode))
1711 myViewerSelMode.removeAll(theMode);
1713 myViewerSelMode.append(theMode);
1715 selectionActivate()->updateSelectionModes();
1718 //**************************************************************
1719 void XGUI_Workshop::activateObjectsSelection(const QObjectPtrList& theList)
1722 module()->activeSelectionModes(aModes);
1723 if (aModes.isEmpty() && (myViewerSelMode.length() > 0))
1724 aModes.append(myViewerSelMode);
1725 selectionActivate()->activateObjects(aModes, theList);
1728 //**************************************************************
1729 bool XGUI_Workshop::prepareForDisplay(const std::set<ObjectPtr>& theObjects) const
1731 if (facesPanel()->isEmpty())
1734 // generate container of objects taking into account sub elments of compsolid
1735 std::set<ObjectPtr> anAllProcessedObjects;
1736 for (std::set<ObjectPtr>::const_iterator anObjectsIt = theObjects.begin();
1737 anObjectsIt != theObjects.end(); anObjectsIt++) {
1738 ObjectPtr anObject = *anObjectsIt;
1739 ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(anObject);
1740 if (aCompRes.get()) {
1741 std::list<ResultPtr> allRes;
1742 ModelAPI_Tools::allSubs(aCompRes, allRes);
1743 if (allRes.empty()) {
1744 anAllProcessedObjects.insert(anObject);
1746 for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
1747 ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aRes);
1748 if (aBody.get() && aBody->numberOfSubs() == 0)
1749 anAllProcessedObjects.insert(aBody);
1753 anAllProcessedObjects.insert(anObject);
1756 // find hidden objects in faces panel
1757 std::set<ObjectPtr> aHiddenObjects;
1758 QStringList aHiddenObjectNames;
1759 for (std::set<ObjectPtr>::const_iterator anObjectsIt = anAllProcessedObjects.begin();
1760 anObjectsIt != anAllProcessedObjects.end(); anObjectsIt++) {
1761 if (!facesPanel()->isObjectHiddenByPanel(*anObjectsIt))
1763 aHiddenObjects.insert(*anObjectsIt);
1764 aHiddenObjectNames.append((*anObjectsIt)->data()->name().c_str());
1766 if (aHiddenObjects.empty()) // in parameter objects there are no hidden objects in hide face
1769 int anAnswer = QMessageBox::question(
1770 desktop(), tr("Show object"),
1771 tr("'%1'\n are hidden by %2:\nRemove objects from the panel to be displayed?")
1772 .arg(aHiddenObjectNames.join(", ")).arg(facesPanel()->windowTitle()),
1773 QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
1775 bool aToBeDisplayed = anAnswer == QMessageBox::Yes;
1777 facesPanel()->restoreObjects(aHiddenObjects);
1779 return aToBeDisplayed;
1782 //**************************************************************
1783 void XGUI_Workshop::deleteObjects()
1785 ModuleBase_IModule* aModule = module();
1786 // allow the module to delete objects, do nothing if it has succeed
1787 if (aModule->deleteObjects()) {
1788 updateCommandStatus();
1792 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1793 if (!abortAllOperations())
1796 bool hasResult = false;
1797 bool hasFeature = false;
1798 bool hasParameter = false;
1799 bool hasCompositeOwner = false;
1800 bool hasResultInHistory = false;
1801 bool hasFolder = false;
1802 ModuleBase_Tools::checkObjects(anObjects, hasResult, hasFeature, hasParameter, hasCompositeOwner,
1803 hasResultInHistory, hasFolder);
1804 if (!(hasResult || hasFeature || hasParameter || hasFolder))
1807 // Remove from the list non-deletable objects: infinite constructions which are not in history
1808 bool notDelete = true;
1809 QObjectPtrList::iterator aIt;
1810 for (aIt = anObjects.begin(); aIt != anObjects.end(); aIt++) {
1811 ObjectPtr aObj = (*aIt);
1812 ResultConstructionPtr aConstr = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aObj);
1813 FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
1815 notDelete = (!aFeature->isInHistory()) && aConstr->isInfinite();
1817 anObjects.removeAll(aObj);
1823 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1824 std::set<FeaturePtr> aFeatures;
1825 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1826 ModelAPI_Tools::findAllReferences(aFeatures, aReferences);
1828 std::set<FolderPtr> aFolders;
1829 ModuleBase_Tools::convertToFolders(anObjects, aFolders);
1832 QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text() + " %1";
1833 aDescription = aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
1834 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, module());
1836 operationMgr()->startOperation(anOpAction);
1838 std::set<FeaturePtr> aFeatureRefsToDelete;
1839 if (ModuleBase_Tools::askToDelete(aFeatures, aReferences, desktop(), aFeatureRefsToDelete)) {
1840 // WORKAROUND, should be done before each object remove, if it presents in XGUI_DataModel tree
1841 // It is necessary to clear selection in order to avoid selection changed event during
1842 // deletion and negative consequences connected with processing of already deleted items
1843 mySelector->clearSelection();
1845 if (!aFeatureRefsToDelete.empty())
1846 aFeatures.insert(aFeatureRefsToDelete.begin(), aFeatureRefsToDelete.end());
1847 aDone = ModelAPI_Tools::removeFeatures(aFeatures, false);
1849 if (aFolders.size() > 0) {
1850 std::set<FolderPtr>::const_iterator anIt = aFolders.begin(),
1851 aLast = aFolders.end();
1852 for (; anIt != aLast; anIt++) {
1853 FolderPtr aFolder = *anIt;
1854 if (aFolder.get()) {
1855 DocumentPtr aDoc = aFolder->document();
1856 aDoc->removeFolder(aFolder);
1860 // remove results selected
1861 std::list<ResultPtr> aResults;
1862 for(QObjectPtrList::const_iterator anIt = anObjects.begin(); anIt != anObjects.end(); anIt++) {
1863 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(*anIt);
1864 if (aRes.get() && aRes->data()->isValid() && !aRes->data()->isDeleted() &&
1865 aRes->groupName() != ModelAPI_ResultGroup::group() && // don't remove groups and fields
1866 aRes->groupName() != ModelAPI_ResultField::group()) // because they are badly selected
1867 aResults.push_back(aRes);
1869 if (!aResults.empty()) {
1870 ModelAPI_Tools::removeResults(aResults);
1874 operationMgr()->commitOperation();
1876 operationMgr()->abortOperation(operationMgr()->currentOperation());
1878 myDisplayer->updateViewer();
1881 //**************************************************************
1882 void addRefsToFeature(const FeaturePtr& theFeature,
1883 const std::map<FeaturePtr, std::set<FeaturePtr> >& theMainList,
1884 std::set<FeaturePtr>& theReferences)
1886 //if (theReferences.find(theFeature) != theReferences.end())
1888 if (theMainList.find(theFeature) == theMainList.end())
1889 return; // this feature is not in the selection list, so exists without references to it
1890 std::set<FeaturePtr> aMainReferences = theMainList.at(theFeature);
1892 std::set<FeaturePtr>::const_iterator anIt = aMainReferences.begin(),
1893 aLast = aMainReferences.end();
1894 for (; anIt != aLast; anIt++) {
1895 FeaturePtr aRefFeature = *anIt;
1896 if (theReferences.find(aRefFeature) == theReferences.end())
1897 theReferences.insert(aRefFeature);
1898 addRefsToFeature(aRefFeature, theMainList, theReferences);
1902 //**************************************************************
1903 void XGUI_Workshop::cleanHistory()
1905 if (!abortAllOperations())
1908 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1909 std::set<FeaturePtr> aFeatures;
1910 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1912 #ifdef DEBUG_CLEAN_HISTORY
1914 std::set<FeaturePtr>::const_iterator aFIt;
1915 for (aFIt = aFeatures.begin(); aFIt != aFeatures.end(); ++aFIt) {
1916 FeaturePtr aFeature = ModelAPI_Feature::feature(*aFIt);
1917 anInfo.append(aFeature->name().c_str());
1919 QString anInfoStr = anInfo.join(";\t");
1920 qDebug(QString("cleanHistory for: [%1] - %2").
1921 arg(aFeatures.size()).arg(anInfoStr).toStdString().c_str());
1924 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1925 ModelAPI_Tools::findAllReferences(aFeatures, aReferences, true, false);
1926 // find for each object whether all reference values are in the map as key, that means that there
1927 // is no other reference in the model to this object, so it might be removed by cleaning history
1928 // sk_1(ext_1, vertex_1) + (sk_3, bool_1) - can't be deleted, dependency to bool_1
1929 // ext_1(bool_1, sk_3) - can't be deleted, dependency to bool_1
1931 // sk_2(ext_2) + (bool_1) - can't be deleted, dependency to bool_1
1932 // ext_2(bool_1) - can't be deleted, dependency to bool_1
1934 // Information: bool_1 is not selected
1935 std::set<FeaturePtr> anUnusedObjects;
1936 std::map<FeaturePtr, std::set<FeaturePtr> >::const_iterator aMainIt = aReferences.begin(),
1937 aMainLast = aReferences.end();
1938 for (; aMainIt != aMainLast; aMainIt++) {
1939 FeaturePtr aMainListFeature = aMainIt->first;
1940 std::set<FeaturePtr> aMainRefList = aMainIt->second;
1941 std::set<FeaturePtr>::const_iterator aRefIt = aMainRefList.begin(),
1942 aRefLast = aMainRefList.end();
1943 bool aFeatureOutOfTheList = false;
1944 for (; aRefIt != aRefLast && !aFeatureOutOfTheList; aRefIt++) {
1945 FeaturePtr aRefFeature = *aRefIt;
1946 aFeatureOutOfTheList = aReferences.find(aRefFeature) == aReferences.end();
1948 if (!aFeatureOutOfTheList)
1949 anUnusedObjects.insert(aMainListFeature);
1952 #ifdef DEBUG_CLEAN_HISTORY
1954 for (aFIt = anUnusedObjects.begin(); aFIt != anUnusedObjects.end(); ++aFIt) {
1955 FeaturePtr aFeature = *aFIt;
1956 anInfo.append(aFeature->name().c_str());
1958 qDebug(QString("unused objects: [%1] - %2").
1959 arg(anInfo.size()).arg(anInfo.join(";\t")).toStdString().c_str());
1962 // warn about the references remove, break the delete operation if the user chose it
1963 if (!anUnusedObjects.empty()) {
1965 foreach (const FeaturePtr& aFeature, anUnusedObjects) {
1966 aNames.append(aFeature->name().c_str());
1969 QString anUnusedNames = aNames.join(", ");
1971 QString anActionId = "CLEAN_HISTORY_CMD";
1972 QString aDescription = ModuleBase_Tools::translate("workshop",
1973 contextMenuMgr()->action(anActionId)->text().toStdString());
1975 QMessageBox aMessageBox(desktop());
1976 aMessageBox.setWindowTitle(aDescription);
1977 aMessageBox.setIcon(QMessageBox::Warning);
1978 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
1979 aMessageBox.setDefaultButton(QMessageBox::No);
1981 const char* aKeyStr = "Unused features are the following: "
1982 "%1.\nThese features will be deleted.\nWould you like to continue?";
1983 QString aText = QString(tr(aKeyStr).arg(anUnusedNames));
1984 aMessageBox.setText(aText);
1985 if (aMessageBox.exec() == QMessageBox::No)
1988 // 1. start operation
1989 aDescription += "by deleting of " +
1990 aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
1991 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, module());
1992 operationMgr()->startOperation(anOpAction);
1994 // WORKAROUND, should be done before each object remove, if it presents in XGUI_DataModel tree
1995 // It is necessary to clear selection in order to avoid selection changed event during
1996 // deletion and negative consequences connected with processing of already deleted items
1997 mySelector->clearSelection();
1999 std::set<FeaturePtr> anIgnoredFeatures;
2000 if (ModelAPI_Tools::removeFeatures(anUnusedObjects, true)) {
2001 operationMgr()->commitOperation();
2004 operationMgr()->abortOperation(operationMgr()->currentOperation());
2008 QString anActionId = "CLEAN_HISTORY_CMD";
2009 QString aDescription = contextMenuMgr()->action(anActionId)->text();
2011 QMessageBox aMessageBox(desktop());
2012 aMessageBox.setWindowTitle(aDescription);
2013 aMessageBox.setIcon(QMessageBox::Warning);
2014 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
2015 aMessageBox.setDefaultButton(QMessageBox::No);
2018 aMessageBox.setStandardButtons(QMessageBox::Ok);
2019 aMessageBox.setDefaultButton(QMessageBox::Ok);
2021 aText = QString(tr("All features are relevant, there is nothing to be deleted"));
2022 aMessageBox.setText(aText);
2024 if (aMessageBox.exec() == QMessageBox::No)
2029 //**************************************************************
2030 bool compareFeature(const FeaturePtr& theF1, const FeaturePtr& theF2) {
2031 DocumentPtr aDoc = theF1->document();
2032 return aDoc->index(theF1) < aDoc->index(theF2);
2034 void XGUI_Workshop::moveObjects()
2036 if (!abortAllOperations())
2039 SessionPtr aMgr = ModelAPI_Session::get();
2041 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
2042 // It is necessary to clear selection in order to avoid selection changed event during
2043 // moving and negative consequences connected with processing of already moved items
2044 mySelector->clearSelection();
2045 // check whether the object can be moved. There should not be parts which are not loaded
2046 std::set<FeaturePtr> aFeatures;
2047 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
2048 if (!XGUI_Tools::canRemoveOrRename(desktop(), aFeatures))
2051 QString anActionId = "MOVE_CMD";
2052 QString aDescription = contextMenuMgr()->action(anActionId)->text();
2053 aMgr->startOperation(aDescription.toStdString());
2055 // Sort features by index in document
2056 std::list<FeaturePtr> aFList(aFeatures.begin(), aFeatures.end());
2057 aFList.sort(compareFeature);
2059 DocumentPtr anActiveDocument = aMgr->activeDocument();
2060 FeaturePtr aCurrentFeature = anActiveDocument->currentFeature(true);
2061 std::list<FeaturePtr>::const_iterator anIt = aFList.begin(), aLast = aFList.end();
2062 for (; anIt != aLast; anIt++) {
2063 FeaturePtr aFeature = *anIt;
2064 if (!aFeature.get() || !myModule->canApplyAction(aFeature, anActionId))
2067 anActiveDocument->moveFeature(aFeature, aCurrentFeature);
2068 aCurrentFeature = anActiveDocument->currentFeature(true);
2070 aMgr->finishOperation();
2071 updateCommandStatus();
2074 //**************************************************************
2075 bool XGUI_Workshop::deleteFeatures(const QObjectPtrList& theObjects)
2077 std::set<FeaturePtr> aFeatures;
2078 ModuleBase_Tools::convertToFeatures(theObjects, aFeatures);
2080 return ModelAPI_Tools::removeFeaturesAndReferences(aFeatures);
2083 //******************************************************
2084 bool hasResults(QObjectPtrList theObjects, const std::set<std::string>& theTypes)
2086 bool isFoundResultType = false;
2087 foreach(ObjectPtr anObj, theObjects)
2089 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
2090 if (aResult.get() == NULL)
2093 isFoundResultType = theTypes.find(aResult->groupName()) != theTypes.end();
2094 if (isFoundResultType)
2097 return isFoundResultType;
2100 //**************************************************************
2101 // Returns the list of all features for theDocument and all features of
2102 // all nested parts.
2103 std::list<FeaturePtr> allFeatures(const DocumentPtr& theDocument)
2105 std::list<FeaturePtr> aResultList;
2106 std::list<FeaturePtr> anAllFeatures = theDocument->allFeatures();
2107 foreach (const FeaturePtr& aFeature, anAllFeatures) {
2108 // The order of appending features of the part and the part itself is important
2110 // Append features from a part feature
2111 std::list<ResultPtr> aResults;
2112 ModelAPI_Tools::allResults(aFeature, aResults);
2113 foreach (const ResultPtr& aResult, aResults) {
2114 ResultPartPtr aResultPart =
2115 std::dynamic_pointer_cast<ModelAPI_ResultPart>(aResult);
2116 if (aResultPart.get() && aResultPart->partDoc().get()) {
2118 std::list<FeaturePtr> anAllFeatures = allFeatures(aResultPart->partDoc());
2119 aResultList.insert(aResultList.end(), anAllFeatures.begin(), anAllFeatures.end());
2123 aResultList.push_back(aFeature);
2128 //**************************************************************
2129 // Returns the list of features placed between theObject and the current feature
2130 // in the same document. Excludes theObject, includes the current feature.
2131 std::list<FeaturePtr> toCurrentFeatures(const ObjectPtr& theObject)
2133 std::list<FeaturePtr> aResult;
2134 DocumentPtr aDocument = theObject->document();
2135 std::list<FeaturePtr> anAllFeatures = allFeatures(aDocument);
2136 // find the object iterator
2137 std::list<FeaturePtr>::iterator aObjectIt =
2138 std::find(anAllFeatures.begin(), anAllFeatures.end(), theObject);
2139 if (aObjectIt == anAllFeatures.end())
2141 // find the current feature iterator
2142 std::list<FeaturePtr>::iterator aCurrentIt =
2143 std::find(anAllFeatures.begin(), anAllFeatures.end(), aDocument->currentFeature(true));
2144 if (aCurrentIt == anAllFeatures.end())
2146 // check the right order
2147 if (std::distance(aObjectIt, anAllFeatures.end()) <=
2148 std::distance(aCurrentIt, anAllFeatures.end()))
2150 // exclude the object
2151 std::advance(aObjectIt, 1);
2152 // include the current feature
2153 std::advance(aCurrentIt, 1);
2154 return std::list<FeaturePtr>(aObjectIt, aCurrentIt);
2157 //******************************************************
2158 bool XGUI_Workshop::canMoveFeature()
2160 QString anActionId = "MOVE_CMD";
2162 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
2163 QObjectPtrList aValidatedObjects;
2164 foreach (ObjectPtr aObject, aObjects) {
2165 if (!myModule->canApplyAction(aObject, anActionId))
2167 // To be moved feature should be in active document
2168 if (aObject->document() != ModelAPI_Session::get()->activeDocument())
2170 aValidatedObjects.append(aObject);
2172 if (aValidatedObjects.size() != aObjects.size())
2173 aObjects = aValidatedObjects;
2175 bool aCanMove = !aObjects.empty();
2177 QObjectPtrList::const_iterator anIt = aObjects.begin(), aLast = aObjects.end();
2178 for (; anIt != aLast && aCanMove; anIt++) {
2179 ObjectPtr aObject = *anIt;
2180 if (!aObject.get() || !aObject->data().get() || !aObject->data()->isValid()) {
2184 FeaturePtr aFeat = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
2185 // only groups can be moved to the end for now (#2451)
2186 if (aFeat.get() && aFeat->getKind() != "Group") {
2191 // 1. Get features placed between selected and current in the document
2192 std::list<FeaturePtr> aFeaturesBetween = toCurrentFeatures(aObject);
2193 // if aFeaturesBetween is empty it means wrong order or aObject is the current feature
2194 if (aFeaturesBetween.empty())
2197 std::set<FeaturePtr> aPlacedFeatures(aFeaturesBetween.begin(), aFeaturesBetween.end());
2198 // 2. Get all reference features to the selected object in the document
2199 std::set<FeaturePtr> aRefFeatures;
2200 ModuleBase_Tools::refsToFeatureInFeatureDocument(aObject, aRefFeatures);
2202 if (aRefFeatures.empty())
2205 // 3. Find any placed features in all reference features
2206 std::set<FeaturePtr> aIntersectionFeatures;
2207 std::set_intersection(aRefFeatures.begin(), aRefFeatures.end(),
2208 aPlacedFeatures.begin(), aPlacedFeatures.end(),
2209 std::inserter(aIntersectionFeatures, aIntersectionFeatures.begin()));
2210 // 4. Return false if any reference feature is placed before current feature
2211 if (!aIntersectionFeatures.empty())
2219 //**************************************************************
2220 bool XGUI_Workshop::canBeShaded(const ObjectPtr& theObject) const
2222 bool aCanBeShaded = myDisplayer->canBeShaded(theObject);
2223 if (!aCanBeShaded) {
2224 ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theObject);
2225 if (aCompRes.get() != NULL) { // change colors for all sub-solids
2226 std::list<ResultPtr> allRes;
2227 ModelAPI_Tools::allSubs(aCompRes, allRes);
2228 std::list<ResultPtr>::iterator aRes = allRes.begin();
2229 for(; aRes != allRes.end() && !aCanBeShaded; aRes++) {
2230 aCanBeShaded = myDisplayer->canBeShaded(*aRes);
2234 return aCanBeShaded;
2237 //**************************************************************
2238 bool XGUI_Workshop::canChangeProperty(const QString& theActionName) const
2240 if (theActionName == "COLOR_CMD" ||
2241 theActionName == "DEFLECTION_CMD" ||
2242 theActionName == "TRANSPARENCY_CMD") {
2243 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
2245 std::set<std::string> aTypes;
2246 aTypes.insert(ModelAPI_ResultGroup::group());
2247 aTypes.insert(ModelAPI_ResultConstruction::group());
2248 aTypes.insert(ModelAPI_ResultBody::group());
2249 aTypes.insert(ModelAPI_ResultPart::group());
2251 return hasResults(aObjects, aTypes);
2256 //******************************************************
2257 void setColor(ResultPtr theResult, const std::vector<int>& theColor)
2259 if (!theResult.get())
2262 AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
2263 if (aColorAttr.get() != NULL) {
2264 if (!aColorAttr->size()) {
2265 aColorAttr->setSize(3);
2267 aColorAttr->setValue(0, theColor[0]);
2268 aColorAttr->setValue(1, theColor[1]);
2269 aColorAttr->setValue(2, theColor[2]);
2271 static const Events_ID kRedisplayEvent =
2272 Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
2273 ModelAPI_EventCreator::get()->sendUpdated(theResult, kRedisplayEvent);
2276 //**************************************************************
2277 void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
2280 AttributeIntArrayPtr aColorAttr;
2281 // 1. find the current color of the object. This is a color of AIS presentation
2282 // The objects are iterated until a first valid color is found
2283 std::vector<int> aColor;
2284 foreach(ObjectPtr anObject, theObjects) {
2285 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
2286 if (aResult.get()) {
2287 ModelAPI_Tools::getColor(aResult, aColor);
2290 // TODO: remove the obtaining a color from the AIS object
2291 // this does not happen never because:
2292 // 1. The color can be changed only on results
2293 // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
2294 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
2295 if (anAISObj.get()) {
2297 anAISObj->getColor(aColor[0], aColor[1], aColor[2]);
2300 if (!aColor.empty())
2303 if (aColor.size() != 3)
2306 if (!abortAllOperations())
2308 // 2. show the dialog to change the value
2309 XGUI_ColorDialog* aDlg = new XGUI_ColorDialog(desktop());
2310 aDlg->setColor(aColor);
2311 aDlg->move(QCursor::pos());
2312 bool isDone = aDlg->exec() == QDialog::Accepted;
2316 bool isRandomColor = aDlg->isRandomColor();
2318 // 3. abort the previous operation and start a new one
2319 SessionPtr aMgr = ModelAPI_Session::get();
2320 QString aDescription = contextMenuMgr()->action("COLOR_CMD")->text();
2321 aMgr->startOperation(aDescription.toStdString());
2323 // 4. set the value to all results
2324 std::vector<int> aColorResult = aDlg->getColor();
2325 foreach(ObjectPtr anObj, theObjects) {
2326 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
2327 if (aResult.get() != NULL) {
2328 ResultBodyPtr aBodyResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
2329 if (aBodyResult.get() != NULL) { // change colors for all sub-solids
2330 std::list<ResultPtr> allRes;
2331 ModelAPI_Tools::allSubs(aBodyResult, allRes);
2332 for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
2333 setColor(*aRes, !isRandomColor ? aColorResult : aDlg->getRandomColor());
2336 setColor(aResult, !isRandomColor ? aColorResult : aDlg->getRandomColor());
2339 aMgr->finishOperation();
2340 updateCommandStatus();
2343 //**************************************************************
2344 void setDeflection(ResultPtr theResult, const double theDeflection)
2346 if (!theResult.get())
2349 AttributeDoublePtr aDeflectionAttr = theResult->data()->real(ModelAPI_Result::DEFLECTION_ID());
2350 if (aDeflectionAttr.get() != NULL)
2351 aDeflectionAttr->setValue(theDeflection);
2352 static const Events_ID kRedisplayEvent =
2353 Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
2354 ModelAPI_EventCreator::get()->sendUpdated(theResult, kRedisplayEvent);
2357 //**************************************************************
2358 void setTransparency(ResultPtr theResult, double theTransparency)
2360 if (!theResult.get())
2363 AttributeDoublePtr anAttribute = theResult->data()->real(ModelAPI_Result::TRANSPARENCY_ID());
2364 if (anAttribute.get() != NULL)
2365 anAttribute->setValue(theTransparency);
2366 static const Events_ID kRedisplayEvent =
2367 Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
2368 ModelAPI_EventCreator::get()->sendUpdated(theResult, kRedisplayEvent);
2371 //**************************************************************
2372 void setTransparency(double theTransparency, const QObjectPtrList& theObjects)
2374 foreach(ObjectPtr anObj, theObjects) {
2375 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
2376 if (aResult.get() != NULL) {
2377 ResultBodyPtr aBodyResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
2378 if (aBodyResult.get() != NULL) { // change property for all sub-solids
2379 std::list<ResultPtr> allRes;
2380 ModelAPI_Tools::allSubs(aBodyResult, allRes);
2381 for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
2382 setTransparency(*aRes, theTransparency);
2385 setTransparency(aResult, theTransparency);
2390 //**************************************************************
2391 void XGUI_Workshop::changeDeflection(const QObjectPtrList& theObjects)
2393 AttributeDoublePtr aDoubleAttr;
2394 // 1. find the current property of the object. This is a property of AIS presentation
2395 // The objects are iterated until a first valid property is found
2396 double aDeflection = -1;
2397 foreach(ObjectPtr anObject, theObjects) {
2398 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
2399 if (aResult.get()) {
2400 aDeflection = ModelAPI_Tools::getDeflection(aResult);
2403 // TODO: remove the obtaining a property from the AIS object
2404 // this does not happen never because:
2405 // 1. The property can be changed only on results
2406 // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
2407 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
2408 if (anAISObj.get()) {
2409 aDeflection = anAISObj->getDeflection();
2412 if (aDeflection > 0)
2415 if (aDeflection < 0)
2418 if (!abortAllOperations())
2420 // 2. show the dialog to change the value
2421 XGUI_DeflectionDialog* aDlg = new XGUI_DeflectionDialog(desktop());
2422 aDlg->setDeflection(aDeflection);
2423 aDlg->move(QCursor::pos());
2424 bool isDone = aDlg->exec() == QDialog::Accepted;
2428 // 3. abort the previous operation and start a new one
2429 SessionPtr aMgr = ModelAPI_Session::get();
2430 QString aDescription = contextMenuMgr()->action("DEFLECTION_CMD")->text();
2431 aMgr->startOperation(aDescription.toStdString());
2433 // 4. set the value to all results
2434 aDeflection = aDlg->getDeflection();
2435 foreach(ObjectPtr anObj, theObjects) {
2436 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
2437 if (aResult.get() != NULL) {
2438 ResultBodyPtr aBodyResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
2439 if (aBodyResult.get() != NULL) { // change property for all sub-solids
2440 std::list<ResultPtr> allRes;
2441 ModelAPI_Tools::allSubs(aBodyResult, allRes);
2442 for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
2443 setDeflection(*aRes, aDeflection);
2446 setDeflection(aResult, aDeflection);
2449 aMgr->finishOperation();
2450 updateCommandStatus();
2453 //**************************************************************
2454 void XGUI_Workshop::changeTransparency(const QObjectPtrList& theObjects)
2456 AttributeDoublePtr aDoubleAttr;
2457 // 1. find the current property of the object. This is a property of AIS presentation
2458 // The objects are iterated until a first valid property is found
2459 double aCurrentValue = -1;
2460 foreach(ObjectPtr anObject, theObjects) {
2461 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
2462 if (aResult.get()) {
2463 aCurrentValue = ModelAPI_Tools::getTransparency(aResult);
2465 if (aCurrentValue > 0)
2468 if (aCurrentValue < 0)
2471 if (!abortAllOperations())
2474 // 2. show the dialog to change the value
2475 XGUI_PropertyDialog* aDlg = new XGUI_PropertyDialog(desktop());
2476 aDlg->setWindowTitle(tr("Transparency"));
2477 XGUI_TransparencyWidget* aTransparencyWidget = new XGUI_TransparencyWidget(aDlg);
2478 connect(aTransparencyWidget, SIGNAL(transparencyValueChanged()),
2479 this, SLOT(onTransparencyValueChanged()));
2480 aDlg->setContent(aTransparencyWidget);
2481 aTransparencyWidget->setValue(aCurrentValue);
2483 // 3. abort the previous operation and start a new one
2484 SessionPtr aMgr = ModelAPI_Session::get();
2485 QString aDescription = contextMenuMgr()->action("TRANSPARENCY_CMD")->text();
2486 aMgr->startOperation(aDescription.toStdString());
2488 if (aDlg->exec() == QDialog::Accepted) {
2489 // 4. set the value to all results
2490 aCurrentValue = aTransparencyWidget->getValue();
2491 setTransparency(aCurrentValue, theObjects);
2492 aMgr->finishOperation();
2494 aMgr->abortOperation();
2495 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2498 updateCommandStatus();
2501 //**************************************************************
2502 void XGUI_Workshop::onTransparencyValueChanged()
2504 XGUI_TransparencyWidget* aTransparencyWidget = (XGUI_TransparencyWidget*)sender();
2505 if (!aTransparencyWidget)
2508 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
2509 setTransparency(aTransparencyWidget->getValue(), anObjects);
2510 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2514 //******************************************************
2515 void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible)
2518 std::set<ObjectPtr> anObjects;
2519 foreach (ObjectPtr aObj, theList) {
2520 anObjects.insert(aObj);
2522 if (!prepareForDisplay(anObjects))
2526 foreach (ObjectPtr aObj, theList) {
2527 aObj->setDisplayed(isVisible);
2529 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2530 myObjectBrowser->updateAllIndexes();
2532 updateColorScaleVisibility();
2533 displayer()->updateViewer();
2536 //**************************************************************
2537 void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList)
2539 QObjectPtrList aSrcList = theList;
2540 // Hide all displayed objects
2541 QObjectPtrList aList = myDisplayer->displayedObjects();
2542 foreach (ObjectPtr aObj, aList) {
2543 if ((!aSrcList.contains(aObj)) && (module()->canEraseObject(aObj)))
2544 aObj->setDisplayed(false);
2546 aSrcList.removeAll(aObj);
2548 //Do not use eraseAll if you didn't send Redisplay event:
2549 //all objects are erased from viewer, but considered as displayed in displayer
2550 // Problem in bug 2218
2551 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2553 //issue #2159 Hide all incomplete behavior
2554 viewer()->eraseAll();
2557 std::set<ObjectPtr> anObjects;
2558 foreach (ObjectPtr aObj, aSrcList) {
2559 anObjects.insert(aObj);
2562 if (!prepareForDisplay(anObjects))
2565 // Show only objects from the list
2566 foreach (ObjectPtr aObj, aSrcList) {
2567 aObj->setDisplayed(true);
2569 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2571 // Necessary for update icons in ObjectBrowser on Linux
2572 myObjectBrowser->updateAllIndexes();
2573 updateColorScaleVisibility();
2574 displayer()->updateViewer();
2578 //**************************************************************
2579 void XGUI_Workshop::updateColorScaleVisibility()
2581 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
2582 viewer()->setColorScaleShown(false);
2583 if (aObjects.size() == 1) {
2584 FieldStepPtr aStep =
2585 std::dynamic_pointer_cast<ModelAPI_ResultField::ModelAPI_FieldStep>(aObjects.first());
2586 if (aStep.get() && myDisplayer->isVisible(aStep)) {
2587 AISObjectPtr aAisPtr = myDisplayer->getAISObject(aStep);
2588 Handle(AIS_InteractiveObject) aIO = aAisPtr->impl<Handle(AIS_InteractiveObject)>();
2589 ModuleBase_IStepPrs* aPrs = dynamic_cast<ModuleBase_IStepPrs*>(aIO.get());
2591 ModelAPI_AttributeTables::ValueType aType = aPrs->dataType();
2592 if ((aType == ModelAPI_AttributeTables::DOUBLE) ||
2593 (aType == ModelAPI_AttributeTables::INTEGER) ||
2594 (aType == ModelAPI_AttributeTables::BOOLEAN)) {
2595 myViewerProxy->setupColorScale();
2596 if (aType == ModelAPI_AttributeTables::BOOLEAN) {
2597 myViewerProxy->setColorScaleIntervals(2);
2598 myViewerProxy->setColorScaleRange(0., 1.);
2602 aPrs->dataRange(aMin, aMax);
2603 myViewerProxy->setColorScaleRange(aMin, aMax);
2605 myViewerProxy->setColorScaleTitle(aStep->name().c_str());
2606 myViewerProxy->setColorScaleShown(true);
2614 //**************************************************************
2615 void XGUI_Workshop::setNormalView(bool toInvert)
2617 QList<ModuleBase_ViewerPrsPtr> aPrsList =
2618 mySelector->selection()->getSelected(ModuleBase_ISelection::Viewer);
2619 GeomShapePtr aPlanarFace;
2620 foreach(ModuleBase_ViewerPrsPtr aPrs, aPrsList) {
2621 GeomShapePtr aShape = aPrs->shape();
2622 if (aShape.get() && aShape->isPlanar()) {
2623 aPlanarFace = aShape;
2627 if (aPlanarFace.get()) {
2628 GeomFacePtr aFace(new GeomAPI_Face(aPlanarFace));
2629 GeomPlanePtr aPlane = aFace->getPlane();
2630 GeomDirPtr aNormal = aPlane->direction();
2633 GeomPointPtr aPos = aPlane->location();
2635 double aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
2636 aFace->computeSize(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
2638 Handle(V3d_View) aView = myViewerProxy->activeView();
2639 double aScale = aView->Scale();
2640 aView->SetAt(aPos->x(), aPos->y(), aPos->z());
2641 aView->SetProj(aNormal->x(), aNormal->y(), aNormal->z());
2643 aBox.Update(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
2644 aView->FitAll(aBox);
2648 //**************************************************************
2649 void XGUI_Workshop::registerValidators() const
2651 SessionPtr aMgr = ModelAPI_Session::get();
2652 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
2655 //**************************************************************
2656 void XGUI_Workshop::displayDocumentResults(DocumentPtr theDoc)
2660 displayGroupResults(theDoc, ModelAPI_ResultConstruction::group());
2661 displayGroupResults(theDoc, ModelAPI_ResultBody::group());
2664 //**************************************************************
2665 void XGUI_Workshop::displayGroupResults(DocumentPtr theDoc, std::string theGroup)
2667 for (int i = 0; i < theDoc->size(theGroup); i++)
2668 theDoc->object(theGroup, i)->setDisplayed(true);
2669 //displayObject(theDoc->object(theGroup, i));
2670 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2673 //**************************************************************
2674 void XGUI_Workshop::setDisplayMode(const QObjectPtrList& theList, int theMode)
2676 foreach(ObjectPtr anObj, theList) {
2677 myDisplayer->setDisplayMode(anObj, (XGUI_Displayer::DisplayMode)theMode, false);
2679 ResultBodyPtr aBodyResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(anObj);
2680 if (aBodyResult.get() != NULL) { // change display mode for all sub-solids
2681 std::list<ResultPtr> allRes;
2682 ModelAPI_Tools::allSubs(aBodyResult, allRes);
2683 for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
2684 myDisplayer->setDisplayMode(*aRes, (XGUI_Displayer::DisplayMode)theMode, false);
2688 if (theList.size() > 0)
2689 myDisplayer->updateViewer();
2692 //**************************************************************
2693 void XGUI_Workshop::closeDocument()
2695 ModuleBase_Operation* anOperation = operationMgr()->currentOperation();
2696 while (anOperation) {
2697 anOperation->abort();
2698 anOperation = operationMgr()->currentOperation();
2700 //myDisplayer->closeLocalContexts();
2701 myDisplayer->eraseAll();
2702 objectBrowser()->clearContent();
2704 module()->closeDocument();
2705 // we need to clear viewer (with created filters) to do not have problems in 2nd SALOME study
2706 module()->clearViewer();
2709 // data model need not process the document's signals about objects modifications as
2710 // the document is closed
2711 //bool isBlocked = objectBrowser()->dataModel()->blockEventsProcessing(true);
2713 SessionPtr aMgr = ModelAPI_Session::get();
2716 //objectBrowser()->dataModel()->blockEventsProcessing(isBlocked);
2719 //******************************************************
2720 void XGUI_Workshop::addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot)
2722 XGUI_HistoryMenu* aMenu = NULL;
2723 if (isSalomeMode()) {
2724 QAction* anAction = qobject_cast<QAction*>(theObject);
2727 aMenu = new XGUI_HistoryMenu(anAction);
2729 QToolButton* aButton = qobject_cast<QToolButton*>(theObject);
2730 aMenu = new XGUI_HistoryMenu(aButton);
2732 connect(this, theSignal, aMenu, SLOT(setHistory(const QList<ActionInfo>&)));
2733 connect(aMenu, SIGNAL(actionSelected(int)), this, theSlot);
2736 //******************************************************
2737 QList<ActionInfo> XGUI_Workshop::processHistoryList(const std::list<std::string>& theList) const
2739 QList<ActionInfo> aResult;
2740 std::list<std::string>::const_iterator it = theList.cbegin();
2741 for (; it != theList.cend(); it++) {
2742 QString anId = QString::fromStdString(*it);
2743 bool isEditing = anId.endsWith(ModuleBase_OperationFeature::EditSuffix());
2745 anId.chop(ModuleBase_OperationFeature::EditSuffix().size());
2748 QAction* aContextMenuAct = myContextMenuMgr->actionByName(anId);
2749 if (aContextMenuAct) {
2750 anInfo.initFrom(aContextMenuAct);
2752 anInfo = myActionsMgr->actionInfoById(anId);
2755 anInfo.text = anInfo.text.prepend("Modify ");
2762 //******************************************************
2763 void XGUI_Workshop::setStatusBarMessage(const QString& theMessage)
2766 salomeConnector()->putInfo(theMessage, -1);
2768 myMainWindow->putInfo(theMessage, -1);
2773 //******************************************************
2774 void XGUI_Workshop::synchronizeViewer()
2776 SessionPtr aMgr = ModelAPI_Session::get();
2777 QList<DocumentPtr> aDocs;
2778 aDocs.append(aMgr->activeDocument());
2779 aDocs.append(aMgr->moduleDocument());
2781 foreach(DocumentPtr aDoc, aDocs) {
2782 synchronizeGroupInViewer(aDoc, ModelAPI_ResultConstruction::group(), false);
2783 synchronizeGroupInViewer(aDoc, ModelAPI_ResultBody::group(), false);
2784 synchronizeGroupInViewer(aDoc, ModelAPI_ResultPart::group(), false);
2785 synchronizeGroupInViewer(aDoc, ModelAPI_ResultGroup::group(), false);
2789 //******************************************************
2790 void XGUI_Workshop::synchronizeGroupInViewer(const DocumentPtr& theDoc,
2791 const std::string& theGroup,
2792 bool theUpdateViewer)
2795 int aSize = theDoc->size(theGroup);
2796 for (int i = 0; i < aSize; i++) {
2797 aObj = theDoc->object(theGroup, i);
2798 if (aObj->isDisplayed()) {
2799 // Hide the presentation with an empty shape. But isDisplayed state of the object should not
2800 // be changed to the object becomes visible when the shape becomes not empty
2801 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
2802 if (aRes.get() && (!aRes->shape().get() || aRes->shape()->isNull()))
2804 ResultBodyPtr aResBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aObj);
2806 synchronizeResultTree(aResBody, false);
2808 myDisplayer->display(aObj, false);
2811 if (theUpdateViewer)
2812 myDisplayer->updateViewer();
2815 void XGUI_Workshop::synchronizeResultTree(const ResultBodyPtr& theRes, bool theUpdateViewer)
2817 if (theRes->numberOfSubs() > 0)
2818 for (int i = 0; i < theRes->numberOfSubs(); i++) {
2819 ResultBodyPtr aRes = theRes->subResult(i);
2821 synchronizeResultTree(aRes, theUpdateViewer);
2824 if (theRes->isDisplayed())
2825 myDisplayer->display(theRes, theUpdateViewer);
2827 myDisplayer->erase(theRes, theUpdateViewer);
2832 //******************************************************
2833 void XGUI_Workshop::highlightResults(const QObjectPtrList& theObjects)
2835 FeaturePtr aFeature;
2836 QObjectPtrList aSelList = theObjects;
2837 QObjectPtrList aNewSel;
2838 bool aHasHidden = false;
2839 foreach(ObjectPtr aObj, theObjects) {
2840 aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
2841 if (aFeature.get()) {
2842 std::list<ResultPtr> aResults;
2843 ModelAPI_Tools::allResults(aFeature, aResults);
2844 std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aIt;
2845 for(aIt = aResults.cbegin(); aIt != aResults.cend(); aIt++) {
2846 aHasHidden |= (*aIt)->isConcealed();
2847 aSelList.append(*aIt);
2848 aNewSel.append(*aIt);
2852 if (aSelList.count() > theObjects.count()) {
2853 // if something was found
2854 objectBrowser()->setObjectsSelected(aSelList);
2855 objectBrowser()->ensureVisible(aNewSel.first());
2858 QMessageBox::information(desktop(), tr("Find results"),
2859 tr("Results not found"), QMessageBox::Ok);
2862 //******************************************************
2863 void XGUI_Workshop::highlightFeature(const QObjectPtrList& theObjects)
2866 QObjectPtrList aSelList = theObjects;
2867 QObjectPtrList aNewSel;
2868 FeaturePtr aFeature;
2869 foreach(ObjectPtr aObj, theObjects) {
2870 aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
2871 if (aResult.get()) {
2872 aFeature = ModelAPI_Feature::feature(aResult);
2873 if (aFeature.get()) {
2874 aSelList.append(aFeature);
2875 aNewSel.append(aFeature);
2879 if (aSelList.count() > theObjects.count()) {
2880 // if something was found
2881 objectBrowser()->setObjectsSelected(aSelList);
2882 objectBrowser()->ensureVisible(aNewSel.first());
2886 void XGUI_Workshop::insertFeatureFolder()
2888 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
2889 if (aObjects.isEmpty())
2891 ObjectPtr aObj = aObjects.first();
2892 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
2893 if (aFeature.get() == NULL)
2895 SessionPtr aMgr = ModelAPI_Session::get();
2896 DocumentPtr aDoc = aMgr->activeDocument();
2898 QString aDescription = contextMenuMgr()->action("INSERT_FOLDER_CMD")->text();
2900 aMgr->startOperation(aDescription.toStdString());
2901 aDoc->addFolder(aFeature);
2902 aMgr->finishOperation();
2904 updateCommandStatus();
2908 void XGUI_Workshop::insertToFolder(bool isBefore)
2910 std::list<FeaturePtr> aFeatures = mySelector->getSelectedFeatures();
2911 if (aFeatures.empty())
2914 SessionPtr aMgr = ModelAPI_Session::get();
2915 DocumentPtr aDoc = aMgr->activeDocument();
2917 FolderPtr aFolder = isBefore? aDoc->findFolderAbove(aFeatures):
2918 aDoc->findFolderBelow(aFeatures);
2922 QString aDescription = contextMenuMgr()->action(
2923 isBefore ? "ADD_TO_FOLDER_BEFORE_CMD" : "ADD_TO_FOLDER_AFTER_CMD")->text();
2925 QMap<ObjectPtr, bool> aStates = myObjectBrowser->getFoldersState(aDoc);
2927 aMgr->startOperation(aDescription.toStdString());
2928 aDoc->moveToFolder(aFeatures, aFolder);
2929 aMgr->finishOperation();
2931 myObjectBrowser->setFoldersState(aStates);
2933 updateCommandStatus();
2936 void XGUI_Workshop::moveOutFolder(bool isBefore)
2938 std::list<FeaturePtr> aFeatures = mySelector->getSelectedFeatures();
2939 if (aFeatures.empty())
2942 SessionPtr aMgr = ModelAPI_Session::get();
2943 DocumentPtr aDoc = aMgr->activeDocument();
2945 QString aDescription = contextMenuMgr()->action(
2946 isBefore ? "ADD_OUT_FOLDER_BEFORE_CMD" : "ADD_OUT_FOLDER_AFTER_CMD")->text();
2948 QMap<ObjectPtr, bool> aStates = myObjectBrowser->getFoldersState(aDoc);
2950 aMgr->startOperation(aDescription.toStdString());
2951 aDoc->removeFromFolder(aFeatures, isBefore);
2952 aMgr->finishOperation();
2954 myObjectBrowser->setFoldersState(aStates);
2956 updateCommandStatus();
2959 void XGUI_Workshop::onAutoApply()
2961 SessionPtr aMgr = ModelAPI_Session::get();
2962 bool isBlocked = aMgr->isAutoUpdateBlocked();
2963 aMgr->blockAutoUpdate(!isBlocked);
2966 void XGUI_Workshop::updateAutoComputeState()
2968 SessionPtr aMgr = ModelAPI_Session::get();
2969 bool isComputeBlocked = aMgr->isAutoUpdateBlocked();
2971 // QAction* aUpdateCmd;
2972 // QList<QAction*> aCommands = mySalomeConnector->commandList();
2973 // foreach(QAction* aCmd, aCommands) {
2974 // if (aCmd->data().toString() == "AUTOCOMPUTE_CMD") {
2975 // aUpdateCmd = aCmd;
2979 // aUpdateCmd->setIcon(isComputeBlocked? QIcon(":pictures/autoapply_stop.png") :
2980 // QIcon(":pictures/autoapply_start.png"));
2982 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
2983 AppElements_Command* aUpdateCmd = aMenuBar->feature("AUTOCOMPUTE_CMD");
2984 aUpdateCmd->button()->setIcon(isComputeBlocked? QIcon(":pictures/autoapply_stop.png") :
2985 QIcon(":pictures/autoapply_start.png"));
2990 void XGUI_Workshop::clearTemporaryDir()
2992 QDir aDir(myTmpDir.path());
2993 if (!aDir.isEmpty()) {
2994 QStringList aEntries;
2995 aDir.entryList(aEntries);
2996 foreach(QString aFile, aEntries) {
3003 void XGUI_Workshop::onDockSizeChanged()
3005 QDockWidget* aDockWgt = dynamic_cast<QDockWidget*>(myObjectBrowser->parentWidget());
3006 int aObWidth = aDockWgt->size().width();
3007 if (myPropertyPanel->width() != aObWidth) {
3008 QList<QDockWidget*> aWgtList;
3009 aWgtList << myPropertyPanel << aDockWgt;
3010 QList<int> aSizeList;
3011 aSizeList << aObWidth << aObWidth;
3012 desktop()->resizeDocks(aWgtList, aSizeList, Qt::Horizontal);
3013 disconnect(myObjectBrowser, SIGNAL(sizeChanged()), this, SLOT(onDockSizeChanged()));
3017 void XGUI_Workshop::deactivateCurrentSelector()
3019 myActiveControlMgr->deactivateSelector(myActiveControlMgr->activeSelector());