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