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