Salome HOME
3860a9ff1af1bad55f3132d648b8547ca594e44b
[modules/shaper.git] / src / XGUI / XGUI_PropertyPanel.cpp
1 // Copyright (C) 2014-2019  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include <XGUI_ActionsMgr.h>
21 #include <XGUI_ActiveControlMgr.h>
22 #include <XGUI_SelectionActivate.h>
23 #include <XGUI_ActiveControlSelector.h>
24 #include <XGUI_PropertyPanel.h>
25 #include <XGUI_PropertyPanelSelector.h>
26 #include <XGUI_OperationMgr.h>
27 #include <XGUI_Tools.h>
28 #include <XGUI_Workshop.h>
29
30 //#include <AppElements_Constants.h>
31 #include <ModuleBase_WidgetMultiSelector.h>
32 #include <ModuleBase_Tools.h>
33 #include <ModuleBase_PageBase.h>
34 #include <ModuleBase_PageWidget.h>
35 #include <ModuleBase_WidgetFactory.h>
36 #include <ModuleBase_OperationDescription.h>
37 #include <ModuleBase_Events.h>
38 #include <ModuleBase_IModule.h>
39 #include <ModuleBase_IWorkshop.h>
40
41 #include <Events_Loop.h>
42
43 #include <ModelAPI_Session.h>
44 #include <ModelAPI_Validator.h>
45
46 #include <QEvent>
47 #include <QFrame>
48 #include <QIcon>
49 #include <QKeyEvent>
50 #include <QLayoutItem>
51 #include <QToolButton>
52 #include <QVBoxLayout>
53 #include <QGridLayout>
54 #include <QWidget>
55 #include <QAction>
56 #include <QScrollArea>
57
58 #ifdef _DEBUG
59 #include <iostream>
60 #endif
61
62 //#define DEBUG_TAB_WIDGETS
63
64 //#define DEBUG_ACTIVE_WIDGET
65
66 XGUI_PropertyPanel::XGUI_PropertyPanel(QWidget* theParent, XGUI_OperationMgr* theMgr)
67     : ModuleBase_IPropertyPanel(theParent),
68     myActiveWidget(NULL),
69     myPreselectionWidget(NULL),
70     myInternalActiveWidget(NULL),
71     myPanelPage(NULL),
72     myOperationMgr(theMgr)
73 {
74   setWindowTitle(tr("Property Panel"));
75   QAction* aViewAct = toggleViewAction();
76   setObjectName(PROP_PANEL);
77   setStyleSheet("::title { position: relative; padding-left: 5px; text-align: left center }");
78
79   QWidget* aContent = new QWidget(this);
80   QGridLayout* aMainLayout = new QGridLayout(aContent);
81   const int kPanelColumn = 0;
82   int aPanelRow = 0;
83   aMainLayout->setContentsMargins(3, 3, 3, 3);
84   setWidget(aContent);
85
86   QFrame* aFrm = new QFrame(aContent);
87   aFrm->setFrameStyle(QFrame::Raised);
88   aFrm->setFrameShape(QFrame::Panel);
89   QHBoxLayout* aBtnLay = new QHBoxLayout(aFrm);
90   ModuleBase_Tools::zeroMargins(aBtnLay);
91   aMainLayout->addWidget(aFrm, aPanelRow++, kPanelColumn);
92
93   myHeaderWidget = aFrm;
94
95   QStringList aBtnNames;
96   aBtnNames << QString(PROP_PANEL_HELP)
97     << QString(PROP_PANEL_OK)
98     << QString(PROP_PANEL_OK_PLUS)
99     << QString(PROP_PANEL_CANCEL);
100   foreach(QString eachBtnName, aBtnNames) {
101     QToolButton* aBtn = new QToolButton(aFrm);
102     aBtn->setObjectName(eachBtnName);
103     aBtn->setAutoRaise(true);
104     aBtnLay->addWidget(aBtn);
105   }
106   aBtnLay->insertStretch(1, 1);
107
108   myPanelPage = new ModuleBase_PageWidget(aContent);
109   myPanelPage->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
110   aMainLayout->addWidget(myPanelPage, aPanelRow, kPanelColumn);
111
112   // spit to make the preview button on the bottom of the panel
113   aMainLayout->setRowStretch(aPanelRow++, 1);
114
115   // preview button on the bottom of panel
116   aFrm = new QFrame(aContent);
117   aBtnLay = new QHBoxLayout(aFrm);
118   aBtnLay->addStretch(1);
119   ModuleBase_Tools::zeroMargins(aBtnLay);
120   aMainLayout->addWidget(aFrm, aPanelRow++, kPanelColumn);
121
122   QToolButton* aBtn = new QToolButton(aFrm);
123   aBtn->setObjectName(PROP_PANEL_PREVIEW);
124   aBtnLay->addWidget(aBtn);
125 }
126
127 XGUI_PropertyPanel::~XGUI_PropertyPanel()
128 {
129 }
130
131 void XGUI_PropertyPanel::cleanContent()
132 {
133   if (myActiveWidget)
134     myActiveWidget->deactivate();
135
136   XGUI_ActiveControlSelector* aPPSelector = XGUI_Tools::workshop(myOperationMgr->workshop())->
137     activeControlMgr()->getSelector(XGUI_PropertyPanelSelector::Type());
138   aPPSelector->reset(); // it removes need to be updated widget link
139
140   /// as the widgets are deleted later, it is important that the signals
141   /// of these widgets are not processed. An example of the error is issue 986.
142   /// In the given case, the property panel is firstly filled by new widgets
143   /// of restarted operation and after that the mouse release signal come from
144   /// the widget of the previous operation (Point2d widget about mouse is released
145   /// and focus is out of this widget)
146   QList<ModuleBase_ModelWidget*>::const_iterator anIt = myWidgets.begin(),
147                                                  aLast = myWidgets.end();
148   for (; anIt != aLast; anIt++) {
149     QWidget* aWidget = *anIt;
150     if (aWidget) {
151       aWidget->blockSignals(true);
152     }
153   }
154
155   myWidgets.clear();
156   myPanelPage->clearPage();
157   myActiveWidget = NULL;
158   emit propertyPanelDeactivated();
159   // VSV: It seems that this code is not necessary:
160   //      it is called on propertyPanelDeactivated() event
161   //myOperationMgr->workshop()->selectionActivate()->updateSelectionModes();
162   //myOperationMgr->workshop()->selectionActivate()->updateSelectionFilters();
163 #ifdef DEBUG_ACTIVE_WIDGET
164   std::cout << "myActiveWidget = NULL" << std::endl;
165 #endif
166
167   findButton(PROP_PANEL_PREVIEW)->setVisible(false); /// by default it is hidden
168   setWindowTitle(tr("Property Panel"));
169 }
170
171 void XGUI_PropertyPanel::setModelWidgets(const QList<ModuleBase_ModelWidget*>& theWidgets)
172 {
173   myWidgets = theWidgets;
174   if (theWidgets.empty())
175     return;
176   foreach (ModuleBase_ModelWidget* aWidget, theWidgets) {
177     connect(aWidget, SIGNAL(focusInWidget(ModuleBase_ModelWidget*)),
178             this,    SLOT(onFocusInWidget(ModuleBase_ModelWidget*)));
179     connect(aWidget, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)),
180             this,    SLOT(onActivateNextWidget(ModuleBase_ModelWidget*)));
181     connect(aWidget, SIGNAL(keyReleased(QObject*, QKeyEvent*)),
182             this,    SIGNAL(keyReleased(QObject*, QKeyEvent*)));
183     connect(aWidget, SIGNAL(enterClicked(QObject*)),
184             this,    SIGNAL(enterClicked(QObject*)));
185   }
186 }
187
188
189 const QList<ModuleBase_ModelWidget*>& XGUI_PropertyPanel::modelWidgets() const
190 {
191   return myWidgets;
192 }
193
194 ModuleBase_PageBase* XGUI_PropertyPanel::contentWidget()
195 {
196   return static_cast<ModuleBase_PageBase*>(myPanelPage);
197 }
198
199 void XGUI_PropertyPanel::updateContentWidget(FeaturePtr theFeature)
200 {
201   // Invalid feature case on abort of the operation
202   if (theFeature.get() == NULL)
203     return;
204   if (theFeature->isAction() || !theFeature->data())
205     return;
206   foreach(ModuleBase_ModelWidget* eachWidget, myWidgets) {
207     if (!eachWidget->feature().get())
208       eachWidget->setFeature(theFeature);
209     eachWidget->restoreValue();
210   }
211   // the repaint is used here to immediately react in GUI to the values change.
212   update();
213 }
214
215 void XGUI_PropertyPanel::createContentPanel(FeaturePtr theFeature)
216 {
217   // Invalid feature case on abort of the operation
218   if (theFeature.get() == NULL)
219     return;
220   if (theFeature->isAction() || !theFeature->data())
221     return;
222
223   ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
224   if (myWidgets.empty()) {
225     QString aXmlRepr = anOperation->getDescription()->xmlRepresentation();
226
227     ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), myOperationMgr->workshop());
228     aFactory.createPanel(contentWidget(), theFeature);
229     /// Apply button should be update if the feature was modified by the panel
230     myOperationMgr->onValidateOperation();
231   }
232   ModuleBase_OperationFeature* aFeatureOp =
233     dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
234   if (aFeatureOp && (!aFeatureOp->isEditOperation()))
235     updateApplyPlusButton(theFeature);
236   else
237     findButton(PROP_PANEL_OK_PLUS)->setVisible(false);
238 }
239
240 void XGUI_PropertyPanel::updateApplyPlusButton(FeaturePtr theFeature)
241 {
242   if (theFeature.get()) {
243     std::shared_ptr<Config_FeatureMessage> aFeatureInfo =
244       myOperationMgr->workshop()->featureInfo(theFeature->getKind().c_str());
245     if (aFeatureInfo.get()) {
246       findButton(PROP_PANEL_OK_PLUS)->setVisible(aFeatureInfo->isApplyContinue());
247       return;
248     }
249   }
250   findButton(PROP_PANEL_OK_PLUS)->setVisible(false);
251 }
252
253 ModuleBase_ModelWidget* XGUI_PropertyPanel::activeWidget(const bool isUseCustomWidget) const
254 {
255   if (isUseCustomWidget && myInternalActiveWidget)
256     return myInternalActiveWidget;
257
258   return myActiveWidget;
259 }
260
261 void XGUI_PropertyPanel::activateNextWidget(ModuleBase_ModelWidget* theWidget)
262 {
263   // it is possible that the property panel widgets have not been visualized
264   // (e.g. on start operation), so it is strictly important to do not check visualized state
265   activateNextWidget(theWidget, false);
266 }
267
268 void XGUI_PropertyPanel::onFocusInWidget(ModuleBase_ModelWidget* theWidget)
269 {
270 #ifdef DEBUG_ACTIVE_WIDGET
271   std::cout << "onFocusInWidget" << std::endl;
272 #endif
273   if (theWidget->canAcceptFocus())
274     activateWidget(theWidget);
275 }
276
277 void XGUI_PropertyPanel::onActivateNextWidget(ModuleBase_ModelWidget* theWidget)
278 {
279   // this slot happens when some widget lost focus, the next widget which accepts the focus
280   // should be shown, so the second parameter is true
281   // it is important for features where in cases the same attributes are used, isCase for this
282   // attribute returns true, however it can be placed in hidden stack widget(extrusion: elements,
283   // sketch multi rotation -> single/full point)
284   // it is important to check the widget visibility to do not check of the next widget visible
285   // state if the current is not shown. (example: sketch circle re-entrant operation after mouse
286   // release in the viewer, next, radius,
287   // widget should be activated but the first is not visualized)
288   bool isVisible = theWidget->isVisible();
289   activateNextWidget(theWidget, isVisible);
290 }
291
292
293 void XGUI_PropertyPanel::activateNextWidget(ModuleBase_ModelWidget* theWidget,
294                                             const bool isCheckVisibility)
295 {
296   // TO CHECK: Editing operation does not have automatical activation of widgets
297   if (isEditingMode()) {
298     activateWidget(NULL);
299     return;
300   }
301   ModelAPI_ValidatorsFactory* aValidators = ModelAPI_Session::get()->validators();
302
303   QList<ModuleBase_ModelWidget*>::const_iterator anIt = myWidgets.begin(), aLast = myWidgets.end();
304   bool isFoundWidget = false;
305   ModuleBase_Tools::activateWindow(this, "XGUI_PropertyPanel::activateNextWidget()");
306   for (; anIt != aLast; anIt++) {
307     ModuleBase_ModelWidget* aCurrentWidget = *anIt;
308     if (isFoundWidget || !theWidget) {
309
310       if (!aValidators->isCase(aCurrentWidget->feature(), aCurrentWidget->attributeID()))
311         continue; // this attribute does not participate in the current case
312       if (isCheckVisibility && !aCurrentWidget->isInternal()) {
313         if (!aCurrentWidget->isVisible())
314           continue;
315       }
316       if (!aCurrentWidget->isObligatory())
317         continue; // not obligatory widgets are not activated automatically
318
319       if (!aCurrentWidget->canAcceptFocus())
320         continue; // do not set focus if it can not be accepted, case: optional choice
321
322       if (aCurrentWidget->focusTo()) {
323         aCurrentWidget->emitFocusInWidget();
324         return;
325       }
326     }
327     isFoundWidget = isFoundWidget || (*anIt) == theWidget;
328   }
329   // set focus to Ok/Cancel button in Property panel if there are no more active widgets
330   // it should be performed before activateWidget(NULL) because it emits some signals which
331   // can be processed by moudule for example as to activate another widget with setting focus
332   QWidget* aNewFocusWidget = 0;
333   QToolButton* anOkBtn = findButton(PROP_PANEL_OK);
334   if (anOkBtn->isEnabled())
335     aNewFocusWidget = anOkBtn;
336   else {
337     QToolButton* aCancelBtn = findButton(PROP_PANEL_CANCEL);
338     if (aCancelBtn->isEnabled())
339       aNewFocusWidget = aCancelBtn;
340   }
341   if (aNewFocusWidget)
342     ModuleBase_Tools::setFocus(aNewFocusWidget, "XGUI_PropertyPanel::activateNextWidget");
343
344   activateWidget(NULL);
345 }
346
347 void findDirectChildren(QWidget* theParent, QList<QWidget*>& theWidgets, const bool theDebug)
348 {
349   QList<QWidget*> aWidgets;
350
351   if (theParent) {
352     QLayout* aLayout = theParent->layout();
353     if (aLayout) {
354       for (int i = 0, aCount = aLayout->count(); i < aCount; i++) {
355         QLayoutItem* anItem = aLayout->itemAt(i);
356         QWidget* aWidget = anItem ? anItem->widget() : 0;
357         if (aWidget) {
358           if (aWidget->isVisible()) {
359             if (aWidget->focusPolicy() != Qt::NoFocus)
360               theWidgets.append(aWidget);
361             findDirectChildren(aWidget, theWidgets, false);
362           }
363         }
364         else if (anItem->layout()) {
365           QLayout* aLayout = anItem->layout();
366           for (int i = 0, aCount = aLayout->count(); i < aCount; i++) {
367             QLayoutItem* anItem = aLayout->itemAt(i);
368             QWidget* aWidget = anItem ? anItem->widget() : 0;
369             if (aWidget) {
370               if (aWidget->isVisible()) {
371                 if (aWidget->focusPolicy() != Qt::NoFocus)
372                   theWidgets.append(aWidget);
373                 findDirectChildren(aWidget, theWidgets, false);
374               }
375             }
376             else {
377               // TODO: improve recursive search for the case when here QLayout is used
378               // currently, the switch widget uses only 1 level of qlayout in qlayout using for
379               // example for construction plane feature. If there are more levels,
380               // it should be implemented here
381             }
382           }
383         }
384       }
385     }
386   }
387 #ifdef DEBUG_TAB_WIDGETS
388   if (theDebug) {
389     QStringList aWidgetTypes;
390     QList<QWidget*>::const_iterator anIt =  theWidgets.begin(), aLast = theWidgets.end();
391     for (; anIt != aLast; anIt++) {
392       QWidget* aWidget = *anIt;
393       if (aWidget)
394         aWidgetTypes.append(aWidget->objectName());
395     }
396     QString anInfo = QString("theWidgets[%1]: %2")
397       .arg(theWidgets.count()).arg(aWidgetTypes.join(","));
398     qDebug(anInfo.toStdString().c_str());
399   }
400 #endif
401 }
402
403 bool XGUI_PropertyPanel::setFocusNextPrevChild(bool theIsNext)
404 {
405   return focusNextPrevChild(theIsNext);
406 }
407
408 bool XGUI_PropertyPanel::focusNextPrevChild(bool theIsNext)
409 {
410   // it wraps the Tabs clicking to follow in the chain:
411   // controls, last control, Apply, Cancel, first control, controls
412   bool isChangedFocus = false;
413
414   QWidget* aFocusWidget = focusWidget();
415 #ifdef DEBUG_TAB_WIDGETS
416   if (aFocusWidget) {
417     QString anInfo = QString("focus Widget: %1").arg(aFocusWidget->objectName());
418     qDebug(anInfo.toStdString().c_str());
419   }
420 #endif
421   ModuleBase_ModelWidget* aFocusMWidget = ModuleBase_ModelWidget::findModelWidget(this,
422                                                                          aFocusWidget);
423   //if (aFocusMWidget)
424   //  aFocusMWidget->setHighlighted(false);
425
426   QWidget* aNewFocusWidget = 0;
427   if (aFocusWidget) {
428     QList<QWidget*> aChildren;
429     findDirectChildren(this, aChildren, true);
430     int aChildrenCount = aChildren.count();
431     int aFocusWidgetIndex = aChildren.indexOf(aFocusWidget);
432     QToolButton* anOkBtn = findButton(PROP_PANEL_OK);
433     if (aFocusWidgetIndex >= 0) {
434       if (theIsNext) {
435         if (aFocusWidgetIndex == aChildrenCount-1) {
436           // after the last widget focus should be set to "Apply"
437           if (anOkBtn->isEnabled())
438             aNewFocusWidget = anOkBtn;
439           else {
440             QToolButton* aCancelBtn = findButton(PROP_PANEL_CANCEL);
441             if (aCancelBtn->isEnabled())
442               aNewFocusWidget = aCancelBtn;
443           }
444         }
445         else {
446           aNewFocusWidget = aChildren[aFocusWidgetIndex+1];
447         }
448       }
449       else {
450         if (aFocusWidgetIndex == 0) {
451           // before the first widget, the last should accept focus
452           aNewFocusWidget = aChildren[aChildrenCount - 1];
453         }
454         else {
455           // before the "Apply" button, the last should accept focus for consistency with "Next"
456           if (aFocusWidget == anOkBtn) {
457             aNewFocusWidget = aChildren[aChildrenCount - 1];
458           }
459           else {
460             aNewFocusWidget = aChildren[aFocusWidgetIndex-1];
461           }
462         }
463       }
464     }
465   }
466   if (aNewFocusWidget) {
467     if (myActiveWidget) {
468       bool isFirstControl = !theIsNext;
469       QWidget* aLastFocusControl = myActiveWidget->getControlAcceptingFocus(isFirstControl);
470       if (aFocusWidget == aLastFocusControl) {
471         setActiveWidget(NULL, false);
472       }
473     }
474
475     // we want to have property panel as an active window to enter values in double control
476     ModuleBase_Tools::setFocus(aNewFocusWidget, "XGUI_PropertyPanel::focusNextPrevChild()");
477
478     ModuleBase_ModelWidget* aNewFocusMWidget = ModuleBase_ModelWidget::findModelWidget(this,
479                                                                               aNewFocusWidget);
480     if (aNewFocusMWidget) {
481       if (aFocusMWidget) {
482         aFocusMWidget->setHighlighted(false);
483       }
484       aNewFocusMWidget->emitFocusInWidget();
485       isChangedFocus = true;
486     }
487   }
488   return isChangedFocus;
489 }
490
491 void XGUI_PropertyPanel::activateNextWidget()
492 {
493   activateNextWidget(myActiveWidget);
494 }
495
496 void XGUI_PropertyPanel::activateWidget(ModuleBase_ModelWidget* theWidget, const bool theEmitSignal)
497 {
498   std::string aPreviosAttributeID;
499   if(myActiveWidget)
500     aPreviosAttributeID = myActiveWidget->attributeID();
501
502   // Avoid activation of already actve widget. It could happen on focusIn event many times
503   setActiveWidget(theWidget, theEmitSignal);
504 }
505
506 bool XGUI_PropertyPanel::setActiveWidget(ModuleBase_ModelWidget* theWidget, const bool isEmitSignal)
507 {
508   // Avoid activation of already actve widget. It could happen on focusIn event many times
509   if (theWidget == myActiveWidget) {
510     return false;
511   }
512   std::string aPreviosAttributeID;
513   ModuleBase_ModelWidget* aDeactivatedWidget = NULL, *anActivatedWidget = NULL;
514   if(myActiveWidget) {
515     aPreviosAttributeID = myActiveWidget->attributeID();
516     myActiveWidget->processValueState();
517     myActiveWidget->deactivate();
518     myActiveWidget->setHighlighted(false);
519     aDeactivatedWidget = myActiveWidget;
520   }
521   if(theWidget) {
522     emit beforeWidgetActivated(theWidget);
523     theWidget->setHighlighted(true);
524     theWidget->activate();
525     anActivatedWidget = theWidget;
526   }
527   myActiveWidget = theWidget;
528
529 #ifdef DEBUG_ACTIVE_WIDGET
530   std::cout << "myActiveWidget = " << (theWidget ? theWidget->context().c_str() : "") << std::endl;
531 #endif
532   bool aHasMoreWidgets = true;
533   if (isEmitSignal) {
534     //emit widgetActivated(myActiveWidget);
535     if (!myActiveWidget && !isEditingMode()) {
536       aHasMoreWidgets = false;
537       emit noMoreWidgets(aPreviosAttributeID);
538     }
539   }
540   if (myActiveWidget)
541     emit propertyPanelActivated();
542   else
543     emit propertyPanelDeactivated();
544   myOperationMgr->workshop()->selectionActivate()->updateSelectionModes();
545   myOperationMgr->workshop()->selectionActivate()->updateSelectionFilters();
546
547   if (aHasMoreWidgets && aDeactivatedWidget)
548     aDeactivatedWidget->updateAfterDeactivation();
549   if (aHasMoreWidgets && anActivatedWidget)
550     anActivatedWidget->updateAfterActivation();
551
552   if (aHasMoreWidgets && myActiveWidget)
553   {
554     // restore widget selection should be done after selection modes of widget activating
555     static Events_ID anEvent = Events_Loop::eventByName(EVENT_UPDATE_BY_WIDGET_SELECTION);
556     Events_Loop::loop()->flush(anEvent);
557   }
558   return true;
559 }
560
561 void XGUI_PropertyPanel::setFocusOnOkButton()
562 {
563   QToolButton* anOkBtn = findButton(PROP_PANEL_OK);
564   ModuleBase_Tools::setFocus(anOkBtn, "XGUI_PropertyPanel::setFocusOnOkButton()");
565 }
566
567 void XGUI_PropertyPanel::setCancelEnabled(bool theEnabled)
568 {
569   QToolButton* anCancelBtn = findButton(PROP_PANEL_CANCEL);
570   anCancelBtn->setEnabled(theEnabled);
571 }
572
573 bool XGUI_PropertyPanel::isCancelEnabled() const
574 {
575   QToolButton* anCancelBtn = findButton(PROP_PANEL_CANCEL);
576   return anCancelBtn->isEnabled();
577 }
578
579 void XGUI_PropertyPanel::setEditingMode(bool isEditing)
580 {
581   ModuleBase_IPropertyPanel::setEditingMode(isEditing);
582   foreach(ModuleBase_ModelWidget* aWgt, myWidgets) {
583     aWgt->setEditingMode(isEditing);
584   }
585 }
586
587 void XGUI_PropertyPanel::setupActions(XGUI_ActionsMgr* theMgr)
588 {
589   QStringList aButtonNames;
590   aButtonNames << PROP_PANEL_OK<< PROP_PANEL_OK_PLUS << PROP_PANEL_CANCEL
591                << PROP_PANEL_HELP << PROP_PANEL_PREVIEW;
592   QList<XGUI_ActionsMgr::OperationStateActionId> aActionIds;
593   aActionIds << XGUI_ActionsMgr::Accept << XGUI_ActionsMgr::AcceptPlus << XGUI_ActionsMgr::Abort
594              << XGUI_ActionsMgr::Help << XGUI_ActionsMgr::Preview;
595   for (int i = 0; i < aButtonNames.size(); ++i) {
596     QToolButton* aBtn = findButton(aButtonNames.at(i).toStdString().c_str());
597     QAction* anAct = theMgr->operationStateAction(aActionIds.at(i));
598     aBtn->setDefaultAction(anAct);
599   }
600 }
601
602 void XGUI_PropertyPanel::onAcceptData()
603 {
604   foreach (ModuleBase_ModelWidget* aWidget, myWidgets) {
605     aWidget->onFeatureAccepted();
606   }
607 }
608
609 void XGUI_PropertyPanel::setInternalActiveWidget(ModuleBase_ModelWidget* theWidget)
610 {
611   if (theWidget)
612   {
613     myInternalActiveWidget = theWidget;
614     emit propertyPanelActivated();
615   }
616   else
617   {
618     if (myInternalActiveWidget)
619     {
620       delete myInternalActiveWidget;
621       myInternalActiveWidget = 0;
622     }
623     emit propertyPanelDeactivated();
624   }
625   myOperationMgr->workshop()->selectionActivate()->updateSelectionModes();
626   myOperationMgr->workshop()->selectionActivate()->updateSelectionFilters();
627 }
628
629 ModuleBase_ModelWidget* XGUI_PropertyPanel::preselectionWidget() const
630 {
631   return myPreselectionWidget;
632 }
633
634 void XGUI_PropertyPanel::setPreselectionWidget(ModuleBase_ModelWidget* theWidget)
635 {
636   myPreselectionWidget = theWidget;
637 }
638
639
640 void XGUI_PropertyPanel::closeEvent(QCloseEvent* theEvent)
641 {
642   ModuleBase_Operation* aOp = myOperationMgr->currentOperation();
643   if (aOp) {
644     if (myOperationMgr->canStopOperation(aOp)) {
645       myOperationMgr->abortOperation(aOp);
646       if (myOperationMgr->hasOperation())
647         theEvent->ignore();
648       else
649         theEvent->accept();
650     } else
651       theEvent->ignore();
652   } else
653     ModuleBase_IPropertyPanel::closeEvent(theEvent);
654 }
655
656 QToolButton* XGUI_PropertyPanel::findButton(const char* theInternalName) const
657 {
658   return findChild<QToolButton*>(theInternalName);
659 }