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