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 constuctions 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);
1814 notDelete = (!aFeature->isInHistory()) && aConstr->isInfinite();
1816 anObjects.removeAll(aObj);
1821 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1822 std::set<FeaturePtr> aFeatures;
1823 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1824 ModelAPI_Tools::findAllReferences(aFeatures, aReferences);
1826 std::set<FolderPtr> aFolders;
1827 ModuleBase_Tools::convertToFolders(anObjects, aFolders);
1830 QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text() + " %1";
1831 aDescription = aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
1832 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, module());
1834 operationMgr()->startOperation(anOpAction);
1836 std::set<FeaturePtr> aFeatureRefsToDelete;
1837 if (ModuleBase_Tools::askToDelete(aFeatures, aReferences, desktop(), aFeatureRefsToDelete)) {
1838 // WORKAROUND, should be done before each object remove, if it presents in XGUI_DataModel tree
1839 // It is necessary to clear selection in order to avoid selection changed event during
1840 // deletion and negative consequences connected with processing of already deleted items
1841 mySelector->clearSelection();
1843 if (!aFeatureRefsToDelete.empty())
1844 aFeatures.insert(aFeatureRefsToDelete.begin(), aFeatureRefsToDelete.end());
1845 aDone = ModelAPI_Tools::removeFeatures(aFeatures, false);
1847 if (aFolders.size() > 0) {
1848 std::set<FolderPtr>::const_iterator anIt = aFolders.begin(),
1849 aLast = aFolders.end();
1850 for (; anIt != aLast; anIt++) {
1851 FolderPtr aFolder = *anIt;
1852 if (aFolder.get()) {
1853 DocumentPtr aDoc = aFolder->document();
1854 aDoc->removeFolder(aFolder);
1858 // remove results selected
1859 std::list<ResultPtr> aResults;
1860 for(QObjectPtrList::const_iterator anIt = anObjects.begin(); anIt != anObjects.end(); anIt++) {
1861 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(*anIt);
1862 if (aRes.get() && aRes->data()->isValid() && !aRes->data()->isDeleted() &&
1863 aRes->groupName() != ModelAPI_ResultGroup::group() && // don't remove groups and fields
1864 aRes->groupName() != ModelAPI_ResultField::group()) // because they are badly selected
1865 aResults.push_back(aRes);
1867 if (!aResults.empty()) {
1868 ModelAPI_Tools::removeResults(aResults);
1872 operationMgr()->commitOperation();
1874 operationMgr()->abortOperation(operationMgr()->currentOperation());
1876 myDisplayer->updateViewer();
1879 //**************************************************************
1880 void addRefsToFeature(const FeaturePtr& theFeature,
1881 const std::map<FeaturePtr, std::set<FeaturePtr> >& theMainList,
1882 std::set<FeaturePtr>& theReferences)
1884 //if (theReferences.find(theFeature) != theReferences.end())
1886 if (theMainList.find(theFeature) == theMainList.end())
1887 return; // this feature is not in the selection list, so exists without references to it
1888 std::set<FeaturePtr> aMainReferences = theMainList.at(theFeature);
1890 std::set<FeaturePtr>::const_iterator anIt = aMainReferences.begin(),
1891 aLast = aMainReferences.end();
1892 for (; anIt != aLast; anIt++) {
1893 FeaturePtr aRefFeature = *anIt;
1894 if (theReferences.find(aRefFeature) == theReferences.end())
1895 theReferences.insert(aRefFeature);
1896 addRefsToFeature(aRefFeature, theMainList, theReferences);
1900 //**************************************************************
1901 void XGUI_Workshop::cleanHistory()
1903 if (!abortAllOperations())
1906 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1907 std::set<FeaturePtr> aFeatures;
1908 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
1910 #ifdef DEBUG_CLEAN_HISTORY
1912 std::set<FeaturePtr>::const_iterator aFIt;
1913 for (aFIt = aFeatures.begin(); aFIt != aFeatures.end(); ++aFIt) {
1914 FeaturePtr aFeature = ModelAPI_Feature::feature(*aFIt);
1915 anInfo.append(aFeature->name().c_str());
1917 QString anInfoStr = anInfo.join(";\t");
1918 qDebug(QString("cleanHistory for: [%1] - %2").
1919 arg(aFeatures.size()).arg(anInfoStr).toStdString().c_str());
1922 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1923 ModelAPI_Tools::findAllReferences(aFeatures, aReferences, true, false);
1924 // find for each object whether all reference values are in the map as key, that means that there
1925 // is no other reference in the model to this object, so it might be removed by cleaning history
1926 // sk_1(ext_1, vertex_1) + (sk_3, bool_1) - can't be deleted, dependency to bool_1
1927 // ext_1(bool_1, sk_3) - can't be deleted, dependency to bool_1
1929 // sk_2(ext_2) + (bool_1) - can't be deleted, dependency to bool_1
1930 // ext_2(bool_1) - can't be deleted, dependency to bool_1
1932 // Information: bool_1 is not selected
1933 std::set<FeaturePtr> anUnusedObjects;
1934 std::map<FeaturePtr, std::set<FeaturePtr> >::const_iterator aMainIt = aReferences.begin(),
1935 aMainLast = aReferences.end();
1936 for (; aMainIt != aMainLast; aMainIt++) {
1937 FeaturePtr aMainListFeature = aMainIt->first;
1938 std::set<FeaturePtr> aMainRefList = aMainIt->second;
1939 std::set<FeaturePtr>::const_iterator aRefIt = aMainRefList.begin(),
1940 aRefLast = aMainRefList.end();
1941 bool aFeatureOutOfTheList = false;
1942 for (; aRefIt != aRefLast && !aFeatureOutOfTheList; aRefIt++) {
1943 FeaturePtr aRefFeature = *aRefIt;
1944 aFeatureOutOfTheList = aReferences.find(aRefFeature) == aReferences.end();
1946 if (!aFeatureOutOfTheList)
1947 anUnusedObjects.insert(aMainListFeature);
1950 #ifdef DEBUG_CLEAN_HISTORY
1952 for (aFIt = anUnusedObjects.begin(); aFIt != anUnusedObjects.end(); ++aFIt) {
1953 FeaturePtr aFeature = *aFIt;
1954 anInfo.append(aFeature->name().c_str());
1956 qDebug(QString("unused objects: [%1] - %2").
1957 arg(anInfo.size()).arg(anInfo.join(";\t")).toStdString().c_str());
1960 // warn about the references remove, break the delete operation if the user chose it
1961 if (!anUnusedObjects.empty()) {
1963 foreach (const FeaturePtr& aFeature, anUnusedObjects) {
1964 aNames.append(aFeature->name().c_str());
1967 QString anUnusedNames = aNames.join(", ");
1969 QString anActionId = "CLEAN_HISTORY_CMD";
1970 QString aDescription = ModuleBase_Tools::translate("workshop",
1971 contextMenuMgr()->action(anActionId)->text().toStdString());
1973 QMessageBox aMessageBox(desktop());
1974 aMessageBox.setWindowTitle(aDescription);
1975 aMessageBox.setIcon(QMessageBox::Warning);
1976 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
1977 aMessageBox.setDefaultButton(QMessageBox::No);
1979 const char* aKeyStr = "Unused features are the following: "
1980 "%1.\nThese features will be deleted.\nWould you like to continue?";
1981 QString aText = QString(tr(aKeyStr).arg(anUnusedNames));
1982 aMessageBox.setText(aText);
1983 if (aMessageBox.exec() == QMessageBox::No)
1986 // 1. start operation
1987 aDescription += "by deleting of " +
1988 aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", "));
1989 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, module());
1990 operationMgr()->startOperation(anOpAction);
1992 // WORKAROUND, should be done before each object remove, if it presents in XGUI_DataModel tree
1993 // It is necessary to clear selection in order to avoid selection changed event during
1994 // deletion and negative consequences connected with processing of already deleted items
1995 mySelector->clearSelection();
1997 std::set<FeaturePtr> anIgnoredFeatures;
1998 if (ModelAPI_Tools::removeFeatures(anUnusedObjects, true)) {
1999 operationMgr()->commitOperation();
2002 operationMgr()->abortOperation(operationMgr()->currentOperation());
2006 QString anActionId = "CLEAN_HISTORY_CMD";
2007 QString aDescription = contextMenuMgr()->action(anActionId)->text();
2009 QMessageBox aMessageBox(desktop());
2010 aMessageBox.setWindowTitle(aDescription);
2011 aMessageBox.setIcon(QMessageBox::Warning);
2012 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
2013 aMessageBox.setDefaultButton(QMessageBox::No);
2016 aMessageBox.setStandardButtons(QMessageBox::Ok);
2017 aMessageBox.setDefaultButton(QMessageBox::Ok);
2019 aText = QString(tr("All features are relevant, there is nothing to be deleted"));
2020 aMessageBox.setText(aText);
2022 if (aMessageBox.exec() == QMessageBox::No)
2027 //**************************************************************
2028 bool compareFeature(const FeaturePtr& theF1, const FeaturePtr& theF2) {
2029 DocumentPtr aDoc = theF1->document();
2030 return aDoc->index(theF1) < aDoc->index(theF2);
2032 void XGUI_Workshop::moveObjects()
2034 if (!abortAllOperations())
2037 SessionPtr aMgr = ModelAPI_Session::get();
2039 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
2040 // It is necessary to clear selection in order to avoid selection changed event during
2041 // moving and negative consequences connected with processing of already moved items
2042 mySelector->clearSelection();
2043 // check whether the object can be moved. There should not be parts which are not loaded
2044 std::set<FeaturePtr> aFeatures;
2045 ModuleBase_Tools::convertToFeatures(anObjects, aFeatures);
2046 if (!XGUI_Tools::canRemoveOrRename(desktop(), aFeatures))
2049 QString anActionId = "MOVE_CMD";
2050 QString aDescription = contextMenuMgr()->action(anActionId)->text();
2051 aMgr->startOperation(aDescription.toStdString());
2053 // Sort features by index in document
2054 std::list<FeaturePtr> aFList(aFeatures.begin(), aFeatures.end());
2055 aFList.sort(compareFeature);
2057 DocumentPtr anActiveDocument = aMgr->activeDocument();
2058 FeaturePtr aCurrentFeature = anActiveDocument->currentFeature(true);
2059 std::list<FeaturePtr>::const_iterator anIt = aFList.begin(), aLast = aFList.end();
2060 for (; anIt != aLast; anIt++) {
2061 FeaturePtr aFeature = *anIt;
2062 if (!aFeature.get() || !myModule->canApplyAction(aFeature, anActionId))
2065 anActiveDocument->moveFeature(aFeature, aCurrentFeature);
2066 aCurrentFeature = anActiveDocument->currentFeature(true);
2068 aMgr->finishOperation();
2069 updateCommandStatus();
2072 //**************************************************************
2073 bool XGUI_Workshop::deleteFeatures(const QObjectPtrList& theObjects)
2075 std::set<FeaturePtr> aFeatures;
2076 ModuleBase_Tools::convertToFeatures(theObjects, aFeatures);
2078 return ModelAPI_Tools::removeFeaturesAndReferences(aFeatures);
2081 //******************************************************
2082 bool hasResults(QObjectPtrList theObjects, const std::set<std::string>& theTypes)
2084 bool isFoundResultType = false;
2085 foreach(ObjectPtr anObj, theObjects)
2087 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
2088 if (aResult.get() == NULL)
2091 isFoundResultType = theTypes.find(aResult->groupName()) != theTypes.end();
2092 if (isFoundResultType)
2095 return isFoundResultType;
2098 //**************************************************************
2099 // Returns the list of all features for theDocument and all features of
2100 // all nested parts.
2101 std::list<FeaturePtr> allFeatures(const DocumentPtr& theDocument)
2103 std::list<FeaturePtr> aResultList;
2104 std::list<FeaturePtr> anAllFeatures = theDocument->allFeatures();
2105 foreach (const FeaturePtr& aFeature, anAllFeatures) {
2106 // The order of appending features of the part and the part itself is important
2108 // Append features from a part feature
2109 std::list<ResultPtr> aResults;
2110 ModelAPI_Tools::allResults(aFeature, aResults);
2111 foreach (const ResultPtr& aResult, aResults) {
2112 ResultPartPtr aResultPart =
2113 std::dynamic_pointer_cast<ModelAPI_ResultPart>(aResult);
2114 if (aResultPart.get() && aResultPart->partDoc().get()) {
2116 std::list<FeaturePtr> anAllFeatures = allFeatures(aResultPart->partDoc());
2117 aResultList.insert(aResultList.end(), anAllFeatures.begin(), anAllFeatures.end());
2121 aResultList.push_back(aFeature);
2126 //**************************************************************
2127 // Returns the list of features placed between theObject and the current feature
2128 // in the same document. Excludes theObject, includes the current feature.
2129 std::list<FeaturePtr> toCurrentFeatures(const ObjectPtr& theObject)
2131 std::list<FeaturePtr> aResult;
2132 DocumentPtr aDocument = theObject->document();
2133 std::list<FeaturePtr> anAllFeatures = allFeatures(aDocument);
2134 // find the object iterator
2135 std::list<FeaturePtr>::iterator aObjectIt =
2136 std::find(anAllFeatures.begin(), anAllFeatures.end(), theObject);
2137 if (aObjectIt == anAllFeatures.end())
2139 // find the current feature iterator
2140 std::list<FeaturePtr>::iterator aCurrentIt =
2141 std::find(anAllFeatures.begin(), anAllFeatures.end(), aDocument->currentFeature(true));
2142 if (aCurrentIt == anAllFeatures.end())
2144 // check the right order
2145 if (std::distance(aObjectIt, anAllFeatures.end()) <=
2146 std::distance(aCurrentIt, anAllFeatures.end()))
2148 // exclude the object
2149 std::advance(aObjectIt, 1);
2150 // include the current feature
2151 std::advance(aCurrentIt, 1);
2152 return std::list<FeaturePtr>(aObjectIt, aCurrentIt);
2155 //******************************************************
2156 bool XGUI_Workshop::canMoveFeature()
2158 QString anActionId = "MOVE_CMD";
2160 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
2161 QObjectPtrList aValidatedObjects;
2162 foreach (ObjectPtr aObject, aObjects) {
2163 if (!myModule->canApplyAction(aObject, anActionId))
2165 // To be moved feature should be in active document
2166 if (aObject->document() != ModelAPI_Session::get()->activeDocument())
2168 aValidatedObjects.append(aObject);
2170 if (aValidatedObjects.size() != aObjects.size())
2171 aObjects = aValidatedObjects;
2173 bool aCanMove = !aObjects.empty();
2175 QObjectPtrList::const_iterator anIt = aObjects.begin(), aLast = aObjects.end();
2176 for (; anIt != aLast && aCanMove; anIt++) {
2177 ObjectPtr aObject = *anIt;
2178 if (!aObject.get() || !aObject->data().get() || !aObject->data()->isValid()) {
2182 FeaturePtr aFeat = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
2183 // only groups can be moved to the end for now (#2451)
2184 if (aFeat.get() && aFeat->getKind() != "Group") {
2189 // 1. Get features placed between selected and current in the document
2190 std::list<FeaturePtr> aFeaturesBetween = toCurrentFeatures(aObject);
2191 // if aFeaturesBetween is empty it means wrong order or aObject is the current feature
2192 if (aFeaturesBetween.empty())
2195 std::set<FeaturePtr> aPlacedFeatures(aFeaturesBetween.begin(), aFeaturesBetween.end());
2196 // 2. Get all reference features to the selected object in the document
2197 std::set<FeaturePtr> aRefFeatures;
2198 ModuleBase_Tools::refsToFeatureInFeatureDocument(aObject, aRefFeatures);
2200 if (aRefFeatures.empty())
2203 // 3. Find any placed features in all reference features
2204 std::set<FeaturePtr> aIntersectionFeatures;
2205 std::set_intersection(aRefFeatures.begin(), aRefFeatures.end(),
2206 aPlacedFeatures.begin(), aPlacedFeatures.end(),
2207 std::inserter(aIntersectionFeatures, aIntersectionFeatures.begin()));
2208 // 4. Return false if any reference feature is placed before current feature
2209 if (!aIntersectionFeatures.empty())
2217 //**************************************************************
2218 bool XGUI_Workshop::canBeShaded(const ObjectPtr& theObject) const
2220 bool aCanBeShaded = myDisplayer->canBeShaded(theObject);
2221 if (!aCanBeShaded) {
2222 ResultBodyPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theObject);
2223 if (aCompRes.get() != NULL) { // change colors for all sub-solids
2224 std::list<ResultPtr> allRes;
2225 ModelAPI_Tools::allSubs(aCompRes, allRes);
2226 std::list<ResultPtr>::iterator aRes = allRes.begin();
2227 for(; aRes != allRes.end() && !aCanBeShaded; aRes++) {
2228 aCanBeShaded = myDisplayer->canBeShaded(*aRes);
2232 return aCanBeShaded;
2235 //**************************************************************
2236 bool XGUI_Workshop::canChangeProperty(const QString& theActionName) const
2238 if (theActionName == "COLOR_CMD" ||
2239 theActionName == "DEFLECTION_CMD" ||
2240 theActionName == "TRANSPARENCY_CMD") {
2241 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
2243 std::set<std::string> aTypes;
2244 aTypes.insert(ModelAPI_ResultGroup::group());
2245 aTypes.insert(ModelAPI_ResultConstruction::group());
2246 aTypes.insert(ModelAPI_ResultBody::group());
2247 aTypes.insert(ModelAPI_ResultPart::group());
2249 return hasResults(aObjects, aTypes);
2254 //******************************************************
2255 void setColor(ResultPtr theResult, const std::vector<int>& theColor)
2257 if (!theResult.get())
2260 AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
2261 if (aColorAttr.get() != NULL) {
2262 if (!aColorAttr->size()) {
2263 aColorAttr->setSize(3);
2265 aColorAttr->setValue(0, theColor[0]);
2266 aColorAttr->setValue(1, theColor[1]);
2267 aColorAttr->setValue(2, theColor[2]);
2269 static const Events_ID kRedisplayEvent =
2270 Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
2271 ModelAPI_EventCreator::get()->sendUpdated(theResult, kRedisplayEvent);
2274 //**************************************************************
2275 void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
2278 AttributeIntArrayPtr aColorAttr;
2279 // 1. find the current color of the object. This is a color of AIS presentation
2280 // The objects are iterated until a first valid color is found
2281 std::vector<int> aColor;
2282 foreach(ObjectPtr anObject, theObjects) {
2283 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
2284 if (aResult.get()) {
2285 ModelAPI_Tools::getColor(aResult, aColor);
2288 // TODO: remove the obtaining a color from the AIS object
2289 // this does not happen never because:
2290 // 1. The color can be changed only on results
2291 // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
2292 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
2293 if (anAISObj.get()) {
2295 anAISObj->getColor(aColor[0], aColor[1], aColor[2]);
2298 if (!aColor.empty())
2301 if (aColor.size() != 3)
2304 if (!abortAllOperations())
2306 // 2. show the dialog to change the value
2307 XGUI_ColorDialog* aDlg = new XGUI_ColorDialog(desktop());
2308 aDlg->setColor(aColor);
2309 aDlg->move(QCursor::pos());
2310 bool isDone = aDlg->exec() == QDialog::Accepted;
2314 bool isRandomColor = aDlg->isRandomColor();
2316 // 3. abort the previous operation and start a new one
2317 SessionPtr aMgr = ModelAPI_Session::get();
2318 QString aDescription = contextMenuMgr()->action("COLOR_CMD")->text();
2319 aMgr->startOperation(aDescription.toStdString());
2321 // 4. set the value to all results
2322 std::vector<int> aColorResult = aDlg->getColor();
2323 foreach(ObjectPtr anObj, theObjects) {
2324 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
2325 if (aResult.get() != NULL) {
2326 ResultBodyPtr aBodyResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
2327 if (aBodyResult.get() != NULL) { // change colors for all sub-solids
2328 std::list<ResultPtr> allRes;
2329 ModelAPI_Tools::allSubs(aBodyResult, allRes);
2330 for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
2331 setColor(*aRes, !isRandomColor ? aColorResult : aDlg->getRandomColor());
2334 setColor(aResult, !isRandomColor ? aColorResult : aDlg->getRandomColor());
2337 aMgr->finishOperation();
2338 updateCommandStatus();
2341 //**************************************************************
2342 void setDeflection(ResultPtr theResult, const double theDeflection)
2344 if (!theResult.get())
2347 AttributeDoublePtr aDeflectionAttr = theResult->data()->real(ModelAPI_Result::DEFLECTION_ID());
2348 if (aDeflectionAttr.get() != NULL)
2349 aDeflectionAttr->setValue(theDeflection);
2350 static const Events_ID kRedisplayEvent =
2351 Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
2352 ModelAPI_EventCreator::get()->sendUpdated(theResult, kRedisplayEvent);
2355 //**************************************************************
2356 void setTransparency(ResultPtr theResult, double theTransparency)
2358 if (!theResult.get())
2361 AttributeDoublePtr anAttribute = theResult->data()->real(ModelAPI_Result::TRANSPARENCY_ID());
2362 if (anAttribute.get() != NULL)
2363 anAttribute->setValue(theTransparency);
2364 static const Events_ID kRedisplayEvent =
2365 Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
2366 ModelAPI_EventCreator::get()->sendUpdated(theResult, kRedisplayEvent);
2369 //**************************************************************
2370 void setTransparency(double theTransparency, const QObjectPtrList& theObjects)
2372 foreach(ObjectPtr anObj, theObjects) {
2373 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
2374 if (aResult.get() != NULL) {
2375 ResultBodyPtr aBodyResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
2376 if (aBodyResult.get() != NULL) { // change property for all sub-solids
2377 std::list<ResultPtr> allRes;
2378 ModelAPI_Tools::allSubs(aBodyResult, allRes);
2379 for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
2380 setTransparency(*aRes, theTransparency);
2383 setTransparency(aResult, theTransparency);
2388 //**************************************************************
2389 void XGUI_Workshop::changeDeflection(const QObjectPtrList& theObjects)
2391 AttributeDoublePtr aDoubleAttr;
2392 // 1. find the current property of the object. This is a property of AIS presentation
2393 // The objects are iterated until a first valid property is found
2394 double aDeflection = -1;
2395 foreach(ObjectPtr anObject, theObjects) {
2396 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
2397 if (aResult.get()) {
2398 aDeflection = ModelAPI_Tools::getDeflection(aResult);
2401 // TODO: remove the obtaining a property from the AIS object
2402 // this does not happen never because:
2403 // 1. The property can be changed only on results
2404 // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
2405 AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
2406 if (anAISObj.get()) {
2407 aDeflection = anAISObj->getDeflection();
2410 if (aDeflection > 0)
2413 if (aDeflection < 0)
2416 if (!abortAllOperations())
2418 // 2. show the dialog to change the value
2419 XGUI_DeflectionDialog* aDlg = new XGUI_DeflectionDialog(desktop());
2420 aDlg->setDeflection(aDeflection);
2421 aDlg->move(QCursor::pos());
2422 bool isDone = aDlg->exec() == QDialog::Accepted;
2426 // 3. abort the previous operation and start a new one
2427 SessionPtr aMgr = ModelAPI_Session::get();
2428 QString aDescription = contextMenuMgr()->action("DEFLECTION_CMD")->text();
2429 aMgr->startOperation(aDescription.toStdString());
2431 // 4. set the value to all results
2432 aDeflection = aDlg->getDeflection();
2433 foreach(ObjectPtr anObj, theObjects) {
2434 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
2435 if (aResult.get() != NULL) {
2436 ResultBodyPtr aBodyResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
2437 if (aBodyResult.get() != NULL) { // change property for all sub-solids
2438 std::list<ResultPtr> allRes;
2439 ModelAPI_Tools::allSubs(aBodyResult, allRes);
2440 for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
2441 setDeflection(*aRes, aDeflection);
2444 setDeflection(aResult, aDeflection);
2447 aMgr->finishOperation();
2448 updateCommandStatus();
2451 //**************************************************************
2452 void XGUI_Workshop::changeTransparency(const QObjectPtrList& theObjects)
2454 AttributeDoublePtr aDoubleAttr;
2455 // 1. find the current property of the object. This is a property of AIS presentation
2456 // The objects are iterated until a first valid property is found
2457 double aCurrentValue = -1;
2458 foreach(ObjectPtr anObject, theObjects) {
2459 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
2460 if (aResult.get()) {
2461 aCurrentValue = ModelAPI_Tools::getTransparency(aResult);
2463 if (aCurrentValue > 0)
2466 if (aCurrentValue < 0)
2469 if (!abortAllOperations())
2472 // 2. show the dialog to change the value
2473 XGUI_PropertyDialog* aDlg = new XGUI_PropertyDialog(desktop());
2474 aDlg->setWindowTitle(tr("Transparency"));
2475 XGUI_TransparencyWidget* aTransparencyWidget = new XGUI_TransparencyWidget(aDlg);
2476 connect(aTransparencyWidget, SIGNAL(transparencyValueChanged()),
2477 this, SLOT(onTransparencyValueChanged()));
2478 aDlg->setContent(aTransparencyWidget);
2479 aTransparencyWidget->setValue(aCurrentValue);
2481 // 3. abort the previous operation and start a new one
2482 SessionPtr aMgr = ModelAPI_Session::get();
2483 QString aDescription = contextMenuMgr()->action("TRANSPARENCY_CMD")->text();
2484 aMgr->startOperation(aDescription.toStdString());
2486 if (aDlg->exec() == QDialog::Accepted) {
2487 // 4. set the value to all results
2488 aCurrentValue = aTransparencyWidget->getValue();
2489 setTransparency(aCurrentValue, theObjects);
2490 aMgr->finishOperation();
2492 aMgr->abortOperation();
2493 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2496 updateCommandStatus();
2499 //**************************************************************
2500 void XGUI_Workshop::onTransparencyValueChanged()
2502 XGUI_TransparencyWidget* aTransparencyWidget = (XGUI_TransparencyWidget*)sender();
2503 if (!aTransparencyWidget)
2506 QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
2507 setTransparency(aTransparencyWidget->getValue(), anObjects);
2508 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2512 //******************************************************
2513 void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible)
2516 std::set<ObjectPtr> anObjects;
2517 foreach (ObjectPtr aObj, theList) {
2518 anObjects.insert(aObj);
2520 if (!prepareForDisplay(anObjects))
2524 foreach (ObjectPtr aObj, theList) {
2525 aObj->setDisplayed(isVisible);
2527 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2528 myObjectBrowser->updateAllIndexes();
2530 updateColorScaleVisibility();
2533 //**************************************************************
2534 void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList)
2536 QObjectPtrList aSrcList = theList;
2537 // Hide all displayed objects
2538 QObjectPtrList aList = myDisplayer->displayedObjects();
2539 foreach (ObjectPtr aObj, aList) {
2540 if ((!aSrcList.contains(aObj)) && (module()->canEraseObject(aObj)))
2541 aObj->setDisplayed(false);
2543 aSrcList.removeAll(aObj);
2545 //Do not use eraseAll if you didn't send Redisplay event:
2546 //all objects are erased from viewer, but considered as displayed in displayer
2547 // Problem in bug 2218
2548 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2550 //issue #2159 Hide all incomplete behavior
2551 viewer()->eraseAll();
2554 std::set<ObjectPtr> anObjects;
2555 foreach (ObjectPtr aObj, aSrcList) {
2556 anObjects.insert(aObj);
2559 if (!prepareForDisplay(anObjects))
2562 // Show only objects from the list
2563 foreach (ObjectPtr aObj, aSrcList) {
2564 aObj->setDisplayed(true);
2566 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2568 // Necessary for update icons in ObjectBrowser on Linux
2569 myObjectBrowser->updateAllIndexes();
2570 updateColorScaleVisibility();
2574 //**************************************************************
2575 void XGUI_Workshop::updateColorScaleVisibility()
2577 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
2578 viewer()->setColorScaleShown(false);
2579 if (aObjects.size() == 1) {
2580 FieldStepPtr aStep =
2581 std::dynamic_pointer_cast<ModelAPI_ResultField::ModelAPI_FieldStep>(aObjects.first());
2582 if (aStep.get() && myDisplayer->isVisible(aStep)) {
2583 AISObjectPtr aAisPtr = myDisplayer->getAISObject(aStep);
2584 Handle(AIS_InteractiveObject) aIO = aAisPtr->impl<Handle(AIS_InteractiveObject)>();
2585 ModuleBase_IStepPrs* aPrs = dynamic_cast<ModuleBase_IStepPrs*>(aIO.get());
2587 ModelAPI_AttributeTables::ValueType aType = aPrs->dataType();
2588 if ((aType == ModelAPI_AttributeTables::DOUBLE) ||
2589 (aType == ModelAPI_AttributeTables::INTEGER) ||
2590 (aType == ModelAPI_AttributeTables::BOOLEAN)) {
2591 myViewerProxy->setupColorScale();
2592 if (aType == ModelAPI_AttributeTables::BOOLEAN) {
2593 myViewerProxy->setColorScaleIntervals(2);
2594 myViewerProxy->setColorScaleRange(0., 1.);
2598 aPrs->dataRange(aMin, aMax);
2599 myViewerProxy->setColorScaleRange(aMin, aMax);
2601 myViewerProxy->setColorScaleTitle(aStep->name().c_str());
2602 myViewerProxy->setColorScaleShown(true);
2610 //**************************************************************
2611 void XGUI_Workshop::setNormalView(bool toInvert)
2613 QList<ModuleBase_ViewerPrsPtr> aPrsList =
2614 mySelector->selection()->getSelected(ModuleBase_ISelection::Viewer);
2615 GeomShapePtr aPlanarFace;
2616 foreach(ModuleBase_ViewerPrsPtr aPrs, aPrsList) {
2617 GeomShapePtr aShape = aPrs->shape();
2618 if (aShape.get() && aShape->isPlanar()) {
2619 aPlanarFace = aShape;
2623 if (aPlanarFace.get()) {
2624 GeomFacePtr aFace(new GeomAPI_Face(aPlanarFace));
2625 GeomPlanePtr aPlane = aFace->getPlane();
2626 GeomDirPtr aNormal = aPlane->direction();
2629 GeomPointPtr aPos = aPlane->location();
2631 double aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
2632 aFace->computeSize(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
2634 Handle(V3d_View) aView = myViewerProxy->activeView();
2635 double aScale = aView->Scale();
2636 aView->SetAt(aPos->x(), aPos->y(), aPos->z());
2637 aView->SetProj(aNormal->x(), aNormal->y(), aNormal->z());
2639 aBox.Update(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
2640 aView->FitAll(aBox);
2644 //**************************************************************
2645 void XGUI_Workshop::registerValidators() const
2647 SessionPtr aMgr = ModelAPI_Session::get();
2648 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
2651 //**************************************************************
2652 void XGUI_Workshop::displayDocumentResults(DocumentPtr theDoc)
2656 displayGroupResults(theDoc, ModelAPI_ResultConstruction::group());
2657 displayGroupResults(theDoc, ModelAPI_ResultBody::group());
2660 //**************************************************************
2661 void XGUI_Workshop::displayGroupResults(DocumentPtr theDoc, std::string theGroup)
2663 for (int i = 0; i < theDoc->size(theGroup); i++)
2664 theDoc->object(theGroup, i)->setDisplayed(true);
2665 //displayObject(theDoc->object(theGroup, i));
2666 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
2669 //**************************************************************
2670 void XGUI_Workshop::setDisplayMode(const QObjectPtrList& theList, int theMode)
2672 foreach(ObjectPtr anObj, theList) {
2673 myDisplayer->setDisplayMode(anObj, (XGUI_Displayer::DisplayMode)theMode, false);
2675 ResultBodyPtr aBodyResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(anObj);
2676 if (aBodyResult.get() != NULL) { // change display mode for all sub-solids
2677 std::list<ResultPtr> allRes;
2678 ModelAPI_Tools::allSubs(aBodyResult, allRes);
2679 for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
2680 myDisplayer->setDisplayMode(*aRes, (XGUI_Displayer::DisplayMode)theMode, false);
2684 if (theList.size() > 0)
2685 myDisplayer->updateViewer();
2688 //**************************************************************
2689 void XGUI_Workshop::closeDocument()
2691 ModuleBase_Operation* anOperation = operationMgr()->currentOperation();
2692 while (anOperation) {
2693 anOperation->abort();
2694 anOperation = operationMgr()->currentOperation();
2696 //myDisplayer->closeLocalContexts();
2697 myDisplayer->eraseAll();
2698 objectBrowser()->clearContent();
2700 module()->closeDocument();
2701 // we need to clear viewer (with created filters) to do not have problems in 2nd SALOME study
2702 module()->clearViewer();
2705 // data model need not process the document's signals about objects modifications as
2706 // the document is closed
2707 //bool isBlocked = objectBrowser()->dataModel()->blockEventsProcessing(true);
2709 SessionPtr aMgr = ModelAPI_Session::get();
2712 //objectBrowser()->dataModel()->blockEventsProcessing(isBlocked);
2715 //******************************************************
2716 void XGUI_Workshop::addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot)
2718 XGUI_HistoryMenu* aMenu = NULL;
2719 if (isSalomeMode()) {
2720 QAction* anAction = qobject_cast<QAction*>(theObject);
2723 aMenu = new XGUI_HistoryMenu(anAction);
2725 QToolButton* aButton = qobject_cast<QToolButton*>(theObject);
2726 aMenu = new XGUI_HistoryMenu(aButton);
2728 connect(this, theSignal, aMenu, SLOT(setHistory(const QList<ActionInfo>&)));
2729 connect(aMenu, SIGNAL(actionSelected(int)), this, theSlot);
2732 //******************************************************
2733 QList<ActionInfo> XGUI_Workshop::processHistoryList(const std::list<std::string>& theList) const
2735 QList<ActionInfo> aResult;
2736 std::list<std::string>::const_iterator it = theList.cbegin();
2737 for (; it != theList.cend(); it++) {
2738 QString anId = QString::fromStdString(*it);
2739 bool isEditing = anId.endsWith(ModuleBase_OperationFeature::EditSuffix());
2741 anId.chop(ModuleBase_OperationFeature::EditSuffix().size());
2744 QAction* aContextMenuAct = myContextMenuMgr->actionByName(anId);
2745 if (aContextMenuAct) {
2746 anInfo.initFrom(aContextMenuAct);
2748 anInfo = myActionsMgr->actionInfoById(anId);
2751 anInfo.text = anInfo.text.prepend("Modify ");
2758 //******************************************************
2759 void XGUI_Workshop::setStatusBarMessage(const QString& theMessage)
2762 salomeConnector()->putInfo(theMessage, -1);
2764 myMainWindow->putInfo(theMessage, -1);
2769 //******************************************************
2770 void XGUI_Workshop::synchronizeViewer()
2772 SessionPtr aMgr = ModelAPI_Session::get();
2773 QList<DocumentPtr> aDocs;
2774 aDocs.append(aMgr->activeDocument());
2775 aDocs.append(aMgr->moduleDocument());
2777 foreach(DocumentPtr aDoc, aDocs) {
2778 synchronizeGroupInViewer(aDoc, ModelAPI_ResultConstruction::group(), false);
2779 synchronizeGroupInViewer(aDoc, ModelAPI_ResultBody::group(), false);
2780 synchronizeGroupInViewer(aDoc, ModelAPI_ResultPart::group(), false);
2781 synchronizeGroupInViewer(aDoc, ModelAPI_ResultGroup::group(), false);
2785 //******************************************************
2786 void XGUI_Workshop::synchronizeGroupInViewer(const DocumentPtr& theDoc,
2787 const std::string& theGroup,
2788 bool theUpdateViewer)
2791 int aSize = theDoc->size(theGroup);
2792 for (int i = 0; i < aSize; i++) {
2793 aObj = theDoc->object(theGroup, i);
2794 if (aObj->isDisplayed()) {
2795 // Hide the presentation with an empty shape. But isDisplayed state of the object should not
2796 // be changed to the object becomes visible when the shape becomes not empty
2797 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
2798 if (aRes.get() && (!aRes->shape().get() || aRes->shape()->isNull()))
2800 ResultBodyPtr aResBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aObj);
2802 synchronizeResultTree(aResBody, false);
2804 myDisplayer->display(aObj, false);
2807 if (theUpdateViewer)
2808 myDisplayer->updateViewer();
2811 void XGUI_Workshop::synchronizeResultTree(const ResultBodyPtr& theRes, bool theUpdateViewer)
2813 if (theRes->numberOfSubs() > 0)
2814 for (int i = 0; i < theRes->numberOfSubs(); i++) {
2815 ResultBodyPtr aRes = theRes->subResult(i);
2817 synchronizeResultTree(aRes, theUpdateViewer);
2820 if (theRes->isDisplayed())
2821 myDisplayer->display(theRes, theUpdateViewer);
2823 myDisplayer->erase(theRes, theUpdateViewer);
2828 //******************************************************
2829 void XGUI_Workshop::highlightResults(const QObjectPtrList& theObjects)
2831 FeaturePtr aFeature;
2832 QObjectPtrList aSelList = theObjects;
2833 QObjectPtrList aNewSel;
2834 bool aHasHidden = false;
2835 foreach(ObjectPtr aObj, theObjects) {
2836 aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
2837 if (aFeature.get()) {
2838 std::list<ResultPtr> aResults;
2839 ModelAPI_Tools::allResults(aFeature, aResults);
2840 std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aIt;
2841 for(aIt = aResults.cbegin(); aIt != aResults.cend(); aIt++) {
2842 aHasHidden |= (*aIt)->isConcealed();
2843 aSelList.append(*aIt);
2844 aNewSel.append(*aIt);
2848 if (aSelList.count() > theObjects.count()) {
2849 // if something was found
2850 objectBrowser()->setObjectsSelected(aSelList);
2851 objectBrowser()->ensureVisible(aNewSel.first());
2854 QMessageBox::information(desktop(), tr("Find results"),
2855 tr("Results not found"), QMessageBox::Ok);
2858 //******************************************************
2859 void XGUI_Workshop::highlightFeature(const QObjectPtrList& theObjects)
2862 QObjectPtrList aSelList = theObjects;
2863 QObjectPtrList aNewSel;
2864 FeaturePtr aFeature;
2865 foreach(ObjectPtr aObj, theObjects) {
2866 aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
2867 if (aResult.get()) {
2868 aFeature = ModelAPI_Feature::feature(aResult);
2869 if (aFeature.get()) {
2870 aSelList.append(aFeature);
2871 aNewSel.append(aFeature);
2875 if (aSelList.count() > theObjects.count()) {
2876 // if something was found
2877 objectBrowser()->setObjectsSelected(aSelList);
2878 objectBrowser()->ensureVisible(aNewSel.first());
2882 void XGUI_Workshop::insertFeatureFolder()
2884 QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
2885 if (aObjects.isEmpty())
2887 ObjectPtr aObj = aObjects.first();
2888 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
2889 if (aFeature.get() == NULL)
2891 SessionPtr aMgr = ModelAPI_Session::get();
2892 DocumentPtr aDoc = aMgr->activeDocument();
2894 QString aDescription = contextMenuMgr()->action("INSERT_FOLDER_CMD")->text();
2896 aMgr->startOperation(aDescription.toStdString());
2897 aDoc->addFolder(aFeature);
2898 aMgr->finishOperation();
2900 updateCommandStatus();
2904 void XGUI_Workshop::insertToFolder(bool isBefore)
2906 std::list<FeaturePtr> aFeatures = mySelector->getSelectedFeatures();
2907 if (aFeatures.empty())
2910 SessionPtr aMgr = ModelAPI_Session::get();
2911 DocumentPtr aDoc = aMgr->activeDocument();
2913 FolderPtr aFolder = isBefore? aDoc->findFolderAbove(aFeatures):
2914 aDoc->findFolderBelow(aFeatures);
2918 QString aDescription = contextMenuMgr()->action(
2919 isBefore ? "ADD_TO_FOLDER_BEFORE_CMD" : "ADD_TO_FOLDER_AFTER_CMD")->text();
2921 QMap<ObjectPtr, bool> aStates = myObjectBrowser->getFoldersState(aDoc);
2923 aMgr->startOperation(aDescription.toStdString());
2924 aDoc->moveToFolder(aFeatures, aFolder);
2925 aMgr->finishOperation();
2927 myObjectBrowser->setFoldersState(aStates);
2929 updateCommandStatus();
2932 void XGUI_Workshop::moveOutFolder(bool isBefore)
2934 std::list<FeaturePtr> aFeatures = mySelector->getSelectedFeatures();
2935 if (aFeatures.empty())
2938 SessionPtr aMgr = ModelAPI_Session::get();
2939 DocumentPtr aDoc = aMgr->activeDocument();
2941 QString aDescription = contextMenuMgr()->action(
2942 isBefore ? "ADD_OUT_FOLDER_BEFORE_CMD" : "ADD_OUT_FOLDER_AFTER_CMD")->text();
2944 QMap<ObjectPtr, bool> aStates = myObjectBrowser->getFoldersState(aDoc);
2946 aMgr->startOperation(aDescription.toStdString());
2947 aDoc->removeFromFolder(aFeatures, isBefore);
2948 aMgr->finishOperation();
2950 myObjectBrowser->setFoldersState(aStates);
2952 updateCommandStatus();
2955 void XGUI_Workshop::onAutoApply()
2957 SessionPtr aMgr = ModelAPI_Session::get();
2958 bool isBlocked = aMgr->isAutoUpdateBlocked();
2959 aMgr->blockAutoUpdate(!isBlocked);
2962 void XGUI_Workshop::updateAutoComputeState()
2964 SessionPtr aMgr = ModelAPI_Session::get();
2965 bool isComputeBlocked = aMgr->isAutoUpdateBlocked();
2967 // QAction* aUpdateCmd;
2968 // QList<QAction*> aCommands = mySalomeConnector->commandList();
2969 // foreach(QAction* aCmd, aCommands) {
2970 // if (aCmd->data().toString() == "AUTOCOMPUTE_CMD") {
2971 // aUpdateCmd = aCmd;
2975 // aUpdateCmd->setIcon(isComputeBlocked? QIcon(":pictures/autoapply_stop.png") :
2976 // QIcon(":pictures/autoapply_start.png"));
2978 AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
2979 AppElements_Command* aUpdateCmd = aMenuBar->feature("AUTOCOMPUTE_CMD");
2980 aUpdateCmd->button()->setIcon(isComputeBlocked? QIcon(":pictures/autoapply_stop.png") :
2981 QIcon(":pictures/autoapply_start.png"));
2986 void XGUI_Workshop::clearTemporaryDir()
2988 QDir aDir(myTmpDir.path());
2989 if (!aDir.isEmpty()) {
2990 QStringList aEntries;
2991 aDir.entryList(aEntries);
2992 foreach(QString aFile, aEntries) {
2999 void XGUI_Workshop::onDockSizeChanged()
3001 QDockWidget* aDockWgt = dynamic_cast<QDockWidget*>(myObjectBrowser->parentWidget());
3002 int aObWidth = aDockWgt->size().width();
3003 if (myPropertyPanel->width() != aObWidth) {
3004 QList<QDockWidget*> aWgtList;
3005 aWgtList << myPropertyPanel << aDockWgt;
3006 QList<int> aSizeList;
3007 aSizeList << aObWidth << aObWidth;
3008 desktop()->resizeDocks(aWgtList, aSizeList, Qt::Horizontal);
3009 disconnect(myObjectBrowser, SIGNAL(sizeChanged()), this, SLOT(onDockSizeChanged()));
3013 void XGUI_Workshop::deactivateCurrentSelector()
3015 myActiveControlMgr->deactivateSelector(myActiveControlMgr->activeSelector());