]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_Tools.cpp
Salome HOME
Issue #1664 In the Sketcher, add the function Split a segment
[modules/shaper.git] / src / ModuleBase / ModuleBase_Tools.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModuleBase_Tools.cpp
4 // Created:     11 July 2014
5 // Author:      Vitaly Smetannikov
6
7 #include "ModuleBase_Tools.h"
8
9 #include <ModuleBase_ParamIntSpinBox.h>
10 #include <ModuleBase_ParamSpinBox.h>
11 #include <ModuleBase_WidgetFactory.h>
12 #include <ModuleBase_IWorkshop.h>
13 #include <ModuleBase_IModule.h>
14 #include <ModuleBase_IconFactory.h>
15 #include <ModuleBase_ResultPrs.h>
16
17 #include <ModelAPI_Attribute.h>
18 #include <ModelAPI_AttributeRefAttr.h>
19 #include <ModelAPI_AttributeReference.h>
20 #include <ModelAPI_AttributeSelection.h>
21 #include <ModelAPI_AttributeSelectionList.h>
22 #include <ModelAPI_AttributeRefList.h>
23 #include <ModelAPI_AttributeRefAttrList.h>
24 #include <ModelAPI_ResultPart.h>
25 #include <ModelAPI_ResultConstruction.h>
26 #include <Events_Loop.h>
27
28 #include <ModelAPI_Data.h>
29 #include <ModelAPI_Result.h>
30 #include <ModelAPI_ResultCompSolid.h>
31 #include <ModelAPI_ResultParameter.h>
32 #include <ModelAPI_Tools.h>
33 #include <ModelAPI_Session.h>
34 #include <ModelAPI_Events.h>
35
36 #include <ModelGeomAlgo_Point2D.h>
37
38 #include <TopoDS_Iterator.hxx>
39
40 #include <GeomDataAPI_Point2D.h>
41 #include <Events_InfoMessage.h>
42 #include <GeomAPI_ShapeExplorer.h>
43
44 #include <Config_PropManager.h>
45 #include <Config_Translator.h>
46
47 #include <Prs3d_PointAspect.hxx>
48 #include <Graphic3d_AspectMarker3d.hxx>
49
50 #include <Image_AlienPixMap.hxx>
51
52 #include <QWidget>
53 #include <QLayout>
54 #include <QPainter>
55 #include <QBitmap>
56 #include <QDoubleSpinBox>
57 #include <QGraphicsDropShadowEffect>
58 #include <QColor>
59 #include <QApplication>
60 #include <QMessageBox>
61 #include <QAction>
62 #include <QTextCodec>
63
64 #include <sstream>
65 #include <string>
66
67 #ifdef WIN32
68 #pragma warning(disable : 4996) // for getenv
69 #endif
70
71 const double tolerance = 1e-7;
72 const double DEFAULT_DEVIATION_COEFFICIENT = 1.e-4;
73
74 //#define DEBUG_ACTIVATE_WINDOW
75 //#define DEBUG_SET_FOCUS
76 //#define DEBUG_SELECTION_INFO
77
78 #ifdef DEBUG_SELECTION_INFO
79 #include <ModuleBase_ISelection.h>
80 #include <ModuleBase_ViewerPrs.h>
81
82 #include <AIS_InteractiveContext.hxx>
83 #include <AIS_ListOfInteractive.hxx>
84 #include <AIS_ListIteratorOfListOfInteractive.hxx>
85 #include <AIS_Shape.hxx>
86 #include <TopoDS_Shape.hxx>
87 #include <AIS_LocalContext.hxx>
88 #include <NCollection_List.hxx>
89 #include <StdSelect_BRepOwner.hxx>
90 #include <TColStd_ListOfInteger.hxx>
91 #include <TColStd_ListIteratorOfListOfInteger.hxx>
92 #endif
93
94 #ifdef WIN32
95 # define FSEP "\\"
96 #else
97 # define FSEP "/"
98 #endif
99
100 namespace ModuleBase_Tools {
101
102 //******************************************************************
103
104 //******************************************************************
105
106 void adjustMargins(QWidget* theWidget)
107 {
108   if(!theWidget)
109     return;
110   adjustMargins(theWidget->layout());
111 }
112
113 void adjustMargins(QLayout* theLayout)
114 {
115   if(!theLayout)
116     return;
117   theLayout->setContentsMargins(2, 5, 2, 5);
118   theLayout->setSpacing(4);
119 }
120
121 void zeroMargins(QWidget* theWidget)
122 {
123   if(!theWidget)
124     return;
125   zeroMargins(theWidget->layout());
126 }
127
128 void zeroMargins(QLayout* theLayout)
129 {
130   if(!theLayout)
131     return;
132   theLayout->setContentsMargins(0, 0, 0, 0);
133   theLayout->setSpacing(5);
134 }
135
136 void activateWindow(QWidget* theWidget, const QString& theInfo)
137 {
138   theWidget->activateWindow();
139
140 #ifdef DEBUG_ACTIVATE_WINDOW
141   qDebug(QString("activateWindow: %1").arg(theInfo).toStdString().c_str());
142 #endif
143 }
144
145 void setFocus(QWidget* theWidget, const QString& theInfo)
146 {
147   theWidget->setFocus();
148
149 #ifdef DEBUG_SET_FOCUS
150   qDebug(QString("setFocus: %1").arg(theInfo).toStdString().c_str());
151 #endif
152 }
153
154 void setShadowEffect(QWidget* theWidget, const bool isSetEffect)
155 {
156   if (isSetEffect) {
157     QGraphicsDropShadowEffect* aGlowEffect = new QGraphicsDropShadowEffect();
158     aGlowEffect->setOffset(.0);
159     aGlowEffect->setBlurRadius(10.0);
160     aGlowEffect->setColor(QColor(0, 170, 255)); // Light-blue color, #00AAFF
161     theWidget->setGraphicsEffect(aGlowEffect);
162   }
163   else {
164     QGraphicsEffect* anEffect = theWidget->graphicsEffect();
165     if(anEffect)
166       anEffect->deleteLater();
167     theWidget->setGraphicsEffect(NULL);
168   }
169 }
170
171 QPixmap composite(const QString& theAdditionalIcon, const QString& theIcon)
172 {
173   QImage anIcon = ModuleBase_IconFactory::loadImage(theIcon);
174   QImage anAditional(theAdditionalIcon);
175
176   if (anIcon.isNull())
177     return QPixmap();
178
179   int anAddWidth = anAditional.width();
180   int anAddHeight = anAditional.height();
181
182   int aWidth = anIcon.width();
183   int aHeight = anIcon.height();
184
185   int aStartWidthPos = aWidth - anAddWidth - 1;
186   int aStartHeightPos = aHeight - anAddHeight - 1;
187
188   for (int i = 0; i < anAddWidth && i + aStartWidthPos < aWidth; i++)
189   {
190     for (int j = 0; j < anAddHeight && j + aStartHeightPos < aHeight; j++)
191     {
192       if (qAlpha(anAditional.pixel(i, j)) > 0)
193         anIcon.setPixel(i + aStartWidthPos, j + aStartHeightPos, anAditional.pixel(i, j));
194     }
195   }
196   return QPixmap::fromImage(anIcon);
197 }
198
199 QPixmap lighter(const QString& theIcon, const int theLighterValue)
200 {
201   QImage anIcon = ModuleBase_IconFactory::loadImage(theIcon);
202   if (anIcon.isNull())
203     return QPixmap();
204
205   QImage aResult = ModuleBase_IconFactory::loadImage(theIcon);
206   for (int i = 0; i < anIcon.width(); i++)
207   {
208     for (int j = 0; j < anIcon.height(); j++)
209     {
210       QRgb anRgb = anIcon.pixel(i, j);
211       QColor aPixelColor(qRed(anRgb), qGreen(anRgb), qBlue(anRgb),
212                          qAlpha(aResult.pixel(i, j)));
213
214       QColor aLighterColor = aPixelColor.lighter(theLighterValue);
215       aResult.setPixel(i, j, qRgba(aLighterColor.red(), aLighterColor.green(),
216                                     aLighterColor.blue(), aLighterColor.alpha()));
217     }
218   }
219   return QPixmap::fromImage(aResult);
220 }
221
222 void setSpinText(ModuleBase_ParamSpinBox* theSpin, const QString& theText)
223 {
224   if (theSpin->text() == theText) 
225     return;
226   // In order to avoid extra text setting because it will
227   // reset cursor position in control
228   bool isBlocked = theSpin->blockSignals(true);
229   theSpin->setText(theText);
230   theSpin->blockSignals(isBlocked);
231 }
232
233 void setSpinValue(QDoubleSpinBox* theSpin, double theValue)
234 {
235   if (fabs(theSpin->value() - theValue) < tolerance)
236     return;
237   bool isBlocked = theSpin->blockSignals(true);
238   theSpin->setValue(theValue);
239   theSpin->blockSignals(isBlocked);
240 }
241
242 void setSpinValue(ModuleBase_ParamSpinBox* theSpin, double theValue)
243 {
244   if (fabs(theSpin->value() - theValue) < tolerance)
245     return;
246   bool isBlocked = theSpin->blockSignals(true);
247   theSpin->setValue(theValue);
248   theSpin->blockSignals(isBlocked);
249 }
250
251 void setSpinText(ModuleBase_ParamIntSpinBox* theSpin, const QString& theText)
252 {
253   // In order to avoid extra text setting because it will
254   // reset cursor position in control
255   if (theSpin->text() == theText)
256     return;
257   bool isBlocked = theSpin->blockSignals(true);
258   theSpin->setText(theText);
259   theSpin->blockSignals(isBlocked);
260 }
261
262 void setSpinValue(ModuleBase_ParamIntSpinBox* theSpin, int theValue)
263 {
264   if (theSpin->value() == theValue)
265     return;
266   bool isBlocked = theSpin->blockSignals(true);
267   theSpin->setValue(theValue);
268   theSpin->blockSignals(isBlocked);
269 }
270
271 QAction* createAction(const QIcon& theIcon, const QString& theText,
272                       QObject* theParent, const QObject* theReceiver,
273                       const char* theMember, const QString& theToolTip,
274                       const QString& theStatusTip)
275 {
276   QAction* anAction = new QAction(theIcon, theText, theParent);
277   anAction->setToolTip(theToolTip.isEmpty() ? theText : theToolTip);
278   anAction->setStatusTip(!theStatusTip.isEmpty() ? theStatusTip :
279                                                    (!theToolTip.isEmpty() ? theToolTip : theText));
280   if (theReceiver)
281     QObject::connect(anAction, SIGNAL(triggered(bool)), theReceiver, theMember);
282
283   return anAction;
284 }
285
286 QString objectInfo(const ObjectPtr& theObj, const bool isUseAttributesInfo)
287 {
288   QString aFeatureStr = "feature";
289   if (!theObj.get())
290     return aFeatureStr;
291
292   std::ostringstream aPtrStr;
293   aPtrStr << "[" << theObj.get() << "]";
294
295   ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObj);
296   FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObj);
297   if(aRes.get()) {
298     aFeatureStr.append(QString("(result%1)").arg(aPtrStr.str().c_str()).toStdString() .c_str());
299     if (aRes->isDisabled())
300       aFeatureStr.append("[disabled]");
301     if (aRes->isConcealed())
302       aFeatureStr.append("[concealed]");
303     if (ModelAPI_Tools::hasSubResults(aRes))
304       aFeatureStr.append("[hasSubResults]");
305
306     aFeature = ModelAPI_Feature::feature(aRes);
307   }
308   else
309     aFeatureStr.append(aPtrStr.str().c_str());
310
311   if (aFeature.get()) {
312     aFeatureStr.append(QString(": %1").arg(aFeature->getKind().c_str()).toStdString().c_str());
313     if (aFeature->data()->isValid()) {
314       aFeatureStr.append(QString(", name=%1").arg(theObj->data()->name().c_str()).toStdString()
315                                                                                        .c_str());
316     }
317     if (isUseAttributesInfo) {
318       std::set<std::shared_ptr<ModelAPI_Attribute> > anAttributes;
319       std::string aPointsInfo = ModelGeomAlgo_Point2D::getPontAttributesInfo(aFeature,
320                                                                              anAttributes).c_str();
321       if (!aPointsInfo.empty())
322         aFeatureStr.append(QString(", attributes: %1").arg(aPointsInfo.c_str()).toStdString().c_str());
323     }
324   }
325
326   return aFeatureStr;
327 }
328
329 #ifdef DEBUG_SELECTION_INFO
330 QString getShapeTypeInfo(const int theType)
331 {
332   QString anInfo = "Undefined";
333   switch(theType) {
334     case TopAbs_COMPOUND:  anInfo = "compound"; break;
335     case TopAbs_COMPSOLID: anInfo = "compsolid"; break;
336     case TopAbs_SOLID:     anInfo = "solid"; break;
337     case TopAbs_SHELL:     anInfo = "shell"; break;
338     case TopAbs_FACE:      anInfo = "face"; break;
339     case TopAbs_WIRE:      anInfo = "wire"; break;
340     case TopAbs_EDGE:      anInfo = "edge"; break;
341     case TopAbs_VERTEX:    anInfo = "vertex"; break;
342     case TopAbs_SHAPE:     anInfo = "shape"; break;
343     case ModuleBase_ResultPrs::Sel_Result:
344                            anInfo = "result_shape"; break;
345     default: break;
346   }
347   return anInfo;
348 }
349
350 QString getModeInfo(const int theMode)
351 {
352   QString anInfo = "Undefined";
353   switch(theMode) {
354     case 0: anInfo = "SHAPE(0)"; break;
355     case 1: anInfo = "VERTEX(1)"; break;
356     case 2: anInfo = "EDGE(2)"; break;
357     case 3: anInfo = "WIRE(3)"; break;
358     case 4: anInfo = "FACE(4)"; break;
359     case 5: anInfo = "SHELL(5)"; break;
360     case 6: anInfo = "SOLID(6)"; break;
361     case 7: anInfo = "COMPSOLID(7)"; break;
362     case 8: anInfo = "COMPOUND(8)"; break;
363     case 100: anInfo = "Sel_Mode_First(100)"; break; //SketcherPrs_Tools
364     case 101: anInfo = "Sel_Constraint(101)"; break;
365     case 102: anInfo = "Sel_Dimension_All(102)"; break;
366     case 103: anInfo = "Sel_Dimension_Line(103)"; break;
367     case 104: anInfo = "Sel_Dimension_Text(104)"; break;
368     default: break;
369   }
370   return anInfo;
371 }
372
373 QString displayedInteractiveObjects(Handle(AIS_InteractiveContext)& theContext,
374                                     const bool theShapeInfoOnly = true)
375 {
376   if (theContext.IsNull())
377     return "";
378   AIS_ListOfInteractive aListOfIO;
379   theContext->DisplayedObjects(aListOfIO, false);
380   QStringList anObjects;
381   AIS_ListIteratorOfListOfInteractive aIt;
382   for (aIt.Initialize(aListOfIO); aIt.More(); aIt.Next()) {
383     Handle(AIS_InteractiveObject) anAISIO = aIt.Value();
384     Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(anAISIO);
385     if (theShapeInfoOnly && aShapePrs.IsNull())
386       continue;
387
388     QString anInfo = "IO";
389     std::ostringstream aPtrStr;
390     aPtrStr << "[" << anAISIO.Access() << "]";
391     anInfo += aPtrStr.str().c_str();
392
393     if (!aShapePrs.IsNull()) {
394       const TopoDS_Shape& aShape = aShapePrs->Shape();
395       if (aShape.IsNull()) {
396         //Events_Error::throwException("An empty AIS presentation");
397       }
398       else
399         anInfo += QString(", shape type: %1").arg(getShapeTypeInfo(aShape.ShapeType()));
400     }
401     TColStd_ListOfInteger aTColModes;
402     theContext->ActivatedModes(anAISIO, aTColModes);
403     TColStd_ListIteratorOfListOfInteger itr( aTColModes );
404     QIntList aModesActivatedForIO;
405     bool isDeactivated = false;
406     QStringList aModes;
407     for (; itr.More(); itr.Next() ) {
408       Standard_Integer aMode = itr.Value();
409       aModes.append(getModeInfo(aMode));
410       //int aShapeMode = (aMode > 8)? aMode : AIS_Shape::SelectionType(aMode);
411     }
412     if (aModes.size() > 0)
413       anInfo += QString(", activated modes: %1").arg(aModes.join(", "));
414
415     anObjects += anInfo;
416   }
417   QString aValue = QString("displayedIO[%1]").arg(anObjects.size());
418   if (anObjects.size() > 0)
419     aValue += QString(":\n  %1").arg(anObjects.join("\n  "));
420   return aValue;
421 }
422
423 QString activeOwners(Handle(AIS_InteractiveContext)& theContext, const bool theShapeInfoOnly = true)
424 {
425   if (theContext.IsNull())
426     return "";
427   Handle(AIS_LocalContext) aLContext = theContext->LocalContext();
428   TCollection_AsciiString aSelectionName = aLContext->SelectionName();
429   aLContext->UnhilightPicked(Standard_False);
430
431   NCollection_List<Handle(SelectBasics_EntityOwner)> anActiveOwners;
432   aLContext->MainSelector()->ActiveOwners(anActiveOwners);
433   NCollection_List<Handle(SelectBasics_EntityOwner)>::Iterator anOwnersIt (anActiveOwners);
434   Handle(SelectMgr_EntityOwner) anOwner;
435   QStringList anObjects;
436   for (; anOwnersIt.More(); anOwnersIt.Next()) {
437     anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anOwnersIt.Value());
438     Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(anOwner);
439     if (theShapeInfoOnly && BROwnr.IsNull())
440       continue;
441
442     QString anInfo = "Owner";
443     std::ostringstream aPtrStr;
444     aPtrStr << "[" << anOwner.Access() << "]";
445     anInfo += aPtrStr.str().c_str();
446
447     Handle(AIS_InteractiveObject) aAISObj = 
448           Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
449     if (!aAISObj.IsNull()) {
450       std::ostringstream aPtrStr;
451       aPtrStr << "[" << aAISObj.Access() << "]";
452       anInfo += QString(", selectable(IO): %1").arg(aPtrStr.str().c_str());
453     }
454
455     if (!BROwnr.IsNull() && BROwnr->HasShape()) {
456       const TopoDS_Shape& aShape = BROwnr->Shape();
457       if (aShape.IsNull()) {
458         //Events_Error::throwException("An empty AIS presentation");
459       }
460       else
461         anInfo += QString(", shape type: %1").arg(getShapeTypeInfo(aShape.ShapeType()));
462     }
463     anObjects += anInfo;
464   }
465   QString aValue = QString("activeOwners[%1]").arg(anObjects.size());
466   if (anObjects.size() > 0)
467     aValue += QString(":\n  %1").arg(anObjects.join("\n  "));
468   return aValue;
469 }
470
471 QString selectedOwners(Handle(AIS_InteractiveContext)& theContext, const bool theShapeInfoOnly = true)
472 {
473   QStringList anObjects;
474   if (theContext.IsNull())
475     return "";
476
477   QList<long> aSelectedIds; // Remember of selected address in order to avoid duplicates
478   for (theContext->InitSelected(); theContext->MoreSelected(); theContext->NextSelected()) {
479     Handle(SelectMgr_EntityOwner) anOwner = theContext->SelectedOwner();
480     Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(anOwner);
481     if (theShapeInfoOnly && BROwnr.IsNull())
482       continue;
483
484     if (aSelectedIds.contains((long)anOwner.Access()))
485       continue;
486     aSelectedIds.append((long)anOwner.Access());
487
488     QString anInfo = "Owner";
489     std::ostringstream aPtrStr;
490     aPtrStr << "[" << anOwner.Access() << "]";
491     anInfo += aPtrStr.str().c_str();
492
493     if (!BROwnr.IsNull() && BROwnr->HasShape()) {
494       const TopoDS_Shape& aShape = BROwnr->Shape();
495       anInfo += QString(", shape type = %1").arg(getShapeTypeInfo(aShape.ShapeType()));
496     }
497     anObjects += anInfo;
498   }
499   QString aValue = QString("selectedOwners[%1]").arg(anObjects.size());
500   if (anObjects.size() > 0)
501     aValue += QString(":\n  %1").arg(anObjects.join("\n  "));
502   return aValue;
503 }
504 #endif
505
506 void selectionInfo(Handle(AIS_InteractiveContext)& theContext, const std::string& thePrefix)
507 {
508 #ifdef DEBUG_SELECTION_INFO
509   QString aValue = QString("\n\n\nDEBUG_SELECTION_INFO for '%1'\n%2\n%3\n%4")
510                                               .arg(thePrefix.c_str())
511                                               .arg(displayedInteractiveObjects(theContext))
512                                               .arg(activeOwners(theContext))
513                                               .arg(selectedOwners(theContext));
514   qDebug(aValue.toStdString().c_str());
515 #endif
516 }
517
518 typedef QMap<QString, int> ShapeTypes;
519 static ShapeTypes myShapeTypes;
520
521 int shapeType(const QString& theType)
522 {
523   if (myShapeTypes.count() == 0) {
524     myShapeTypes["compound"]   = TopAbs_COMPOUND;
525     myShapeTypes["compounds"]  = TopAbs_COMPOUND;
526     myShapeTypes["compsolid"]  = TopAbs_COMPSOLID;
527     myShapeTypes["compsolids"] = TopAbs_COMPSOLID;
528     myShapeTypes["solid"]      = TopAbs_SOLID;
529     myShapeTypes["solids"]     = TopAbs_SOLID;
530     myShapeTypes["shell"]      = TopAbs_SHELL;
531     myShapeTypes["shells"]     = TopAbs_SHELL;
532     myShapeTypes["face"]       = TopAbs_FACE;
533     myShapeTypes["faces"]      = TopAbs_FACE;
534     myShapeTypes["wire"]       = TopAbs_WIRE;
535     myShapeTypes["wires"]      = TopAbs_WIRE;
536     myShapeTypes["edge"]       = TopAbs_EDGE;
537     myShapeTypes["edges"]      = TopAbs_EDGE;
538     myShapeTypes["vertex"]     = TopAbs_VERTEX;
539     myShapeTypes["vertices"]   = TopAbs_VERTEX;
540     myShapeTypes["object"]     = ModuleBase_ResultPrs::Sel_Result;
541     myShapeTypes["objects"]    = ModuleBase_ResultPrs::Sel_Result;
542   }
543   QString aType = theType.toLower();
544   if(myShapeTypes.contains(aType))
545     return myShapeTypes[aType];
546   Events_InfoMessage("ModuleBase_Tools", "Shape type defined in XML is not implemented!").send();
547   return TopAbs_SHAPE;
548 }
549
550 void checkObjects(const QObjectPtrList& theObjects, bool& hasResult, bool& hasFeature,
551                   bool& hasParameter, bool& hasCompositeOwner)
552 {
553   hasResult = false;
554   hasFeature = false;
555   hasParameter = false;
556   hasCompositeOwner = false;
557   foreach(ObjectPtr aObj, theObjects) {
558     FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
559     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
560     ResultParameterPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aResult);
561
562     hasResult |= (aResult.get() != NULL);
563     hasFeature |= (aFeature.get() != NULL);
564     hasParameter |= (aConstruction.get() != NULL);
565     if (hasFeature) 
566       hasCompositeOwner |= (ModelAPI_Tools::compositeOwner(aFeature) != NULL);
567     if (hasFeature && hasResult  && hasParameter && hasCompositeOwner)
568       break;
569   }
570 }
571
572 /*bool setDefaultDeviationCoefficient(std::shared_ptr<GeomAPI_Shape> theGeomShape)
573 {
574   if (!theGeomShape.get())
575     return false;
576   // if the shape could not be exploded on faces, it contains only wires, edges, and vertices
577   // correction of deviation for them should not influence to the application performance
578   GeomAPI_ShapeExplorer anExp(theGeomShape, GeomAPI_Shape::FACE);
579   bool anEmpty = anExp.empty();
580   return !anExp.more();
581 }*/
582
583 /*void setDefaultDeviationCoefficient(const std::shared_ptr<ModelAPI_Result>& theResult,
584                                     const Handle(Prs3d_Drawer)& theDrawer)
585 {
586   if (!theResult.get())
587     return;
588   bool aUseDeviation = false;
589
590   std::string aResultGroup = theResult->groupName();
591   if (aResultGroup == ModelAPI_ResultConstruction::group())
592     aUseDeviation = true;
593   else if (aResultGroup == ModelAPI_ResultBody::group()) {
594     GeomShapePtr aGeomShape = theResult->shape();
595     if (aGeomShape.get())
596       aUseDeviation = setDefaultDeviationCoefficient(aGeomShape);
597   }
598   if (aUseDeviation)
599     theDrawer->SetDeviationCoefficient(DEFAULT_DEVIATION_COEFFICIENT);
600 }
601 */
602 void setDefaultDeviationCoefficient(const TopoDS_Shape& theShape,
603                                     const Handle(Prs3d_Drawer)& theDrawer)
604 {
605   if (theShape.IsNull())
606     return;
607
608   std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape());
609   aGeomShape->setImpl(new TopoDS_Shape(theShape));
610
611   // if the shape could not be exploded on faces, it contains only wires, edges, and vertices
612   // correction of deviation for them should not influence to the application performance
613   GeomAPI_ShapeExplorer anExp(aGeomShape, GeomAPI_Shape::FACE);
614   bool isConstruction = !anExp.more();
615
616   double aDeflection;
617   if (isConstruction)
618     aDeflection = Config_PropManager::real("Visualization", "construction_deflection",
619                                            ModelAPI_ResultConstruction::DEFAULT_DEFLECTION());
620   else
621     aDeflection = Config_PropManager::real("Visualization", "body_deflection",
622                                            ModelAPI_ResultBody::DEFAULT_DEFLECTION());
623
624   theDrawer->SetDeviationCoefficient(aDeflection);
625 }
626
627 Quantity_Color color(const std::string& theSection,
628                      const std::string& theName,
629                      const std::string& theDefault)
630 {
631   std::vector<int> aColor = Config_PropManager::color(theSection, theName, theDefault);
632   return Quantity_Color(aColor[0] / 255., aColor[1] / 255., aColor[2] / 255., Quantity_TOC_RGB);
633 }
634
635 ObjectPtr getObject(const AttributePtr& theAttribute)
636 {
637   ObjectPtr anObject;
638   std::string anAttrType = theAttribute->attributeType();
639   if (anAttrType == ModelAPI_AttributeRefAttr::typeId()) {
640     AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
641     if (anAttr != NULL && anAttr->isObject())
642       anObject = anAttr->object();
643   }
644   if (anAttrType == ModelAPI_AttributeSelection::typeId()) {
645     AttributeSelectionPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
646     if (anAttr != NULL)
647       anObject = anAttr->context();
648   }
649   if (anAttrType == ModelAPI_AttributeReference::typeId()) {
650     AttributeReferencePtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
651     if (anAttr.get() != NULL)
652       anObject = anAttr->value();
653   }
654   return anObject;
655 }
656
657 TopAbs_ShapeEnum getCompoundSubType(const TopoDS_Shape& theShape)
658 {
659   TopAbs_ShapeEnum aShapeType = theShape.ShapeType();
660
661   // for compounds check sub-shapes: it may be compound of needed type:
662   // Booleans may produce compounds of Solids
663   if (aShapeType == TopAbs_COMPOUND) {
664     for(TopoDS_Iterator aSubs(theShape); aSubs.More(); aSubs.Next()) {
665       if (!aSubs.Value().IsNull()) {
666         TopAbs_ShapeEnum aSubType = aSubs.Value().ShapeType();
667         if (aSubType == TopAbs_COMPOUND) { // compound of compound(s)
668           aShapeType = TopAbs_COMPOUND;
669           break;
670         }
671         if (aShapeType == TopAbs_COMPOUND) {
672           aShapeType = aSubType;
673         } else if (aShapeType != aSubType) { // compound of shapes of different types
674           aShapeType = TopAbs_COMPOUND;
675           break;
676         }
677       }
678     }
679   }
680   return aShapeType;
681 }
682
683 void getParameters(QStringList& theParameters)
684 {
685   theParameters.clear();
686
687   SessionPtr aSession = ModelAPI_Session::get();
688   std::list<DocumentPtr> aDocList;
689   DocumentPtr anActiveDocument = aSession->activeDocument();
690   DocumentPtr aRootDocument = aSession->moduleDocument();
691   aDocList.push_back(anActiveDocument);
692   if (anActiveDocument != aRootDocument) {
693     aDocList.push_back(aRootDocument);
694   }
695   std::string aGroupId = ModelAPI_ResultParameter::group();
696   for(std::list<DocumentPtr>::const_iterator it = aDocList.begin(); it != aDocList.end(); ++it) {
697     DocumentPtr aDocument = *it;
698     int aSize = aDocument->size(aGroupId);
699     for (int i = 0; i < aSize; i++) {
700       ObjectPtr anObject = aDocument->object(aGroupId, i);
701       std::string aParameterName = anObject->data()->name();
702       theParameters.append(aParameterName.c_str());
703     }
704   }
705 }
706
707 std::string findGreedAttribute(ModuleBase_IWorkshop* theWorkshop, const FeaturePtr& theFeature)
708 {
709   std::string anAttributeId;
710
711   std::string aXmlCfg, aDescription;
712   theWorkshop->module()->getXMLRepresentation(theFeature->getKind(), aXmlCfg, aDescription);
713
714   ModuleBase_WidgetFactory aFactory(aXmlCfg, theWorkshop);
715   std::string anAttributeTitle;
716   aFactory.getGreedAttribute(anAttributeId);
717
718   return anAttributeId;
719 }
720
721 bool hasObject(const AttributePtr& theAttribute, const ObjectPtr& theObject,
722                const std::shared_ptr<GeomAPI_Shape>& theShape,
723                ModuleBase_IWorkshop* theWorkshop,
724                const bool theTemporarily)
725 {
726   bool aHasObject = false;
727   if (!theAttribute.get())
728     return aHasObject;
729
730   std::string aType = theAttribute->attributeType();
731   if (aType == ModelAPI_AttributeReference::typeId()) {
732     AttributeReferencePtr aRef = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
733     ObjectPtr aObject = aRef->value();
734     aHasObject = aObject && aObject->isSame(theObject);
735     //if (!(aObject && aObject->isSame(theObject))) {
736     //  aRef->setValue(theObject);
737     //}
738   } else if (aType == ModelAPI_AttributeRefAttr::typeId()) {
739     AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
740
741     AttributePtr anAttribute = theWorkshop->module()->findAttribute(theObject, theShape);
742     if (anAttribute.get()) {
743       //aRefAttr->setAttr(anAttribute);
744     }
745     else {
746       ObjectPtr aObject = aRefAttr->object();
747       aHasObject = aObject && aObject->isSame(theObject);
748       //if (!(aObject && aObject->isSame(theObject))) {
749       //  aRefAttr->setObject(theObject);
750       //}
751     }
752   } else if (aType == ModelAPI_AttributeSelection::typeId()) {
753     /*AttributeSelectionPtr aSelectAttr =
754                              std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
755     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
756     if (aSelectAttr.get() != NULL) {
757       aSelectAttr->setValue(aResult, theShape, theTemporarily);
758     }*/
759   }
760   if (aType == ModelAPI_AttributeSelectionList::typeId()) {
761     AttributeSelectionListPtr aSelectionListAttr =
762                          std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
763     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
764     aHasObject = aSelectionListAttr->isInList(aResult, theShape, theTemporarily);
765     //if (!theCheckIfAttributeHasObject || !aSelectionListAttr->isInList(aResult, theShape, theTemporarily))
766     //  aSelectionListAttr->append(aResult, theShape, theTemporarily);
767   }
768   else if (aType == ModelAPI_AttributeRefList::typeId()) {
769     AttributeRefListPtr aRefListAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
770     aHasObject = aRefListAttr->isInList(theObject);
771     //if (!theCheckIfAttributeHasObject || !aRefListAttr->isInList(theObject))
772     //  aRefListAttr->append(theObject);
773   }
774   else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
775     AttributeRefAttrListPtr aRefAttrListAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(theAttribute);
776     AttributePtr anAttribute = theWorkshop->module()->findAttribute(theObject, theShape);
777
778     if (anAttribute.get()) {
779       aHasObject = aRefAttrListAttr->isInList(anAttribute);
780       //if (!theCheckIfAttributeHasObject || !aRefAttrListAttr->isInList(anAttribute))
781       //  aRefAttrListAttr->append(anAttribute);
782     }
783     else {
784       aHasObject = aRefAttrListAttr->isInList(theObject);
785       //if (!theCheckIfAttributeHasObject || !aRefAttrListAttr->isInList(theObject))
786       //  aRefAttrListAttr->append(theObject);
787     }
788   }
789   return aHasObject;
790 }
791
792 bool setObject(const AttributePtr& theAttribute, const ObjectPtr& theObject,
793                const GeomShapePtr& theShape, ModuleBase_IWorkshop* theWorkshop,
794                const bool theTemporarily, const bool theCheckIfAttributeHasObject)
795 {
796   if (!theAttribute.get())
797     return false;
798
799   bool isDone = true;
800   std::string aType = theAttribute->attributeType();
801   if (aType == ModelAPI_AttributeReference::typeId()) {
802     AttributeReferencePtr aRef = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
803     ObjectPtr aObject = aRef->value();
804     if (!(aObject && aObject->isSame(theObject))) {
805       aRef->setValue(theObject);
806     }
807   } else if (aType == ModelAPI_AttributeRefAttr::typeId()) {
808     AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
809
810     AttributePtr anAttribute = theWorkshop->module()->findAttribute(theObject, theShape);
811     if (anAttribute.get())
812       aRefAttr->setAttr(anAttribute);
813     else {
814       ObjectPtr aObject = aRefAttr->object();
815       if (!(aObject && aObject->isSame(theObject))) {
816         aRefAttr->setObject(theObject);
817       }
818     }
819   } else if (aType == ModelAPI_AttributeSelection::typeId()) {
820     AttributeSelectionPtr aSelectAttr =
821                              std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
822     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
823     if (aSelectAttr.get() != NULL) {
824       aSelectAttr->setValue(aResult, theShape, theTemporarily);
825     }
826   }
827   if (aType == ModelAPI_AttributeSelectionList::typeId()) {
828     AttributeSelectionListPtr aSelectionListAttr =
829                          std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
830     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
831     if (!theCheckIfAttributeHasObject || !aSelectionListAttr->isInList(aResult, theShape, theTemporarily))
832       aSelectionListAttr->append(aResult, theShape, theTemporarily);
833   }
834   else if (aType == ModelAPI_AttributeRefList::typeId()) {
835     AttributeRefListPtr aRefListAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
836     if (!theCheckIfAttributeHasObject || !aRefListAttr->isInList(theObject)) {
837       if (theObject.get())
838         aRefListAttr->append(theObject);
839       else
840         isDone = false;
841     }
842   }
843   else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
844     AttributeRefAttrListPtr aRefAttrListAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(theAttribute);
845     AttributePtr anAttribute = theWorkshop->module()->findAttribute(theObject, theShape);
846
847     if (anAttribute.get()) {
848       if (!theCheckIfAttributeHasObject || !aRefAttrListAttr->isInList(anAttribute))
849         aRefAttrListAttr->append(anAttribute);
850     }
851     else {
852       if (!theCheckIfAttributeHasObject || !aRefAttrListAttr->isInList(theObject)) {
853         if (theObject.get())
854           aRefAttrListAttr->append(theObject);
855         else
856           isDone = false;
857       }
858     }
859   }
860   return isDone;
861 }
862
863 GeomShapePtr getShape(const AttributePtr& theAttribute, ModuleBase_IWorkshop* theWorkshop)
864 {
865   GeomShapePtr aShape;
866   if (!theAttribute.get())
867     return aShape;
868
869   std::string aType = theAttribute->attributeType();
870   if (aType == ModelAPI_AttributeReference::typeId()) {
871   } else if (aType == ModelAPI_AttributeRefAttr::typeId()) {
872     AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
873     if (aRefAttr.get() && !aRefAttr->isObject()) {
874       AttributePtr anAttribute = aRefAttr->attr();
875       aShape = theWorkshop->module()->findShape(anAttribute);
876     }
877   } else if (aType == ModelAPI_AttributeSelection::typeId()) {
878     AttributeSelectionPtr aSelectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
879                                                                                  (theAttribute);
880     aShape = aSelectAttr->value();
881   }
882   else // Geom2D point processing
883     aShape = theWorkshop->module()->findShape(theAttribute);
884   return aShape;
885 }
886
887 void flushUpdated(ObjectPtr theObject)
888 {
889   blockUpdateViewer(true);
890
891   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
892
893   blockUpdateViewer(false);
894 }
895
896 void blockUpdateViewer(const bool theValue)
897 {
898   // the viewer update should be blocked in order to avoid the temporary feature content
899   // when the solver processes the feature, the redisplay message can be flushed
900   // what caused the display in the viewer preliminary states of object
901   // e.g. fillet feature, angle value change
902   std::shared_ptr<Events_Message> aMsg;
903   if (theValue) {
904     aMsg = std::shared_ptr<Events_Message>(
905         new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_BLOCKED)));
906   }
907   else {
908     // the viewer update should be unblocked
909     aMsg = std::shared_ptr<Events_Message>(
910         new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_UNBLOCKED)));
911   }
912   Events_Loop::loop()->send(aMsg);
913 }
914
915 QString wrapTextByWords(const QString& theValue, QWidget* theWidget,
916                                           int theMaxLineInPixels)
917 {
918   static QFontMetrics tfm(theWidget ? theWidget->font() : QApplication::font());
919   static qreal phi = 2.618;
920
921   QRect aBounds = tfm.boundingRect(theValue);
922   if(aBounds.width() <= theMaxLineInPixels)
923     return theValue;
924
925   qreal s = aBounds.width() * aBounds.height();
926   qreal aGoldWidth = sqrt(s*phi);
927
928   QStringList aWords = theValue.split(" ", QString::SkipEmptyParts);
929   QStringList aLines;
930   int n = aWords.count();
931   QString aLine;
932   for (int i = 0; i < n; i++) {
933     QString aLineExt = aLine + " " + aWords[i];
934     qreal anWidthNonExt = tfm.boundingRect(aLine).width();
935     qreal anWidthExt = tfm.boundingRect(aLineExt).width();
936     qreal aDeltaNonExt = fabs(anWidthNonExt-aGoldWidth);
937     qreal aDeltaExt    = fabs(anWidthExt-aGoldWidth);
938     if(aDeltaNonExt < aDeltaExt) {
939       // new line
940       aLines.append(aLine);
941       aLine = aWords[i];
942     }
943     else
944       aLine = aLineExt;
945   }
946
947   if(!aLine.isEmpty())
948     aLines.append(aLine);
949
950   QString aResult = aLines.join("\n");
951   return aResult;
952 }
953
954 //**************************************************************
955 void refsToFeatureInFeatureDocument(const ObjectPtr& theObject, std::set<FeaturePtr>& theRefFeatures)
956 {
957   FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
958   if (aFeature.get()) {
959     DocumentPtr aFeatureDoc = aFeature->document();
960     // 1. find references in the current document
961     aFeatureDoc->refsToFeature(aFeature, theRefFeatures, false);
962   }
963 }
964
965
966 //**************************************************************
967 /*bool isSubOfComposite(const ObjectPtr& theObject)
968 {
969   bool isSub = false;
970   std::set<FeaturePtr> aRefFeatures;
971   refsToFeatureInFeatureDocument(theObject, aRefFeatures);
972   std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
973                                        aLast = aRefFeatures.end();
974   for (; anIt != aLast && !isSub; anIt++) {
975     isSub = isSubOfComposite(theObject, *anIt);
976   }
977   return isSub;
978 }*/
979
980 //**************************************************************
981 /*bool isSubOfComposite(const ObjectPtr& theObject, const FeaturePtr& theFeature)
982 {
983   bool isSub = false;
984   CompositeFeaturePtr aComposite = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theFeature);
985   if (aComposite.get()) {
986     isSub = aComposite->isSub(theObject);
987     // the recursive is possible, the parameters are sketch circle and extrusion cut. They are
988     // separated by composite sketch feature
989     if (!isSub) {
990       int aNbSubs = aComposite->numberOfSubs();
991       for (int aSub = 0; aSub < aNbSubs && !isSub; aSub++) {
992         isSub = isSubOfComposite(theObject, aComposite->subFeature(aSub));
993       }
994     }
995   }
996   return isSub;
997 }*/
998
999 //**************************************************************
1000 ResultPtr firstResult(const ObjectPtr& theObject)
1001 {
1002   ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1003   if (!aResult.get()) {
1004     FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
1005     if (aFeature.get())
1006       aResult = aFeature->firstResult();
1007   }
1008   return aResult;
1009 }
1010
1011 //**************************************************************
1012 bool isFeatureOfResult(const FeaturePtr& theFeature, const std::string& theGroupOfResult)
1013 {
1014   bool isResult = false;
1015
1016   if (!theFeature->data()->isValid())
1017     return isResult;
1018
1019   ResultPtr aFirstResult = theFeature->firstResult();
1020   if (!aFirstResult.get())
1021     return isResult;
1022
1023   return aFirstResult->groupName() == theGroupOfResult;
1024 }
1025
1026 //**************************************************************
1027 bool hasModuleDocumentFeature(const std::set<FeaturePtr>& theFeatures)
1028 {
1029   bool aFoundModuleDocumentObject = false;
1030   DocumentPtr aModuleDoc = ModelAPI_Session::get()->moduleDocument();
1031
1032   std::set<FeaturePtr>::const_iterator anIt = theFeatures.begin(), aLast = theFeatures.end();
1033   for (; anIt != aLast && !aFoundModuleDocumentObject; anIt++) {
1034     FeaturePtr aFeature = *anIt;
1035     ResultPtr aResult = ModuleBase_Tools::firstResult(aFeature);
1036     if (aResult.get() && aResult->groupName() == ModelAPI_ResultPart::group())
1037       continue;
1038     aFoundModuleDocumentObject = aFeature->document() == aModuleDoc;
1039   }
1040
1041   return aFoundModuleDocumentObject;
1042 }
1043
1044 //**************************************************************
1045 bool askToDelete(const std::set<FeaturePtr> theFeatures,
1046                  const std::map<FeaturePtr, std::set<FeaturePtr> >& theReferences,
1047                  QWidget* theParent,
1048                  std::set<FeaturePtr>& theReferencesToDelete,
1049                  const std::string& thePrefixInfo)
1050 {
1051   QString aNotActivatedDocWrn;
1052   std::string aNotActivatedNames;
1053   if (!ModelAPI_Tools::allDocumentsActivated(aNotActivatedNames)) {
1054     if (ModuleBase_Tools::hasModuleDocumentFeature(theFeatures))
1055       aNotActivatedDocWrn = QObject::tr("Selected objects can be used in Part documents which are not loaded:%1.\n")
1056                             .arg(aNotActivatedNames.c_str());
1057   }
1058   
1059   std::set<FeaturePtr> aFeaturesRefsTo;
1060   std::set<FeaturePtr> aFeaturesRefsToParameter;
1061   std::set<FeaturePtr> aParameterFeatures;
1062   QStringList aPartFeatureNames;
1063   std::set<FeaturePtr>::const_iterator anIt = theFeatures.begin(),
1064                                        aLast = theFeatures.end();
1065   // separate features to references to parameter features and references to others
1066   for (; anIt != aLast; anIt++) {
1067     FeaturePtr aFeature = *anIt;
1068     if (theReferences.find(aFeature) == theReferences.end())
1069       continue;
1070
1071     if (isFeatureOfResult(aFeature, ModelAPI_ResultPart::group()))
1072       aPartFeatureNames.append(aFeature->name().c_str());
1073
1074     std::set<FeaturePtr> aRefFeatures;
1075     std::set<FeaturePtr> aRefList = theReferences.at(aFeature);
1076     std::set<FeaturePtr>::const_iterator aRefIt = aRefList.begin(), aRefLast = aRefList.end();
1077     for (; aRefIt != aRefLast; aRefIt++) {
1078       FeaturePtr aRefFeature = *aRefIt;
1079       if (theFeatures.find(aRefFeature) == theFeatures.end() && // it is not selected
1080           aRefFeatures.find(aRefFeature) == aRefFeatures.end()) // it is not added
1081         aRefFeatures.insert(aRefFeature);
1082     }
1083
1084     if (isFeatureOfResult(aFeature, ModelAPI_ResultParameter::group())) {
1085       aFeaturesRefsToParameter.insert(aRefFeatures.begin(), aRefFeatures.end());
1086       aParameterFeatures.insert(aFeature);
1087     }
1088     else {
1089       theReferencesToDelete.insert(aRefFeatures.begin(), aRefFeatures.end());
1090     }
1091   }
1092
1093   std::set<FeaturePtr> aFeaturesRefsToParameterOnly;
1094   anIt = aFeaturesRefsToParameter.begin();
1095   aLast = aFeaturesRefsToParameter.end();
1096   // separate features to references to parameter features and references to others
1097   QStringList aParamFeatureNames;
1098   for (; anIt != aLast; anIt++) {
1099     FeaturePtr aFeature = *anIt;
1100     if (theReferencesToDelete.find(aFeature) == theReferencesToDelete.end()) {
1101       aFeaturesRefsToParameterOnly.insert(aFeature);
1102       aParamFeatureNames.append(aFeature->name().c_str());
1103     }
1104   }
1105   aParamFeatureNames.sort();
1106   QStringList anOtherFeatureNames;
1107   anIt = theReferencesToDelete.begin();
1108   aLast = theReferencesToDelete.end();
1109   for (; anIt != aLast; anIt++) {
1110     FeaturePtr aFeature = *anIt;
1111     if (isFeatureOfResult(aFeature, ModelAPI_ResultPart::group()))
1112       aPartFeatureNames.append(aFeature->name().c_str());
1113     else
1114       anOtherFeatureNames.append(aFeature->name().c_str());
1115   }
1116   aPartFeatureNames.sort();
1117   anOtherFeatureNames.sort();
1118
1119   bool aCanReplaceParameters = !aFeaturesRefsToParameterOnly.empty();
1120
1121   QMessageBox aMessageBox(theParent);
1122   aMessageBox.setWindowTitle(QObject::tr("Delete features"));
1123   aMessageBox.setIcon(QMessageBox::Warning);
1124   aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
1125   aMessageBox.setDefaultButton(QMessageBox::No);
1126
1127   QString aText;
1128   if (!thePrefixInfo.empty())
1129     aText = thePrefixInfo.c_str();
1130   QString aSep = ", ";
1131   if (!aPartFeatureNames.empty())
1132     aText += QString(QObject::tr("The following parts will be deleted: %1.\n")).arg(aPartFeatureNames.join(aSep));
1133   if (!aNotActivatedDocWrn.isEmpty())
1134     aText += aNotActivatedDocWrn;
1135   if (!anOtherFeatureNames.empty())
1136     aText += QString(QObject::tr("Features are used in the following features: %1.\nThese features will be deleted.\n"))
1137                      .arg(anOtherFeatureNames.join(aSep));
1138   if (!aParamFeatureNames.empty()) {
1139     aText += QString(QObject::tr("Parameters are used in the following features: %1.\nThese features will be deleted.\nOr parameters could be replaced by their values.\n"))
1140                      .arg(aParamFeatureNames.join(aSep));
1141     QPushButton *aReplaceButton = aMessageBox.addButton(QObject::tr("Replace"), QMessageBox::ActionRole);
1142   }
1143
1144   if (!aText.isEmpty()) {
1145     aText += "Would you like to continue?";
1146     aMessageBox.setText(aText);
1147     aMessageBox.exec();
1148     QMessageBox::ButtonRole aButtonRole = aMessageBox.buttonRole(aMessageBox.clickedButton());
1149
1150     if (aButtonRole == QMessageBox::NoRole)
1151       return false;
1152
1153     if (aButtonRole == QMessageBox::ActionRole) {
1154       foreach (FeaturePtr aObj, aParameterFeatures)
1155         ModelAPI_ReplaceParameterMessage::send(aObj, 0);
1156     }
1157     else
1158       theReferencesToDelete.insert(aFeaturesRefsToParameterOnly.begin(), aFeaturesRefsToParameterOnly.end());
1159   }
1160   return true;
1161 }
1162
1163 //**************************************************************
1164 void convertToFeatures(const QObjectPtrList& theObjects, std::set<FeaturePtr>& theFeatures)
1165 {
1166   QObjectPtrList::const_iterator anIt = theObjects.begin(), aLast = theObjects.end();
1167   for(; anIt != aLast; anIt++) {
1168     ObjectPtr anObject = *anIt;
1169     FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
1170     // for parameter result, use the corresponded reature to be removed
1171     if (!aFeature.get() && anObject->groupName() == ModelAPI_ResultParameter::group()) {
1172       aFeature = ModelAPI_Feature::feature(anObject);
1173     }
1174     theFeatures.insert(aFeature);
1175   }
1176 }
1177
1178 void translate(const std::string& theContext, std::string& theMessage)
1179 {
1180   if (!theMessage.empty()) {
1181     std::string aStr = Config_Translator::translate(theContext, theMessage);
1182     if (!aStr.empty()) {
1183       std::string aCodec = Config_Translator::codec(theContext);
1184       theMessage = QTextCodec::codecForName(aCodec.c_str())->toUnicode(aStr.c_str()).toStdString();
1185     }
1186   }
1187 }
1188
1189 void setPointBallHighlighting(AIS_Shape* theAIS)
1190 {
1191   static Handle(Image_AlienPixMap) aPixMap;
1192   if(aPixMap.IsNull()) {
1193     // Load icon for the presentation
1194     std::string aFile;
1195     char* anEnv = getenv("SHAPER_ROOT_DIR");
1196     if(anEnv) {
1197       aFile = std::string(anEnv) +
1198         FSEP + "share" + FSEP + "salome" + FSEP + "resources" + FSEP + "shaper";
1199     } else {
1200       anEnv = getenv("OPENPARTS_ROOT_DIR");
1201       if (anEnv)
1202         aFile = std::string(anEnv) + FSEP + "resources";
1203     }
1204
1205     aFile += FSEP;
1206     static const std::string aMarkerName = "marker_dot.png";
1207     aFile += aMarkerName;
1208     aPixMap = new Image_AlienPixMap();
1209     if(!aPixMap->Load(aFile.c_str())) {
1210       // The icon for constraint is not found
1211       static const std::string aMsg = "Error: Point market not found by path: \"" + aFile + "\". Falling back.";
1212       //Events_InfoMessage("ModuleBase_Tools::setPointBallHighlighting", aMsg).send();
1213     }
1214   }
1215
1216   Handle(Graphic3d_AspectMarker3d) anAspect;
1217   Handle(Prs3d_Drawer) aDrawer = theAIS->HilightAttributes();
1218   if(aDrawer->HasOwnPointAspect()) {
1219     Handle(Prs3d_PointAspect) aPntAspect = aDrawer->PointAspect();
1220     if(aPixMap->IsEmpty()) {
1221       anAspect = aPntAspect->Aspect();
1222       anAspect->SetType(Aspect_TOM_BALL);
1223     } else {
1224       if(aPixMap->Format() == Image_PixMap::ImgGray) {
1225         aPixMap->SetFormat (Image_PixMap::ImgAlpha);
1226       } else if(aPixMap->Format() == Image_PixMap::ImgGrayF) {
1227         aPixMap->SetFormat (Image_PixMap::ImgAlphaF);
1228       }
1229       anAspect = new Graphic3d_AspectMarker3d(aPixMap);
1230       aPntAspect->SetAspect(anAspect);
1231     }
1232     aDrawer->SetPointAspect(aPntAspect);
1233     theAIS->SetHilightAttributes(aDrawer);
1234   }
1235 }
1236
1237 } // namespace ModuleBase_Tools
1238
1239