1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "ModuleBase_Tools.h"
22 #include <ModuleBase_ParamIntSpinBox.h>
23 #include <ModuleBase_ParamSpinBox.h>
24 #include <ModuleBase_WidgetFactory.h>
25 #include <ModuleBase_IWorkshop.h>
26 #include <ModuleBase_IModule.h>
27 #include <ModuleBase_IViewer.h>
28 #include <ModuleBase_IconFactory.h>
29 #include <ModuleBase_ResultPrs.h>
30 #include <ModuleBase_ViewerPrs.h>
32 #include <ModelAPI_Attribute.h>
33 #include <ModelAPI_AttributeRefAttr.h>
34 #include <ModelAPI_AttributeReference.h>
35 #include <ModelAPI_AttributeSelection.h>
36 #include <ModelAPI_AttributeSelectionList.h>
37 #include <ModelAPI_AttributeRefList.h>
38 #include <ModelAPI_AttributeRefAttrList.h>
39 #include <ModelAPI_ResultPart.h>
40 #include <ModelAPI_ResultConstruction.h>
41 #include <ModelAPI_AttributeString.h>
42 #include <ModelAPI_Expression.h>
43 #include <ModelAPI_ResultField.h>
44 #include <Events_Loop.h>
46 #include <ModelAPI_Data.h>
47 #include <ModelAPI_Result.h>
48 #include <ModelAPI_ResultParameter.h>
49 #include <ModelAPI_Tools.h>
50 #include <ModelAPI_Session.h>
51 #include <ModelAPI_Events.h>
52 #include <ModelAPI_Folder.h>
54 #include <ModelGeomAlgo_Point2D.h>
56 #include <StdSelect_BRepOwner.hxx>
57 #include <TopoDS_Iterator.hxx>
58 #include <AIS_InteractiveContext.hxx>
59 #include <Prs3d_LineAspect.hxx>
60 #include <Prs3d_PlaneAspect.hxx>
62 #include <GeomDataAPI_Point2D.h>
63 #include <Events_InfoMessage.h>
64 #include <GeomAPI_ShapeExplorer.h>
66 #include <Config_PropManager.h>
67 #include <Config_Translator.h>
69 #include <Prs3d_PointAspect.hxx>
70 #include <Graphic3d_AspectMarker3d.hxx>
72 #include <Image_AlienPixMap.hxx>
78 #include <QDoubleSpinBox>
79 #include <QGraphicsDropShadowEffect>
81 #include <QApplication>
82 #include <QMessageBox>
92 #pragma warning(disable : 4996) // for getenv
95 const double tolerance = 1e-7;
96 const double DEFAULT_DEVIATION_COEFFICIENT = 1.e-4;
98 //#define DEBUG_ACTIVATE_WINDOW
99 //#define DEBUG_SET_FOCUS
107 namespace ModuleBase_Tools {
109 //******************************************************************
111 //******************************************************************
113 void adjustMargins(QWidget* theWidget)
117 adjustMargins(theWidget->layout());
120 void adjustMargins(QLayout* theLayout)
124 theLayout->setContentsMargins(2, 5, 2, 5);
125 theLayout->setSpacing(4);
128 void zeroMargins(QWidget* theWidget)
132 zeroMargins(theWidget->layout());
135 void zeroMargins(QLayout* theLayout)
139 theLayout->setContentsMargins(0, 0, 0, 0);
140 theLayout->setSpacing(5);
143 void activateWindow(QWidget* theWidget, const QString& theInfo)
146 theWidget->activateWindow();
150 #ifdef DEBUG_ACTIVATE_WINDOW
151 qDebug(QString("activateWindow: %1").arg(theInfo).toStdString().c_str());
155 void setFocus(QWidget* theWidget, const QString& theInfo)
157 theWidget->setFocus();
158 // rectangle of focus is not visible on tool button widgets
160 #ifdef DEBUG_SET_FOCUS
161 qDebug(QString("setFocus: %1").arg(theInfo).toStdString().c_str());
165 void setShadowEffect(QWidget* theWidget, const bool isSetEffect)
168 QGraphicsDropShadowEffect* aGlowEffect = new QGraphicsDropShadowEffect();
169 aGlowEffect->setOffset(.0);
170 aGlowEffect->setBlurRadius(10.0);
171 aGlowEffect->setColor(QColor(0, 170, 255)); // Light-blue color, #00AAFF
172 theWidget->setGraphicsEffect(aGlowEffect);
175 QGraphicsEffect* anEffect = theWidget->graphicsEffect();
177 anEffect->deleteLater();
178 theWidget->setGraphicsEffect(NULL);
182 QPixmap composite(const QString& theAdditionalIcon, const QString& theIcon)
184 QImage anIcon = ModuleBase_IconFactory::loadImage(theIcon);
185 QImage anAditional(theAdditionalIcon);
186 return composite(anAditional, anIcon);
189 QPixmap composite(const QImage& theAdditionalIcon, QImage& theIcon)
191 if (theIcon.isNull())
194 int anAddWidth = theAdditionalIcon.width();
195 int anAddHeight = theAdditionalIcon.height();
197 int aWidth = theIcon.width();
198 int aHeight = theIcon.height();
200 int aStartWidthPos = aWidth - anAddWidth;
201 int aStartHeightPos = aHeight - anAddHeight;
203 for (int i = 0; i < anAddWidth && i + aStartWidthPos < aWidth; i++)
205 for (int j = 0; j < anAddHeight && j + aStartHeightPos < aHeight; j++)
207 if (qAlpha(theAdditionalIcon.pixel(i, j)) > 0)
208 theIcon.setPixel(i + aStartWidthPos, j + aStartHeightPos, theAdditionalIcon.pixel(i, j));
211 return QPixmap::fromImage(theIcon);
214 QPixmap lighter(const QString& theIcon, const int theLighterValue)
216 QImage anIcon = ModuleBase_IconFactory::loadImage(theIcon);
220 QImage aResult = ModuleBase_IconFactory::loadImage(theIcon);
221 for (int i = 0; i < anIcon.width(); i++)
223 for (int j = 0; j < anIcon.height(); j++)
225 QRgb anRgb = anIcon.pixel(i, j);
226 QColor aPixelColor(qRed(anRgb), qGreen(anRgb), qBlue(anRgb),
227 qAlpha(aResult.pixel(i, j)));
229 QColor aLighterColor = aPixelColor.lighter(theLighterValue);
230 aResult.setPixel(i, j, qRgba(aLighterColor.red(), aLighterColor.green(),
231 aLighterColor.blue(), aLighterColor.alpha()));
234 return QPixmap::fromImage(aResult);
237 void setSpinText(ModuleBase_ParamSpinBox* theSpin, const QString& theText)
239 if (theSpin->text() == theText)
241 // In order to avoid extra text setting because it will
242 // reset cursor position in control
243 bool isBlocked = theSpin->blockSignals(true);
244 theSpin->setText(theText);
245 theSpin->blockSignals(isBlocked);
248 void setSpinValue(QDoubleSpinBox* theSpin, double theValue)
250 if (fabs(theSpin->value() - theValue) < tolerance)
252 bool isBlocked = theSpin->blockSignals(true);
253 theSpin->setValue(theValue);
254 theSpin->blockSignals(isBlocked);
257 void setSpinValue(ModuleBase_ParamSpinBox* theSpin, double theValue)
259 if (fabs(theSpin->value() - theValue) < tolerance)
261 bool isBlocked = theSpin->blockSignals(true);
262 theSpin->setValue(theValue);
263 theSpin->blockSignals(isBlocked);
266 void setSpinText(ModuleBase_ParamIntSpinBox* theSpin, const QString& theText)
268 // In order to avoid extra text setting because it will
269 // reset cursor position in control
270 if (theSpin->text() == theText)
272 bool isBlocked = theSpin->blockSignals(true);
273 theSpin->setText(theText);
274 theSpin->blockSignals(isBlocked);
277 void setSpinValue(ModuleBase_ParamIntSpinBox* theSpin, int theValue)
279 if (theSpin->value() == theValue)
281 bool isBlocked = theSpin->blockSignals(true);
282 theSpin->setValue(theValue);
283 theSpin->blockSignals(isBlocked);
286 QAction* createAction(const QIcon& theIcon, const QString& theText,
287 QObject* theParent, const QObject* theReceiver,
288 const char* theMember, const QString& theToolTip,
289 const QString& theStatusTip)
291 QAction* anAction = new QAction(theIcon, theText, theParent);
292 anAction->setToolTip(theToolTip.isEmpty() ? theText : theToolTip);
293 anAction->setStatusTip(!theStatusTip.isEmpty() ? theStatusTip :
294 (!theToolTip.isEmpty() ? theToolTip : theText));
296 QObject::connect(anAction, SIGNAL(triggered(bool)), theReceiver, theMember);
302 QString objectName(const ObjectPtr& theObj)
307 return theObj->data()->name().c_str();
310 QString objectInfo(const ObjectPtr& theObj, const bool isUseAttributesInfo)
312 QString aFeatureStr = "feature";
316 std::ostringstream aPtrStr;
317 aPtrStr << "[" << theObj.get() << "]";
319 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObj);
320 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObj);
322 aFeatureStr.append(QString("(result%1)").arg(aPtrStr.str().c_str()).toStdString() .c_str());
323 if (aRes->isDisabled())
324 aFeatureStr.append("[disabled]");
325 if (aRes->isConcealed())
326 aFeatureStr.append("[concealed]");
327 if (ModelAPI_Tools::hasSubResults(aRes))
328 aFeatureStr.append("[hasSubResults]");
330 aFeature = ModelAPI_Feature::feature(aRes);
333 aFeatureStr.append(aPtrStr.str().c_str());
335 if (aFeature.get()) {
336 aFeatureStr.append(QString(": %1").arg(aFeature->getKind().c_str()).toStdString().c_str());
337 if (aFeature->data()->isValid()) {
338 aFeatureStr.append(QString(", name=%1").arg(theObj->data()->name().c_str()).toStdString()
341 if (isUseAttributesInfo) {
342 std::set<std::shared_ptr<ModelAPI_Attribute> > anAttributes;
343 std::string aPointsInfo = ModelGeomAlgo_Point2D::getPontAttributesInfo(aFeature,
344 anAttributes).c_str();
345 if (!aPointsInfo.empty())
346 aFeatureStr.append(QString(", attributes: %1")
347 .arg(aPointsInfo.c_str()).toStdString().c_str());
355 typedef QMap<QString, int> ShapeTypes;
356 static ShapeTypes myShapeTypes;
358 int shapeType(const QString& theType)
360 if (myShapeTypes.count() == 0) {
361 myShapeTypes["compound"] = TopAbs_COMPOUND;
362 myShapeTypes["compounds"] = TopAbs_COMPOUND;
363 myShapeTypes["compsolid"] = TopAbs_COMPSOLID;
364 myShapeTypes["compsolids"] = TopAbs_COMPSOLID;
365 myShapeTypes["solid"] = TopAbs_SOLID;
366 myShapeTypes["solids"] = TopAbs_SOLID;
367 myShapeTypes["shell"] = TopAbs_SHELL;
368 myShapeTypes["shells"] = TopAbs_SHELL;
369 myShapeTypes["face"] = TopAbs_FACE;
370 myShapeTypes["faces"] = TopAbs_FACE;
371 myShapeTypes["wire"] = TopAbs_WIRE;
372 myShapeTypes["wires"] = TopAbs_WIRE;
373 myShapeTypes["edge"] = TopAbs_EDGE;
374 myShapeTypes["edges"] = TopAbs_EDGE;
375 myShapeTypes["vertex"] = TopAbs_VERTEX;
376 myShapeTypes["vertices"] = TopAbs_VERTEX;
377 myShapeTypes["object"] = ModuleBase_ResultPrs::Sel_Result;
378 myShapeTypes["objects"] = ModuleBase_ResultPrs::Sel_Result;
380 QString aType = theType.toLower();
381 if(myShapeTypes.contains(aType))
382 return myShapeTypes[aType];
383 Events_InfoMessage("ModuleBase_Tools", "Shape type defined in XML is not implemented!").send();
387 void checkObjects(const QObjectPtrList& theObjects, bool& hasResult, bool& hasFeature,
388 bool& hasParameter, bool& hasCompositeOwner, bool& hasResultInHistory,
393 hasParameter = false;
394 hasCompositeOwner = false;
395 hasResultInHistory = false;
397 foreach(ObjectPtr aObj, theObjects) {
398 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
399 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
400 FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(aObj);
401 ResultParameterPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aResult);
402 FieldStepPtr aStep = std::dynamic_pointer_cast<ModelAPI_ResultField::ModelAPI_FieldStep>(aObj);
404 hasResult |= ((aResult.get() != NULL) || (aStep.get() != NULL));
405 hasFeature |= (aFeature.get() != NULL);
406 hasFolder |= (aFolder.get() != NULL);
407 hasParameter |= (aConstruction.get() != NULL);
409 hasCompositeOwner |= (ModelAPI_Tools::compositeOwner(aFeature) != NULL);
410 else if (aResult.get())
411 hasCompositeOwner |= (ModelAPI_Tools::bodyOwner(aResult) != NULL);
413 if (!hasResultInHistory && aResult.get()) {
414 FeaturePtr aFeature = ModelAPI_Feature::feature(aResult);
415 hasResultInHistory = aFeature.get() && aFeature->isInHistory();
418 if (hasFeature && hasResult && hasParameter && hasCompositeOwner)
423 /*bool setDefaultDeviationCoefficient(std::shared_ptr<GeomAPI_Shape> theGeomShape)
425 if (!theGeomShape.get())
427 // if the shape could not be exploded on faces, it contains only wires, edges, and vertices
428 // correction of deviation for them should not influence to the application performance
429 GeomAPI_ShapeExplorer anExp(theGeomShape, GeomAPI_Shape::FACE);
430 bool anEmpty = anExp.empty();
431 return !anExp.more();
434 /*void setDefaultDeviationCoefficient(const std::shared_ptr<ModelAPI_Result>& theResult,
435 const Handle(Prs3d_Drawer)& theDrawer)
437 if (!theResult.get())
439 bool aUseDeviation = false;
441 std::string aResultGroup = theResult->groupName();
442 if (aResultGroup == ModelAPI_ResultConstruction::group())
443 aUseDeviation = true;
444 else if (aResultGroup == ModelAPI_ResultBody::group()) {
445 GeomShapePtr aGeomShape = theResult->shape();
446 if (aGeomShape.get())
447 aUseDeviation = setDefaultDeviationCoefficient(aGeomShape);
450 theDrawer->SetDeviationCoefficient(DEFAULT_DEVIATION_COEFFICIENT);
453 void setDefaultDeviationCoefficient(const TopoDS_Shape& theShape,
454 const Handle(Prs3d_Drawer)& theDrawer)
456 if (theShape.IsNull())
459 std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape());
460 aGeomShape->setImpl(new TopoDS_Shape(theShape));
462 // if the shape could not be exploded on faces, it contains only wires, edges, and vertices
463 // correction of deviation for them should not influence to the application performance
464 GeomAPI_ShapeExplorer anExp(aGeomShape, GeomAPI_Shape::FACE);
465 bool isConstruction = !anExp.more();
469 aDeflection = Config_PropManager::real("Visualization", "construction_deflection");
471 aDeflection = Config_PropManager::real("Visualization", "body_deflection");
473 theDrawer->SetDeviationCoefficient(aDeflection);
476 Quantity_Color color(const std::string& theSection,
477 const std::string& theName)
479 std::vector<int> aColor = Config_PropManager::color(theSection, theName);
480 return Quantity_Color(aColor[0] / 255., aColor[1] / 255., aColor[2] / 255., Quantity_TOC_RGB);
483 ObjectPtr getObject(const AttributePtr& theAttribute)
486 std::string anAttrType = theAttribute->attributeType();
487 if (anAttrType == ModelAPI_AttributeRefAttr::typeId()) {
488 AttributeRefAttrPtr anAttr =
489 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
490 if (anAttr != NULL && anAttr->isObject())
491 anObject = anAttr->object();
493 if (anAttrType == ModelAPI_AttributeSelection::typeId()) {
494 AttributeSelectionPtr anAttr =
495 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
497 anObject = anAttr->context();
499 if (anAttrType == ModelAPI_AttributeReference::typeId()) {
500 AttributeReferencePtr anAttr =
501 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
502 if (anAttr.get() != NULL)
503 anObject = anAttr->value();
508 TopAbs_ShapeEnum getCompoundSubType(const TopoDS_Shape& theShape)
510 TopAbs_ShapeEnum aShapeType = theShape.ShapeType();
512 // for compounds check sub-shapes: it may be compound of needed type:
513 // Booleans may produce compounds of Solids
514 if (aShapeType == TopAbs_COMPOUND) {
515 for(TopoDS_Iterator aSubs(theShape); aSubs.More(); aSubs.Next()) {
516 if (!aSubs.Value().IsNull()) {
517 TopAbs_ShapeEnum aSubType = aSubs.Value().ShapeType();
518 if (aSubType == TopAbs_COMPOUND) { // compound of compound(s)
519 aShapeType = TopAbs_COMPOUND;
522 if (aShapeType == TopAbs_COMPOUND) {
523 aShapeType = aSubType;
524 } else if (aShapeType != aSubType) { // compound of shapes of different types
525 aShapeType = TopAbs_COMPOUND;
534 TopoDS_Shape getSelectedShape(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs)
536 if (thePrs->shape().get())
537 return thePrs->shape()->impl<TopoDS_Shape>();
539 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(thePrs->owner());
540 if (!anOwner.IsNull())
541 return anOwner->Shape();
543 return TopoDS_Shape();
546 void getParameters(QStringList& theParameters)
548 theParameters.clear();
550 SessionPtr aSession = ModelAPI_Session::get();
551 std::list<DocumentPtr> aDocList;
552 DocumentPtr anActiveDocument = aSession->activeDocument();
553 DocumentPtr aRootDocument = aSession->moduleDocument();
554 aDocList.push_back(anActiveDocument);
555 if (anActiveDocument != aRootDocument) {
556 aDocList.push_back(aRootDocument);
558 std::string aGroupId = ModelAPI_ResultParameter::group();
559 for(std::list<DocumentPtr>::const_iterator it = aDocList.begin(); it != aDocList.end(); ++it) {
560 DocumentPtr aDocument = *it;
561 int aSize = aDocument->size(aGroupId);
562 for (int i = 0; i < aSize; i++) {
563 ObjectPtr anObject = aDocument->object(aGroupId, i);
564 std::string aParameterName = anObject->data()->name();
565 theParameters.append(aParameterName.c_str());
570 std::string findGreedAttribute(ModuleBase_IWorkshop* theWorkshop,
571 const FeaturePtr& theFeature)
573 std::string anAttributeId;
575 std::string aXmlCfg, aDescription;
576 theWorkshop->module()->getXMLRepresentation(theFeature->getKind(), aXmlCfg, aDescription);
578 ModuleBase_WidgetFactory aFactory(aXmlCfg, theWorkshop);
579 std::string anAttributeTitle;
580 aFactory.getGreedAttribute(anAttributeId);
582 return anAttributeId;
585 bool hasObject(const AttributePtr& theAttribute, const ObjectPtr& theObject,
586 const std::shared_ptr<GeomAPI_Shape>& theShape,
587 ModuleBase_IWorkshop* theWorkshop,
588 const bool theTemporarily)
590 bool aHasObject = false;
591 if (!theAttribute.get())
594 std::string aType = theAttribute->attributeType();
595 if (aType == ModelAPI_AttributeReference::typeId()) {
596 AttributeReferencePtr aRef =
597 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
598 ObjectPtr aObject = aRef->value();
599 aHasObject = aObject && aObject->isSame(theObject);
600 //if (!(aObject && aObject->isSame(theObject))) {
601 // aRef->setValue(theObject);
603 } else if (aType == ModelAPI_AttributeRefAttr::typeId()) {
604 AttributeRefAttrPtr aRefAttr =
605 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
607 AttributePtr anAttribute = theWorkshop->module()->findAttribute(theObject, theShape);
608 if (anAttribute.get()) {
609 //aRefAttr->setAttr(anAttribute);
612 ObjectPtr aObject = aRefAttr->object();
613 aHasObject = aObject && aObject->isSame(theObject);
614 //if (!(aObject && aObject->isSame(theObject))) {
615 // aRefAttr->setObject(theObject);
618 } else if (aType == ModelAPI_AttributeSelection::typeId()) {
619 /*AttributeSelectionPtr aSelectAttr =
620 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
621 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
622 if (aSelectAttr.get() != NULL) {
623 aSelectAttr->setValue(aResult, theShape, theTemporarily);
626 if (aType == ModelAPI_AttributeSelectionList::typeId()) {
627 AttributeSelectionListPtr aSelectionListAttr =
628 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
629 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
630 aHasObject = aSelectionListAttr->isInList(aResult, theShape, theTemporarily);
632 else if (aType == ModelAPI_AttributeRefList::typeId()) {
633 AttributeRefListPtr aRefListAttr =
634 std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
635 aHasObject = aRefListAttr->isInList(theObject);
636 //if (!theCheckIfAttributeHasObject || !aRefListAttr->isInList(theObject))
637 // aRefListAttr->append(theObject);
639 else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
640 AttributeRefAttrListPtr aRefAttrListAttr =
641 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(theAttribute);
642 AttributePtr anAttribute = theWorkshop->module()->findAttribute(theObject, theShape);
644 if (anAttribute.get()) {
645 aHasObject = aRefAttrListAttr->isInList(anAttribute);
646 //if (!theCheckIfAttributeHasObject || !aRefAttrListAttr->isInList(anAttribute))
647 // aRefAttrListAttr->append(anAttribute);
650 aHasObject = aRefAttrListAttr->isInList(theObject);
651 //if (!theCheckIfAttributeHasObject || !aRefAttrListAttr->isInList(theObject))
652 // aRefAttrListAttr->append(theObject);
658 bool setObject(const AttributePtr& theAttribute, const ObjectPtr& theObject,
659 const GeomShapePtr& theShape, ModuleBase_IWorkshop* theWorkshop,
660 const bool theTemporarily, const bool theCheckIfAttributeHasObject)
662 if (!theAttribute.get())
666 std::string aType = theAttribute->attributeType();
667 if (aType == ModelAPI_AttributeReference::typeId()) {
668 AttributeReferencePtr aRef =
669 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
670 ObjectPtr aObject = aRef->value();
671 if (!(aObject && aObject->isSame(theObject))) {
672 aRef->setValue(theObject);
674 } else if (aType == ModelAPI_AttributeRefAttr::typeId()) {
675 AttributeRefAttrPtr aRefAttr =
676 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
678 AttributePtr anAttribute = theWorkshop->module()->findAttribute(theObject, theShape);
679 if (anAttribute.get())
680 aRefAttr->setAttr(anAttribute);
682 ObjectPtr aObject = aRefAttr->object();
683 if (!(aObject && aObject->isSame(theObject))) {
684 aRefAttr->setObject(theObject);
687 } else if (aType == ModelAPI_AttributeSelection::typeId()) {
688 AttributeSelectionPtr aSelectAttr =
689 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
690 if (aSelectAttr.get() != NULL) {
691 aSelectAttr->setValue(theObject, theShape, theTemporarily);
694 if (aType == ModelAPI_AttributeSelectionList::typeId()) {
695 AttributeSelectionListPtr aSelectionListAttr =
696 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
697 if (!theCheckIfAttributeHasObject ||
698 !aSelectionListAttr->isInList(theObject, theShape, theTemporarily))
699 aSelectionListAttr->append(theObject, theShape, theTemporarily);
701 else if (aType == ModelAPI_AttributeRefList::typeId()) {
702 AttributeRefListPtr aRefListAttr =
703 std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
704 if (!theCheckIfAttributeHasObject || !aRefListAttr->isInList(theObject)) {
706 aRefListAttr->append(theObject);
711 else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
712 AttributeRefAttrListPtr aRefAttrListAttr =
713 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(theAttribute);
714 AttributePtr anAttribute = theWorkshop->module()->findAttribute(theObject, theShape);
716 if (anAttribute.get()) {
717 if (!theCheckIfAttributeHasObject || !aRefAttrListAttr->isInList(anAttribute))
718 aRefAttrListAttr->append(anAttribute);
721 if (!theCheckIfAttributeHasObject || !aRefAttrListAttr->isInList(theObject)) {
723 aRefAttrListAttr->append(theObject);
732 GeomShapePtr getShape(const AttributePtr& theAttribute, ModuleBase_IWorkshop* theWorkshop)
735 if (!theAttribute.get())
738 std::string aType = theAttribute->attributeType();
739 if (aType == ModelAPI_AttributeReference::typeId()) {
740 } else if (aType == ModelAPI_AttributeRefAttr::typeId()) {
741 AttributeRefAttrPtr aRefAttr =
742 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
743 if (aRefAttr.get() && !aRefAttr->isObject()) {
744 AttributePtr anAttribute = aRefAttr->attr();
745 aShape = theWorkshop->module()->findShape(anAttribute);
747 } else if (aType == ModelAPI_AttributeSelection::typeId()) {
748 AttributeSelectionPtr aSelectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
750 aShape = aSelectAttr->value();
752 else // Geom2D point processing
753 aShape = theWorkshop->module()->findShape(theAttribute);
757 void flushUpdated(ObjectPtr theObject)
759 blockUpdateViewer(true);
761 // Fix the problem of not previewed results of constraints applied. Flush Create/Delete
762 // (for the sketch result) to start processing of the sketch in the solver.
763 // TODO: these flushes should be moved in a separate method provided by Model
764 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
765 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
766 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
768 blockUpdateViewer(false);
771 void blockUpdateViewer(const bool theValue)
773 // the viewer update should be blocked in order to avoid the temporary feature content
774 // when the solver processes the feature, the redisplay message can be flushed
775 // what caused the display in the viewer preliminary states of object
776 // e.g. fillet feature, angle value change
777 std::shared_ptr<Events_Message> aMsg;
779 aMsg = std::shared_ptr<Events_Message>(
780 new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_BLOCKED)));
783 // the viewer update should be unblocked
784 aMsg = std::shared_ptr<Events_Message>(
785 new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_UNBLOCKED)));
787 Events_Loop::loop()->send(aMsg);
790 QString wrapTextByWords(const QString& theValue, QWidget* theWidget,
791 int theMaxLineInPixels)
793 static QFontMetrics tfm(theWidget ? theWidget->font() : QApplication::font());
794 static qreal phi = 2.618;
796 QRect aBounds = tfm.boundingRect(theValue);
797 if(aBounds.width() <= theMaxLineInPixels)
800 qreal s = aBounds.width() * aBounds.height();
801 qreal aGoldWidth = sqrt(s*phi);
803 QStringList aWords = theValue.split(" ", QString::SkipEmptyParts);
805 int n = aWords.count();
807 for (int i = 0; i < n; i++) {
808 QString aLineExt = i == 0 ? aWords[i] : aLine + " " + aWords[i];
809 qreal anWidthNonExt = tfm.boundingRect(aLine).width();
810 qreal anWidthExt = tfm.boundingRect(aLineExt).width();
811 qreal aDeltaNonExt = fabs(anWidthNonExt-aGoldWidth);
812 qreal aDeltaExt = fabs(anWidthExt-aGoldWidth);
813 if(aDeltaNonExt < aDeltaExt) {
815 aLines.append(aLine);
823 aLines.append(aLine);
825 QString aResult = aLines.join("\n");
829 //**************************************************************
830 QLocale doubleLocale()
832 // VSR 01/07/2010: Disable thousands separator for spin box
833 // (to avoid inconsistency of double-2-string and string-2-double conversion)
835 aLocale.setNumberOptions(aLocale.numberOptions() |
836 QLocale::OmitGroupSeparator |
837 QLocale::RejectGroupSeparator);
841 //**************************************************************
842 void refsToFeatureInFeatureDocument(const ObjectPtr& theObject,
843 std::set<FeaturePtr>& theRefFeatures)
845 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
846 if (aFeature.get()) {
847 DocumentPtr aFeatureDoc = aFeature->document();
848 // 1. find references in the current document
849 aFeatureDoc->refsToFeature(aFeature, theRefFeatures, false);
854 //**************************************************************
855 /*bool isSubOfComposite(const ObjectPtr& theObject)
858 std::set<FeaturePtr> aRefFeatures;
859 refsToFeatureInFeatureDocument(theObject, aRefFeatures);
860 std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
861 aLast = aRefFeatures.end();
862 for (; anIt != aLast && !isSub; anIt++) {
863 isSub = isSubOfComposite(theObject, *anIt);
868 //**************************************************************
869 /*bool isSubOfComposite(const ObjectPtr& theObject, const FeaturePtr& theFeature)
872 CompositeFeaturePtr aComposite = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theFeature);
873 if (aComposite.get()) {
874 isSub = aComposite->isSub(theObject);
875 // the recursive is possible, the parameters are sketch circle and extrusion cut. They are
876 // separated by composite sketch feature
878 int aNbSubs = aComposite->numberOfSubs();
879 for (int aSub = 0; aSub < aNbSubs && !isSub; aSub++) {
880 isSub = isSubOfComposite(theObject, aComposite->subFeature(aSub));
887 //**************************************************************
888 ResultPtr firstResult(const ObjectPtr& theObject)
890 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
891 if (!aResult.get()) {
892 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
894 aResult = aFeature->firstResult();
899 //**************************************************************
900 bool isFeatureOfResult(const FeaturePtr& theFeature, const std::string& theGroupOfResult)
902 bool isResult = false;
904 if (!theFeature->data()->isValid())
907 ResultPtr aFirstResult = theFeature->firstResult();
908 if (!aFirstResult.get())
911 return aFirstResult->groupName() == theGroupOfResult;
914 //**************************************************************
915 bool hasModuleDocumentFeature(const std::set<FeaturePtr>& theFeatures)
917 bool aFoundModuleDocumentObject = false;
918 DocumentPtr aModuleDoc = ModelAPI_Session::get()->moduleDocument();
920 std::set<FeaturePtr>::const_iterator anIt = theFeatures.begin(), aLast = theFeatures.end();
921 for (; anIt != aLast && !aFoundModuleDocumentObject; anIt++) {
922 FeaturePtr aFeature = *anIt;
923 ResultPtr aResult = ModuleBase_Tools::firstResult(aFeature);
924 if (aResult.get() && aResult->groupName() == ModelAPI_ResultPart::group())
926 aFoundModuleDocumentObject = aFeature->document() == aModuleDoc;
929 return aFoundModuleDocumentObject;
932 //**************************************************************
933 bool askToDelete(const std::set<FeaturePtr> theFeatures,
934 const std::map<FeaturePtr, std::set<FeaturePtr> >& theReferences,
936 std::set<FeaturePtr>& theReferencesToDelete,
937 const std::string& thePrefixInfo)
939 QString aNotActivatedDocWrn;
940 std::string aNotActivatedNames;
941 if (!ModelAPI_Tools::allDocumentsActivated(aNotActivatedNames)) {
942 if (ModuleBase_Tools::hasModuleDocumentFeature(theFeatures))
943 aNotActivatedDocWrn =
944 QObject::tr("Selected objects can be used in Part documents which are not loaded: %1.\n")
945 .arg(aNotActivatedNames.c_str());
948 std::set<FeaturePtr> aFeaturesRefsTo;
949 std::set<FeaturePtr> aFeaturesRefsToParameter;
950 std::set<FeaturePtr> aParameterFeatures;
951 QStringList aPartFeatureNames;
952 std::set<FeaturePtr>::const_iterator anIt = theFeatures.begin(),
953 aLast = theFeatures.end();
954 // separate features to references to parameter features and references to others
955 for (; anIt != aLast; anIt++) {
956 FeaturePtr aFeature = *anIt;
957 if (theReferences.find(aFeature) == theReferences.end())
960 if (isFeatureOfResult(aFeature, ModelAPI_ResultPart::group()))
961 aPartFeatureNames.append(aFeature->name().c_str());
963 std::set<FeaturePtr> aRefFeatures;
964 std::set<FeaturePtr> aRefList = theReferences.at(aFeature);
965 std::set<FeaturePtr>::const_iterator aRefIt = aRefList.begin(), aRefLast = aRefList.end();
966 for (; aRefIt != aRefLast; aRefIt++) {
967 FeaturePtr aRefFeature = *aRefIt;
968 if (theFeatures.find(aRefFeature) == theFeatures.end() && // it is not selected
969 aRefFeatures.find(aRefFeature) == aRefFeatures.end()) // it is not added
970 aRefFeatures.insert(aRefFeature);
973 if (isFeatureOfResult(aFeature, ModelAPI_ResultParameter::group())) {
974 aFeaturesRefsToParameter.insert(aRefFeatures.begin(), aRefFeatures.end());
975 aParameterFeatures.insert(aFeature);
978 theReferencesToDelete.insert(aRefFeatures.begin(), aRefFeatures.end());
982 std::set<FeaturePtr> aFeaturesRefsToParameterOnly;
983 anIt = aFeaturesRefsToParameter.begin();
984 aLast = aFeaturesRefsToParameter.end();
985 // separate features to references to parameter features and references to others
986 QStringList aParamFeatureNames;
987 for (; anIt != aLast; anIt++) {
988 FeaturePtr aFeature = *anIt;
989 if (theReferencesToDelete.find(aFeature) == theReferencesToDelete.end()) {
990 aFeaturesRefsToParameterOnly.insert(aFeature);
991 aParamFeatureNames.append(aFeature->name().c_str());
994 aParamFeatureNames.sort();
995 QStringList anOtherFeatureNames;
996 anIt = theReferencesToDelete.begin();
997 aLast = theReferencesToDelete.end();
998 for (; anIt != aLast; anIt++) {
999 FeaturePtr aFeature = *anIt;
1000 if (aFeature->getKind() == "RemoveResults")
1001 continue; // skip the remove results feature mentioning: result will be removed anyway
1002 if (isFeatureOfResult(aFeature, ModelAPI_ResultPart::group()))
1003 aPartFeatureNames.append(aFeature->name().c_str());
1005 anOtherFeatureNames.append(aFeature->name().c_str());
1007 aPartFeatureNames.sort();
1008 anOtherFeatureNames.sort();
1010 bool aCanReplaceParameters = !aFeaturesRefsToParameterOnly.empty();
1012 QMessageBox aMessageBox(theParent);
1013 aMessageBox.setWindowTitle(QObject::tr("Delete features"));
1014 aMessageBox.setIcon(QMessageBox::Warning);
1015 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
1016 aMessageBox.setDefaultButton(QMessageBox::No);
1019 if (!thePrefixInfo.empty())
1020 aText = thePrefixInfo.c_str();
1021 QString aSep = ", ";
1022 if (!aPartFeatureNames.empty()) {
1023 aText += QString(QObject::tr("The following parts will be deleted: %1.\n"))
1024 .arg(aPartFeatureNames.join(aSep));
1026 if (!aNotActivatedDocWrn.isEmpty())
1027 aText += aNotActivatedDocWrn;
1028 if (!anOtherFeatureNames.empty()) {
1029 const char* aMsg = "Features are used in the following features: %1.\nThese "
1030 "features will be deleted.\n";
1031 aText += QString(QObject::tr(aMsg))
1032 .arg(anOtherFeatureNames.join(aSep));
1034 if (!aParamFeatureNames.empty()) {
1035 const char* aMsg = "Parameters are used directly and through a sequence "
1036 "of dependencies in the following features: %1.\nThese features will "
1037 "be deleted.\nOr parameters could be replaced by their values.\n";
1038 aText += QString(QObject::tr(aMsg))
1039 .arg(aParamFeatureNames.join(aSep));
1040 QPushButton *aReplaceButton =
1041 aMessageBox.addButton(QObject::tr("Replace"), QMessageBox::ActionRole);
1044 if (!aText.isEmpty()) {
1045 aText += "Would you like to continue?";
1046 aMessageBox.setText(aText);
1048 QMessageBox::ButtonRole aButtonRole = aMessageBox.buttonRole(aMessageBox.clickedButton());
1050 if (aButtonRole == QMessageBox::NoRole)
1053 if (aButtonRole == QMessageBox::ActionRole) {
1054 foreach (FeaturePtr aObj, aParameterFeatures)
1055 ModelAPI_ReplaceParameterMessage::send(aObj, 0);
1058 theReferencesToDelete.insert(aFeaturesRefsToParameterOnly.begin(),
1059 aFeaturesRefsToParameterOnly.end());
1064 //**************************************************************
1065 void convertToFeatures(const QObjectPtrList& theObjects, std::set<FeaturePtr>& theFeatures)
1067 QObjectPtrList::const_iterator anIt = theObjects.begin(), aLast = theObjects.end();
1068 for(; anIt != aLast; anIt++) {
1069 ObjectPtr anObject = *anIt;
1070 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
1071 // for parameter result, use the corresponded reature to be removed
1072 if (!aFeature.get() && anObject->groupName() == ModelAPI_ResultParameter::group()) {
1073 aFeature = ModelAPI_Feature::feature(anObject);
1076 theFeatures.insert(aFeature);
1080 //**************************************************************
1081 void convertToFolders(const QObjectPtrList& theObjects,
1082 std::set<FolderPtr>& theFolders)
1084 QObjectPtrList::const_iterator anIt = theObjects.begin(), aLast = theObjects.end();
1085 for(; anIt != aLast; anIt++) {
1086 ObjectPtr anObject = *anIt;
1087 FolderPtr aFeature = std::dynamic_pointer_cast<ModelAPI_Folder>(anObject);
1089 theFolders.insert(aFeature);
1094 //**************************************************************
1095 QString translate(const Events_InfoMessage& theMessage)
1099 if (!theMessage.empty()) {
1100 std::string aStr = Config_Translator::translate(theMessage);
1101 if (!aStr.empty()) {
1102 std::string aCodec = Config_Translator::codec(theMessage);
1103 aMessage = QTextCodec::codecForName(aCodec.c_str())->toUnicode(aStr.c_str());
1110 QString translate(const std::string& theContext, const std::string& theMessage)
1114 if (!theMessage.empty()) {
1115 std::string aStr = Config_Translator::translate(theContext, theMessage);
1116 if (!aStr.empty()) {
1117 std::string aCodec = Config_Translator::codec(theContext);
1118 aMessage = QTextCodec::codecForName(aCodec.c_str())->toUnicode(aStr.c_str());
1125 void setPointBallHighlighting(AIS_Shape* theAIS)
1127 static Handle(Image_AlienPixMap) aPixMap;
1128 if(aPixMap.IsNull()) {
1129 // Load icon for the presentation
1131 char* anEnv = getenv("SHAPER_ROOT_DIR");
1133 aFile = std::string(anEnv) +
1134 FSEP + "share" + FSEP + "salome" + FSEP + "resources" + FSEP + "shaper";
1136 anEnv = getenv("CADBUILDER_ROOT_DIR");
1138 aFile = std::string(anEnv) + FSEP + "resources";
1142 static const std::string aMarkerName = "marker_dot.png";
1143 aFile += aMarkerName;
1144 aPixMap = new Image_AlienPixMap();
1145 if(!aPixMap->Load(aFile.c_str())) {
1146 // The icon for constraint is not found
1147 static const std::string aMsg =
1148 "Error: Point market not found by path: \"" + aFile + "\". Falling back.";
1149 //Events_InfoMessage("ModuleBase_Tools::setPointBallHighlighting", aMsg).send();
1153 Handle(Graphic3d_AspectMarker3d) anAspect;
1154 Handle(Prs3d_Drawer) aDrawer = theAIS->DynamicHilightAttributes();
1155 if (aDrawer.IsNull()) {
1156 if (ModuleBase_IViewer::DefaultHighlightDrawer.IsNull())
1158 aDrawer = new Prs3d_Drawer(*ModuleBase_IViewer::DefaultHighlightDrawer);
1159 if (!aDrawer->HasOwnPointAspect()) {
1160 aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_BALL, Quantity_NOC_BLACK, 2.0));
1163 if(aDrawer->HasOwnPointAspect()) {
1164 Handle(Prs3d_PointAspect) aPntAspect = aDrawer->PointAspect();
1165 if(aPixMap->IsEmpty()) {
1166 anAspect = aPntAspect->Aspect();
1167 anAspect->SetType(Aspect_TOM_BALL);
1169 if(aPixMap->Format() == Image_PixMap::ImgGray) {
1170 aPixMap->SetFormat (Image_PixMap::ImgAlpha);
1171 } else if(aPixMap->Format() == Image_PixMap::ImgGrayF) {
1172 aPixMap->SetFormat (Image_PixMap::ImgAlphaF);
1174 anAspect = new Graphic3d_AspectMarker3d(aPixMap);
1175 aPntAspect->SetAspect(anAspect);
1177 aDrawer->SetPointAspect(aPntAspect);
1178 theAIS->SetDynamicHilightAttributes(aDrawer);
1182 FeaturePtr createParameter(const QString& theText)
1184 FeaturePtr aParameter;
1185 QStringList aList = theText.split("=");
1186 if (aList.count() != 2) {
1189 QString aParamName = aList.at(0).trimmed();
1191 if (isNameExist(aParamName, FeaturePtr())) {
1195 if (!ModelAPI_Expression::isVariable(aParamName.toStdString())) {
1199 QString aExpression = aList.at(1).trimmed();
1200 if (aExpression.isEmpty()) {
1204 SessionPtr aMgr = ModelAPI_Session::get();
1205 std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
1207 aParameter = aDoc->addFeature("Parameter");
1208 if (aParameter.get()) {
1209 AttributeStringPtr aNameAttr = aParameter->string("variable");
1210 aNameAttr->setValue(aParamName.toStdString());
1212 AttributeStringPtr aExprAttr = aParameter->string("expression");
1213 aExprAttr->setValue(aExpression.toStdString());
1214 aParameter->execute();
1216 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1217 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
1222 void editParameter(FeaturePtr theParam, const QString& theText)
1224 QStringList aList = theText.split("=");
1225 QString aParamName = aList.at(0).trimmed();
1227 QString aExpression = aList.at(1).trimmed();
1228 if (aExpression.isEmpty()) {
1232 if (isNameExist(aParamName, theParam)) {
1235 AttributeStringPtr aNameAttr = theParam->string("variable");
1236 aNameAttr->setValue(aParamName.toStdString());
1238 AttributeStringPtr aExprAttr = theParam->string("expression");
1239 aExprAttr->setValue(aExpression.toStdString());
1240 theParam->execute();
1242 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
1245 bool isNameExist(const QString& theName, FeaturePtr theIgnoreParameter)
1247 SessionPtr aMgr = ModelAPI_Session::get();
1248 std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
1249 FeaturePtr aParamFeature;
1250 int aNbFeatures = aDoc->numInternalFeatures();
1251 std::string aName = theName.toStdString();
1252 for (int i = 0; i < aNbFeatures; i++) {
1253 aParamFeature = aDoc->internalFeature(i);
1254 if (aParamFeature && aParamFeature->getKind() == "Parameter") {
1255 if ((theIgnoreParameter != aParamFeature) && (aParamFeature->name() == aName))
1262 FeaturePtr findParameter(const QString& theName)
1264 SessionPtr aMgr = ModelAPI_Session::get();
1265 std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
1266 FeaturePtr aParamFeature;
1267 int aNbFeatures = aDoc->numInternalFeatures();
1268 std::string aName = theName.toStdString();
1269 for (int i = 0; i < aNbFeatures; i++) {
1270 aParamFeature = aDoc->internalFeature(i);
1271 if (aParamFeature && aParamFeature->getKind() == "Parameter") {
1272 if (aParamFeature->name() == aName)
1273 return aParamFeature;
1276 return FeaturePtr();
1280 //********************************************************************
1281 std::string generateName(const AttributePtr& theAttribute,
1282 ModuleBase_IWorkshop* theWorkshop)
1285 if (theAttribute.get() != NULL) {
1286 ModuleBase_Operation* anOperation = theWorkshop->currentOperation();
1288 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
1289 if (aFeature.get()) {
1290 std::string aXmlCfg, aDescription;
1291 theWorkshop->module()->getXMLRepresentation(aFeature->getKind(), aXmlCfg, aDescription);
1293 ModuleBase_WidgetFactory aFactory(aXmlCfg, theWorkshop);
1294 std::string anAttributeTitle;
1295 aFactory.getAttributeTitle(theAttribute->id(), anAttributeTitle);
1297 std::stringstream aStreamName;
1298 aStreamName << theAttribute->owner()->data()->name() << "/" << anAttributeTitle.c_str();
1299 aName = aStreamName.str();
1305 bool isSameShape(const TopoDS_Shape& theShape1, const TopoDS_Shape& theShape2)
1307 // In case of compound we cannot rely on simple comparison method.
1308 // If the compound is generated by Group feature then this compound is alwais new.
1309 // So, we have to compare content of these compounds
1310 if (theShape1.ShapeType() != theShape2.ShapeType())
1313 if (theShape1.ShapeType() != TopAbs_COMPOUND)
1314 return theShape1.IsSame(theShape2);
1316 TopoDS_Iterator aIt1(theShape1);
1317 TopoDS_Iterator aIt2(theShape2);
1319 for (; aIt1.More() && aIt2.More(); aIt1.Next(), aIt2.Next()) {
1320 if (!(aIt1.Value()).IsSame(aIt2.Value()))
1326 qreal currentPixelRatio()
1328 QWindowList aWnds = qApp->topLevelWindows();
1329 if (aWnds.size() > 0)
1330 return aWnds.first()->devicePixelRatio();
1331 return qApp->primaryScreen()->devicePixelRatio();
1335 } // namespace ModuleBase_Tools