Salome HOME
Implementation of the automatic breaking the link if the shape is modified or deleted
[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   if (myWidgets.empty()) {
224     ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
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   updateApplyPlusButton(theFeature);
233 }
234
235 void XGUI_PropertyPanel::updateApplyPlusButton(FeaturePtr theFeature)
236 {
237   if (theFeature.get()) {
238     std::shared_ptr<Config_FeatureMessage> aFeatureInfo =
239       myOperationMgr->workshop()->featureInfo(theFeature->getKind().c_str());
240     if (aFeatureInfo.get()) {
241       findButton(PROP_PANEL_OK_PLUS)->setVisible(aFeatureInfo->isApplyContinue());
242       return;
243     }
244   }
245   findButton(PROP_PANEL_OK_PLUS)->setVisible(false);
246 }
247
248 ModuleBase_ModelWidget* XGUI_PropertyPanel::activeWidget(const bool isUseCustomWidget) const
249 {
250   if (isUseCustomWidget && myInternalActiveWidget)
251     return myInternalActiveWidget;
252
253   return myActiveWidget;
254 }
255
256 void XGUI_PropertyPanel::activateNextWidget(ModuleBase_ModelWidget* theWidget)
257 {
258   // it is possible that the property panel widgets have not been visualized
259   // (e.g. on start operation), so it is strictly important to do not check visualized state
260   activateNextWidget(theWidget, false);
261 }
262
263 void XGUI_PropertyPanel::onFocusInWidget(ModuleBase_ModelWidget* theWidget)
264 {
265 #ifdef DEBUG_ACTIVE_WIDGET
266   std::cout << "onFocusInWidget" << std::endl;
267 #endif
268   if (theWidget->canAcceptFocus())
269     activateWidget(theWidget);
270 }
271
272 void XGUI_PropertyPanel::onActivateNextWidget(ModuleBase_ModelWidget* theWidget)
273 {
274   // this slot happens when some widget lost focus, the next widget which accepts the focus
275   // should be shown, so the second parameter is true
276   // it is important for features where in cases the same attributes are used, isCase for this
277   // attribute returns true, however it can be placed in hidden stack widget(extrusion: elements,
278   // sketch multi rotation -> single/full point)
279   // it is important to check the widget visibility to do not check of the next widget visible
280   // state if the current is not shown. (example: sketch circle re-entrant operation after mouse
281   // release in the viewer, next, radius,
282   // widget should be activated but the first is not visualized)
283   bool isVisible = theWidget->isVisible();
284   activateNextWidget(theWidget, isVisible);
285 }
286
287
288 void XGUI_PropertyPanel::activateNextWidget(ModuleBase_ModelWidget* theWidget,
289                                             const bool isCheckVisibility)
290 {
291   // TO CHECK: Editing operation does not have automatical activation of widgets
292   if (isEditingMode()) {
293     activateWidget(NULL);
294     return;
295   }
296   ModelAPI_ValidatorsFactory* aValidators = ModelAPI_Session::get()->validators();
297
298   QList<ModuleBase_ModelWidget*>::const_iterator anIt = myWidgets.begin(), aLast = myWidgets.end();
299   bool isFoundWidget = false;
300   ModuleBase_Tools::activateWindow(this, "XGUI_PropertyPanel::activateNextWidget()");
301   for (; anIt != aLast; anIt++) {
302     ModuleBase_ModelWidget* aCurrentWidget = *anIt;
303     if (isFoundWidget || !theWidget) {
304
305       if (!aValidators->isCase(aCurrentWidget->feature(), aCurrentWidget->attributeID()))
306         continue; // this attribute does not participate in the current case
307       if (isCheckVisibility && !aCurrentWidget->isInternal()) {
308         if (!aCurrentWidget->isVisible())
309           continue;
310       }
311       if (!aCurrentWidget->isObligatory())
312         continue; // not obligatory widgets are not activated automatically
313
314       if (!aCurrentWidget->canAcceptFocus())
315         continue; // do not set focus if it can not be accepted, case: optional choice
316
317       if (aCurrentWidget->focusTo()) {
318         aCurrentWidget->emitFocusInWidget();
319         return;
320       }
321     }
322     isFoundWidget = isFoundWidget || (*anIt) == theWidget;
323   }
324   // set focus to Ok/Cancel button in Property panel if there are no more active widgets
325   // it should be performed before activateWidget(NULL) because it emits some signals which
326   // can be processed by moudule for example as to activate another widget with setting focus
327   QWidget* aNewFocusWidget = 0;
328   QToolButton* anOkBtn = findButton(PROP_PANEL_OK);
329   if (anOkBtn->isEnabled())
330     aNewFocusWidget = anOkBtn;
331   else {
332     QToolButton* aCancelBtn = findButton(PROP_PANEL_CANCEL);
333     if (aCancelBtn->isEnabled())
334       aNewFocusWidget = aCancelBtn;
335   }
336   if (aNewFocusWidget)
337     ModuleBase_Tools::setFocus(aNewFocusWidget, "XGUI_PropertyPanel::activateNextWidget");
338
339   activateWidget(NULL);
340 }
341
342 void findDirectChildren(QWidget* theParent, QList<QWidget*>& theWidgets, const bool theDebug)
343 {
344   QList<QWidget*> aWidgets;
345
346   if (theParent) {
347     QLayout* aLayout = theParent->layout();
348     if (aLayout) {
349       for (int i = 0, aCount = aLayout->count(); i < aCount; i++) {
350         QLayoutItem* anItem = aLayout->itemAt(i);
351         QWidget* aWidget = anItem ? anItem->widget() : 0;
352         if (aWidget) {
353           if (aWidget->isVisible()) {
354             if (aWidget->focusPolicy() != Qt::NoFocus)
355               theWidgets.append(aWidget);
356             findDirectChildren(aWidget, theWidgets, false);
357           }
358         }
359         else if (anItem->layout()) {
360           QLayout* aLayout = anItem->layout();
361           for (int i = 0, aCount = aLayout->count(); i < aCount; i++) {
362             QLayoutItem* anItem = aLayout->itemAt(i);
363             QWidget* aWidget = anItem ? anItem->widget() : 0;
364             if (aWidget) {
365               if (aWidget->isVisible()) {
366                 if (aWidget->focusPolicy() != Qt::NoFocus)
367                   theWidgets.append(aWidget);
368                 findDirectChildren(aWidget, theWidgets, false);
369               }
370             }
371             else {
372               // TODO: improve recursive search for the case when here QLayout is used
373               // currently, the switch widget uses only 1 level of qlayout in qlayout using for
374               // example for construction plane feature. If there are more levels,
375               // it should be implemented here
376             }
377           }
378         }
379       }
380     }
381   }
382 #ifdef DEBUG_TAB_WIDGETS
383   if (theDebug) {
384     QStringList aWidgetTypes;
385     QList<QWidget*>::const_iterator anIt =  theWidgets.begin(), aLast = theWidgets.end();
386     for (; anIt != aLast; anIt++) {
387       QWidget* aWidget = *anIt;
388       if (aWidget)
389         aWidgetTypes.append(aWidget->objectName());
390     }
391     QString anInfo = QString("theWidgets[%1]: %2")
392       .arg(theWidgets.count()).arg(aWidgetTypes.join(","));
393     qDebug(anInfo.toStdString().c_str());
394   }
395 #endif
396 }
397
398 bool XGUI_PropertyPanel::setFocusNextPrevChild(bool theIsNext)
399 {
400   return focusNextPrevChild(theIsNext);
401 }
402
403 bool XGUI_PropertyPanel::focusNextPrevChild(bool theIsNext)
404 {
405   // it wraps the Tabs clicking to follow in the chain:
406   // controls, last control, Apply, Cancel, first control, controls
407   bool isChangedFocus = false;
408
409   QWidget* aFocusWidget = focusWidget();
410 #ifdef DEBUG_TAB_WIDGETS
411   if (aFocusWidget) {
412     QString anInfo = QString("focus Widget: %1").arg(aFocusWidget->objectName());
413     qDebug(anInfo.toStdString().c_str());
414   }
415 #endif
416   ModuleBase_ModelWidget* aFocusMWidget = ModuleBase_ModelWidget::findModelWidget(this,
417                                                                          aFocusWidget);
418   //if (aFocusMWidget)
419   //  aFocusMWidget->setHighlighted(false);
420
421   QWidget* aNewFocusWidget = 0;
422   if (aFocusWidget) {
423     QList<QWidget*> aChildren;
424     findDirectChildren(this, aChildren, true);
425     int aChildrenCount = aChildren.count();
426     int aFocusWidgetIndex = aChildren.indexOf(aFocusWidget);
427     QToolButton* anOkBtn = findButton(PROP_PANEL_OK);
428     if (aFocusWidgetIndex >= 0) {
429       if (theIsNext) {
430         if (aFocusWidgetIndex == aChildrenCount-1) {
431           // after the last widget focus should be set to "Apply"
432           if (anOkBtn->isEnabled())
433             aNewFocusWidget = anOkBtn;
434           else {
435             QToolButton* aCancelBtn = findButton(PROP_PANEL_CANCEL);
436             if (aCancelBtn->isEnabled())
437               aNewFocusWidget = aCancelBtn;
438           }
439         }
440         else {
441           aNewFocusWidget = aChildren[aFocusWidgetIndex+1];
442         }
443       }
444       else {
445         if (aFocusWidgetIndex == 0) {
446           // before the first widget, the last should accept focus
447           aNewFocusWidget = aChildren[aChildrenCount - 1];
448         }
449         else {
450           // before the "Apply" button, the last should accept focus for consistency with "Next"
451           if (aFocusWidget == anOkBtn) {
452             aNewFocusWidget = aChildren[aChildrenCount - 1];
453           }
454           else {
455             aNewFocusWidget = aChildren[aFocusWidgetIndex-1];
456           }
457         }
458       }
459     }
460   }
461   if (aNewFocusWidget) {
462     if (myActiveWidget) {
463       bool isFirstControl = !theIsNext;
464       QWidget* aLastFocusControl = myActiveWidget->getControlAcceptingFocus(isFirstControl);
465       if (aFocusWidget == aLastFocusControl) {
466         setActiveWidget(NULL, false);
467       }
468     }
469
470     // we want to have property panel as an active window to enter values in double control
471     ModuleBase_Tools::setFocus(aNewFocusWidget, "XGUI_PropertyPanel::focusNextPrevChild()");
472
473     ModuleBase_ModelWidget* aNewFocusMWidget = ModuleBase_ModelWidget::findModelWidget(this,
474                                                                               aNewFocusWidget);
475     if (aNewFocusMWidget) {
476       if (aFocusMWidget) {
477         aFocusMWidget->setHighlighted(false);
478       }
479       aNewFocusMWidget->emitFocusInWidget();
480       isChangedFocus = true;
481     }
482   }
483   return isChangedFocus;
484 }
485
486 void XGUI_PropertyPanel::activateNextWidget()
487 {
488   activateNextWidget(myActiveWidget);
489 }
490
491 void XGUI_PropertyPanel::activateWidget(ModuleBase_ModelWidget* theWidget, const bool theEmitSignal)
492 {
493   std::string aPreviosAttributeID;
494   if(myActiveWidget)
495     aPreviosAttributeID = myActiveWidget->attributeID();
496
497   // Avoid activation of already actve widget. It could happen on focusIn event many times
498   setActiveWidget(theWidget, theEmitSignal);
499 }
500
501 bool XGUI_PropertyPanel::setActiveWidget(ModuleBase_ModelWidget* theWidget, const bool isEmitSignal)
502 {
503   // Avoid activation of already actve widget. It could happen on focusIn event many times
504   if (theWidget == myActiveWidget) {
505     return false;
506   }
507   std::string aPreviosAttributeID;
508   ModuleBase_ModelWidget* aDeactivatedWidget = NULL, *anActivatedWidget = NULL;
509   if(myActiveWidget) {
510     aPreviosAttributeID = myActiveWidget->attributeID();
511     myActiveWidget->processValueState();
512     myActiveWidget->deactivate();
513     myActiveWidget->setHighlighted(false);
514     aDeactivatedWidget = myActiveWidget;
515   }
516   if(theWidget) {
517     emit beforeWidgetActivated(theWidget);
518     theWidget->setHighlighted(true);
519     theWidget->activate();
520     anActivatedWidget = theWidget;
521   }
522   myActiveWidget = theWidget;
523
524 #ifdef DEBUG_ACTIVE_WIDGET
525   std::cout << "myActiveWidget = " << (theWidget ? theWidget->context().c_str() : "") << std::endl;
526 #endif
527   bool aHasMoreWidgets = true;
528   if (isEmitSignal) {
529     //emit widgetActivated(myActiveWidget);
530     if (!myActiveWidget && !isEditingMode()) {
531       aHasMoreWidgets = false;
532       emit noMoreWidgets(aPreviosAttributeID);
533     }
534   }
535   if (myActiveWidget)
536     emit propertyPanelActivated();
537   else
538     emit propertyPanelDeactivated();
539   myOperationMgr->workshop()->selectionActivate()->updateSelectionModes();
540   myOperationMgr->workshop()->selectionActivate()->updateSelectionFilters();
541
542   if (aHasMoreWidgets && aDeactivatedWidget)
543     aDeactivatedWidget->updateAfterDeactivation();
544   if (aHasMoreWidgets && anActivatedWidget)
545     anActivatedWidget->updateAfterActivation();
546
547   if (aHasMoreWidgets && myActiveWidget)
548   {
549     // restore widget selection should be done after selection modes of widget activating
550     static Events_ID anEvent = Events_Loop::eventByName(EVENT_UPDATE_BY_WIDGET_SELECTION);
551     Events_Loop::loop()->flush(anEvent);
552   }
553   return true;
554 }
555
556 void XGUI_PropertyPanel::setFocusOnOkButton()
557 {
558   QToolButton* anOkBtn = findButton(PROP_PANEL_OK);
559   ModuleBase_Tools::setFocus(anOkBtn, "XGUI_PropertyPanel::setFocusOnOkButton()");
560 }
561
562 void XGUI_PropertyPanel::setCancelEnabled(bool theEnabled)
563 {
564   QToolButton* anCancelBtn = findButton(PROP_PANEL_CANCEL);
565   anCancelBtn->setEnabled(theEnabled);
566 }
567
568 bool XGUI_PropertyPanel::isCancelEnabled() const
569 {
570   QToolButton* anCancelBtn = findButton(PROP_PANEL_CANCEL);
571   return anCancelBtn->isEnabled();
572 }
573
574 void XGUI_PropertyPanel::setEditingMode(bool isEditing)
575 {
576   ModuleBase_IPropertyPanel::setEditingMode(isEditing);
577   foreach(ModuleBase_ModelWidget* aWgt, myWidgets) {
578     aWgt->setEditingMode(isEditing);
579   }
580 }
581
582 void XGUI_PropertyPanel::setupActions(XGUI_ActionsMgr* theMgr)
583 {
584   QStringList aButtonNames;
585   aButtonNames << PROP_PANEL_OK<< PROP_PANEL_OK_PLUS << PROP_PANEL_CANCEL
586                << PROP_PANEL_HELP << PROP_PANEL_PREVIEW;
587   QList<XGUI_ActionsMgr::OperationStateActionId> aActionIds;
588   aActionIds << XGUI_ActionsMgr::Accept << XGUI_ActionsMgr::AcceptPlus << XGUI_ActionsMgr::Abort
589              << XGUI_ActionsMgr::Help << XGUI_ActionsMgr::Preview;
590   for (int i = 0; i < aButtonNames.size(); ++i) {
591     QToolButton* aBtn = findButton(aButtonNames.at(i).toStdString().c_str());
592     QAction* anAct = theMgr->operationStateAction(aActionIds.at(i));
593     aBtn->setDefaultAction(anAct);
594   }
595 }
596
597 void XGUI_PropertyPanel::onAcceptData()
598 {
599   foreach (ModuleBase_ModelWidget* aWidget, myWidgets) {
600     aWidget->onFeatureAccepted();
601   }
602 }
603
604 void XGUI_PropertyPanel::setInternalActiveWidget(ModuleBase_ModelWidget* theWidget)
605 {
606   if (theWidget)
607   {
608     myInternalActiveWidget = theWidget;
609     emit propertyPanelActivated();
610   }
611   else
612   {
613     if (myInternalActiveWidget)
614     {
615       delete myInternalActiveWidget;
616       myInternalActiveWidget = 0;
617     }
618     emit propertyPanelDeactivated();
619   }
620   myOperationMgr->workshop()->selectionActivate()->updateSelectionModes();
621   myOperationMgr->workshop()->selectionActivate()->updateSelectionFilters();
622 }
623
624 ModuleBase_ModelWidget* XGUI_PropertyPanel::preselectionWidget() const
625 {
626   return myPreselectionWidget;
627 }
628
629 void XGUI_PropertyPanel::setPreselectionWidget(ModuleBase_ModelWidget* theWidget)
630 {
631   myPreselectionWidget = theWidget;
632 }
633
634
635 void XGUI_PropertyPanel::closeEvent(QCloseEvent* theEvent)
636 {
637   ModuleBase_Operation* aOp = myOperationMgr->currentOperation();
638   if (aOp) {
639     if (myOperationMgr->canStopOperation(aOp)) {
640       myOperationMgr->abortOperation(aOp);
641       if (myOperationMgr->hasOperation())
642         theEvent->ignore();
643       else
644         theEvent->accept();
645     } else
646       theEvent->ignore();
647   } else
648     ModuleBase_IPropertyPanel::closeEvent(theEvent);
649 }
650
651 QToolButton* XGUI_PropertyPanel::findButton(const char* theInternalName) const
652 {
653   return findChild<QToolButton*>(theInternalName);
654 }