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);
411 if (!hasResultInHistory && aResult.get()) {
412 FeaturePtr aFeature = ModelAPI_Feature::feature(aResult);
413 hasResultInHistory = aFeature.get() && aFeature->isInHistory();
416 if (hasFeature && hasResult && hasParameter && hasCompositeOwner && hasFeature)
421 /*bool setDefaultDeviationCoefficient(std::shared_ptr<GeomAPI_Shape> theGeomShape)
423 if (!theGeomShape.get())
425 // if the shape could not be exploded on faces, it contains only wires, edges, and vertices
426 // correction of deviation for them should not influence to the application performance
427 GeomAPI_ShapeExplorer anExp(theGeomShape, GeomAPI_Shape::FACE);
428 bool anEmpty = anExp.empty();
429 return !anExp.more();
432 /*void setDefaultDeviationCoefficient(const std::shared_ptr<ModelAPI_Result>& theResult,
433 const Handle(Prs3d_Drawer)& theDrawer)
435 if (!theResult.get())
437 bool aUseDeviation = false;
439 std::string aResultGroup = theResult->groupName();
440 if (aResultGroup == ModelAPI_ResultConstruction::group())
441 aUseDeviation = true;
442 else if (aResultGroup == ModelAPI_ResultBody::group()) {
443 GeomShapePtr aGeomShape = theResult->shape();
444 if (aGeomShape.get())
445 aUseDeviation = setDefaultDeviationCoefficient(aGeomShape);
448 theDrawer->SetDeviationCoefficient(DEFAULT_DEVIATION_COEFFICIENT);
451 void setDefaultDeviationCoefficient(const TopoDS_Shape& theShape,
452 const Handle(Prs3d_Drawer)& theDrawer)
454 if (theShape.IsNull())
457 std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape());
458 aGeomShape->setImpl(new TopoDS_Shape(theShape));
460 // if the shape could not be exploded on faces, it contains only wires, edges, and vertices
461 // correction of deviation for them should not influence to the application performance
462 GeomAPI_ShapeExplorer anExp(aGeomShape, GeomAPI_Shape::FACE);
463 bool isConstruction = !anExp.more();
467 aDeflection = Config_PropManager::real("Visualization", "construction_deflection");
469 aDeflection = Config_PropManager::real("Visualization", "body_deflection");
471 theDrawer->SetDeviationCoefficient(aDeflection);
474 Quantity_Color color(const std::string& theSection,
475 const std::string& theName)
477 std::vector<int> aColor = Config_PropManager::color(theSection, theName);
478 return Quantity_Color(aColor[0] / 255., aColor[1] / 255., aColor[2] / 255., Quantity_TOC_RGB);
481 ObjectPtr getObject(const AttributePtr& theAttribute)
484 std::string anAttrType = theAttribute->attributeType();
485 if (anAttrType == ModelAPI_AttributeRefAttr::typeId()) {
486 AttributeRefAttrPtr anAttr =
487 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
488 if (anAttr != NULL && anAttr->isObject())
489 anObject = anAttr->object();
491 if (anAttrType == ModelAPI_AttributeSelection::typeId()) {
492 AttributeSelectionPtr anAttr =
493 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
495 anObject = anAttr->context();
497 if (anAttrType == ModelAPI_AttributeReference::typeId()) {
498 AttributeReferencePtr anAttr =
499 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
500 if (anAttr.get() != NULL)
501 anObject = anAttr->value();
506 TopAbs_ShapeEnum getCompoundSubType(const TopoDS_Shape& theShape)
508 TopAbs_ShapeEnum aShapeType = theShape.ShapeType();
510 // for compounds check sub-shapes: it may be compound of needed type:
511 // Booleans may produce compounds of Solids
512 if (aShapeType == TopAbs_COMPOUND) {
513 for(TopoDS_Iterator aSubs(theShape); aSubs.More(); aSubs.Next()) {
514 if (!aSubs.Value().IsNull()) {
515 TopAbs_ShapeEnum aSubType = aSubs.Value().ShapeType();
516 if (aSubType == TopAbs_COMPOUND) { // compound of compound(s)
517 aShapeType = TopAbs_COMPOUND;
520 if (aShapeType == TopAbs_COMPOUND) {
521 aShapeType = aSubType;
522 } else if (aShapeType != aSubType) { // compound of shapes of different types
523 aShapeType = TopAbs_COMPOUND;
532 TopoDS_Shape getSelectedShape(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs)
534 if (thePrs->shape().get())
535 return thePrs->shape()->impl<TopoDS_Shape>();
537 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(thePrs->owner());
538 if (!anOwner.IsNull())
539 return anOwner->Shape();
541 return TopoDS_Shape();
544 void getParameters(QStringList& theParameters)
546 theParameters.clear();
548 SessionPtr aSession = ModelAPI_Session::get();
549 std::list<DocumentPtr> aDocList;
550 DocumentPtr anActiveDocument = aSession->activeDocument();
551 DocumentPtr aRootDocument = aSession->moduleDocument();
552 aDocList.push_back(anActiveDocument);
553 if (anActiveDocument != aRootDocument) {
554 aDocList.push_back(aRootDocument);
556 std::string aGroupId = ModelAPI_ResultParameter::group();
557 for(std::list<DocumentPtr>::const_iterator it = aDocList.begin(); it != aDocList.end(); ++it) {
558 DocumentPtr aDocument = *it;
559 int aSize = aDocument->size(aGroupId);
560 for (int i = 0; i < aSize; i++) {
561 ObjectPtr anObject = aDocument->object(aGroupId, i);
562 std::string aParameterName = anObject->data()->name();
563 theParameters.append(aParameterName.c_str());
568 std::string findGreedAttribute(ModuleBase_IWorkshop* theWorkshop,
569 const FeaturePtr& theFeature)
571 std::string anAttributeId;
573 std::string aXmlCfg, aDescription;
574 theWorkshop->module()->getXMLRepresentation(theFeature->getKind(), aXmlCfg, aDescription);
576 ModuleBase_WidgetFactory aFactory(aXmlCfg, theWorkshop);
577 std::string anAttributeTitle;
578 aFactory.getGreedAttribute(anAttributeId);
580 return anAttributeId;
583 bool hasObject(const AttributePtr& theAttribute, const ObjectPtr& theObject,
584 const std::shared_ptr<GeomAPI_Shape>& theShape,
585 ModuleBase_IWorkshop* theWorkshop,
586 const bool theTemporarily)
588 bool aHasObject = false;
589 if (!theAttribute.get())
592 std::string aType = theAttribute->attributeType();
593 if (aType == ModelAPI_AttributeReference::typeId()) {
594 AttributeReferencePtr aRef =
595 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
596 ObjectPtr aObject = aRef->value();
597 aHasObject = aObject && aObject->isSame(theObject);
598 //if (!(aObject && aObject->isSame(theObject))) {
599 // aRef->setValue(theObject);
601 } else if (aType == ModelAPI_AttributeRefAttr::typeId()) {
602 AttributeRefAttrPtr aRefAttr =
603 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
605 AttributePtr anAttribute = theWorkshop->module()->findAttribute(theObject, theShape);
606 if (anAttribute.get()) {
607 //aRefAttr->setAttr(anAttribute);
610 ObjectPtr aObject = aRefAttr->object();
611 aHasObject = aObject && aObject->isSame(theObject);
612 //if (!(aObject && aObject->isSame(theObject))) {
613 // aRefAttr->setObject(theObject);
616 } else if (aType == ModelAPI_AttributeSelection::typeId()) {
617 /*AttributeSelectionPtr aSelectAttr =
618 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
619 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
620 if (aSelectAttr.get() != NULL) {
621 aSelectAttr->setValue(aResult, theShape, theTemporarily);
624 if (aType == ModelAPI_AttributeSelectionList::typeId()) {
625 AttributeSelectionListPtr aSelectionListAttr =
626 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
627 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
628 aHasObject = aSelectionListAttr->isInList(aResult, theShape, theTemporarily);
630 else if (aType == ModelAPI_AttributeRefList::typeId()) {
631 AttributeRefListPtr aRefListAttr =
632 std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
633 aHasObject = aRefListAttr->isInList(theObject);
634 //if (!theCheckIfAttributeHasObject || !aRefListAttr->isInList(theObject))
635 // aRefListAttr->append(theObject);
637 else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
638 AttributeRefAttrListPtr aRefAttrListAttr =
639 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(theAttribute);
640 AttributePtr anAttribute = theWorkshop->module()->findAttribute(theObject, theShape);
642 if (anAttribute.get()) {
643 aHasObject = aRefAttrListAttr->isInList(anAttribute);
644 //if (!theCheckIfAttributeHasObject || !aRefAttrListAttr->isInList(anAttribute))
645 // aRefAttrListAttr->append(anAttribute);
648 aHasObject = aRefAttrListAttr->isInList(theObject);
649 //if (!theCheckIfAttributeHasObject || !aRefAttrListAttr->isInList(theObject))
650 // aRefAttrListAttr->append(theObject);
656 bool setObject(const AttributePtr& theAttribute, const ObjectPtr& theObject,
657 const GeomShapePtr& theShape, ModuleBase_IWorkshop* theWorkshop,
658 const bool theTemporarily, const bool theCheckIfAttributeHasObject)
660 if (!theAttribute.get())
664 std::string aType = theAttribute->attributeType();
665 if (aType == ModelAPI_AttributeReference::typeId()) {
666 AttributeReferencePtr aRef =
667 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
668 ObjectPtr aObject = aRef->value();
669 if (!(aObject && aObject->isSame(theObject))) {
670 aRef->setValue(theObject);
672 } else if (aType == ModelAPI_AttributeRefAttr::typeId()) {
673 AttributeRefAttrPtr aRefAttr =
674 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
676 AttributePtr anAttribute = theWorkshop->module()->findAttribute(theObject, theShape);
677 if (anAttribute.get())
678 aRefAttr->setAttr(anAttribute);
680 ObjectPtr aObject = aRefAttr->object();
681 if (!(aObject && aObject->isSame(theObject))) {
682 aRefAttr->setObject(theObject);
685 } else if (aType == ModelAPI_AttributeSelection::typeId()) {
686 AttributeSelectionPtr aSelectAttr =
687 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
688 if (aSelectAttr.get() != NULL) {
689 aSelectAttr->setValue(theObject, theShape, theTemporarily);
692 if (aType == ModelAPI_AttributeSelectionList::typeId()) {
693 AttributeSelectionListPtr aSelectionListAttr =
694 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
695 if (!theCheckIfAttributeHasObject ||
696 !aSelectionListAttr->isInList(theObject, theShape, theTemporarily))
697 aSelectionListAttr->append(theObject, theShape, theTemporarily);
699 else if (aType == ModelAPI_AttributeRefList::typeId()) {
700 AttributeRefListPtr aRefListAttr =
701 std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
702 if (!theCheckIfAttributeHasObject || !aRefListAttr->isInList(theObject)) {
704 aRefListAttr->append(theObject);
709 else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
710 AttributeRefAttrListPtr aRefAttrListAttr =
711 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(theAttribute);
712 AttributePtr anAttribute = theWorkshop->module()->findAttribute(theObject, theShape);
714 if (anAttribute.get()) {
715 if (!theCheckIfAttributeHasObject || !aRefAttrListAttr->isInList(anAttribute))
716 aRefAttrListAttr->append(anAttribute);
719 if (!theCheckIfAttributeHasObject || !aRefAttrListAttr->isInList(theObject)) {
721 aRefAttrListAttr->append(theObject);
730 GeomShapePtr getShape(const AttributePtr& theAttribute, ModuleBase_IWorkshop* theWorkshop)
733 if (!theAttribute.get())
736 std::string aType = theAttribute->attributeType();
737 if (aType == ModelAPI_AttributeReference::typeId()) {
738 } else if (aType == ModelAPI_AttributeRefAttr::typeId()) {
739 AttributeRefAttrPtr aRefAttr =
740 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
741 if (aRefAttr.get() && !aRefAttr->isObject()) {
742 AttributePtr anAttribute = aRefAttr->attr();
743 aShape = theWorkshop->module()->findShape(anAttribute);
745 } else if (aType == ModelAPI_AttributeSelection::typeId()) {
746 AttributeSelectionPtr aSelectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
748 aShape = aSelectAttr->value();
750 else // Geom2D point processing
751 aShape = theWorkshop->module()->findShape(theAttribute);
755 void flushUpdated(ObjectPtr theObject)
757 blockUpdateViewer(true);
759 // Fix the problem of not previewed results of constraints applied. Flush Create/Delete
760 // (for the sketch result) to start processing of the sketch in the solver.
761 // TODO: these flushes should be moved in a separate method provided by Model
762 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
763 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_VISUAL_ATTRIBUTES));
764 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
765 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
767 blockUpdateViewer(false);
770 void blockUpdateViewer(const bool theValue)
772 // the viewer update should be blocked in order to avoid the temporary feature content
773 // when the solver processes the feature, the redisplay message can be flushed
774 // what caused the display in the viewer preliminary states of object
775 // e.g. fillet feature, angle value change
776 std::shared_ptr<Events_Message> aMsg;
778 aMsg = std::shared_ptr<Events_Message>(
779 new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_BLOCKED)));
782 // the viewer update should be unblocked
783 aMsg = std::shared_ptr<Events_Message>(
784 new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_UNBLOCKED)));
786 Events_Loop::loop()->send(aMsg);
789 QString wrapTextByWords(const QString& theValue, QWidget* theWidget,
790 int theMaxLineInPixels)
792 static QFontMetrics tfm(theWidget ? theWidget->font() : QApplication::font());
793 static qreal phi = 2.618;
795 QRect aBounds = tfm.boundingRect(theValue);
796 if(aBounds.width() <= theMaxLineInPixels)
799 qreal s = aBounds.width() * aBounds.height();
800 qreal aGoldWidth = sqrt(s*phi);
802 QStringList aWords = theValue.split(" ", QString::SkipEmptyParts);
804 int n = aWords.count();
806 for (int i = 0; i < n; i++) {
807 QString aLineExt = i == 0 ? aWords[i] : aLine + " " + aWords[i];
808 qreal anWidthNonExt = tfm.boundingRect(aLine).width();
809 qreal anWidthExt = tfm.boundingRect(aLineExt).width();
810 qreal aDeltaNonExt = fabs(anWidthNonExt-aGoldWidth);
811 qreal aDeltaExt = fabs(anWidthExt-aGoldWidth);
812 if(aDeltaNonExt < aDeltaExt) {
814 aLines.append(aLine);
822 aLines.append(aLine);
824 QString aResult = aLines.join("\n");
828 //**************************************************************
829 QLocale doubleLocale()
831 // VSR 01/07/2010: Disable thousands separator for spin box
832 // (to avoid inconsistency of double-2-string and string-2-double conversion)
834 aLocale.setNumberOptions(aLocale.numberOptions() |
835 QLocale::OmitGroupSeparator |
836 QLocale::RejectGroupSeparator);
840 //**************************************************************
841 void refsToFeatureInFeatureDocument(const ObjectPtr& theObject,
842 std::set<FeaturePtr>& theRefFeatures)
844 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
845 if (aFeature.get()) {
846 DocumentPtr aFeatureDoc = aFeature->document();
847 // 1. find references in the current document
848 aFeatureDoc->refsToFeature(aFeature, theRefFeatures, false);
853 //**************************************************************
854 /*bool isSubOfComposite(const ObjectPtr& theObject)
857 std::set<FeaturePtr> aRefFeatures;
858 refsToFeatureInFeatureDocument(theObject, aRefFeatures);
859 std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
860 aLast = aRefFeatures.end();
861 for (; anIt != aLast && !isSub; anIt++) {
862 isSub = isSubOfComposite(theObject, *anIt);
867 //**************************************************************
868 /*bool isSubOfComposite(const ObjectPtr& theObject, const FeaturePtr& theFeature)
871 CompositeFeaturePtr aComposite = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theFeature);
872 if (aComposite.get()) {
873 isSub = aComposite->isSub(theObject);
874 // the recursive is possible, the parameters are sketch circle and extrusion cut. They are
875 // separated by composite sketch feature
877 int aNbSubs = aComposite->numberOfSubs();
878 for (int aSub = 0; aSub < aNbSubs && !isSub; aSub++) {
879 isSub = isSubOfComposite(theObject, aComposite->subFeature(aSub));
886 //**************************************************************
887 ResultPtr firstResult(const ObjectPtr& theObject)
889 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
890 if (!aResult.get()) {
891 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
893 aResult = aFeature->firstResult();
898 //**************************************************************
899 bool isFeatureOfResult(const FeaturePtr& theFeature, const std::string& theGroupOfResult)
901 bool isResult = false;
903 if (!theFeature->data()->isValid())
906 ResultPtr aFirstResult = theFeature->firstResult();
907 if (!aFirstResult.get())
910 return aFirstResult->groupName() == theGroupOfResult;
913 //**************************************************************
914 bool hasModuleDocumentFeature(const std::set<FeaturePtr>& theFeatures)
916 bool aFoundModuleDocumentObject = false;
917 DocumentPtr aModuleDoc = ModelAPI_Session::get()->moduleDocument();
919 std::set<FeaturePtr>::const_iterator anIt = theFeatures.begin(), aLast = theFeatures.end();
920 for (; anIt != aLast && !aFoundModuleDocumentObject; anIt++) {
921 FeaturePtr aFeature = *anIt;
922 ResultPtr aResult = ModuleBase_Tools::firstResult(aFeature);
923 if (aResult.get() && aResult->groupName() == ModelAPI_ResultPart::group())
925 aFoundModuleDocumentObject = aFeature->document() == aModuleDoc;
928 return aFoundModuleDocumentObject;
931 //**************************************************************
932 bool askToDelete(const std::set<FeaturePtr> theFeatures,
933 const std::map<FeaturePtr, std::set<FeaturePtr> >& theReferences,
935 std::set<FeaturePtr>& theReferencesToDelete,
936 const std::string& thePrefixInfo)
938 QString aNotActivatedDocWrn;
939 std::string aNotActivatedNames;
940 if (!ModelAPI_Tools::allDocumentsActivated(aNotActivatedNames)) {
941 if (ModuleBase_Tools::hasModuleDocumentFeature(theFeatures))
942 aNotActivatedDocWrn =
943 QObject::tr("Selected objects can be used in Part documents which are not loaded: %1.\n")
944 .arg(aNotActivatedNames.c_str());
947 std::set<FeaturePtr> aFeaturesRefsTo;
948 std::set<FeaturePtr> aFeaturesRefsToParameter;
949 std::set<FeaturePtr> aParameterFeatures;
950 QStringList aPartFeatureNames;
951 std::set<FeaturePtr>::const_iterator anIt = theFeatures.begin(),
952 aLast = theFeatures.end();
953 // separate features to references to parameter features and references to others
954 for (; anIt != aLast; anIt++) {
955 FeaturePtr aFeature = *anIt;
956 if (theReferences.find(aFeature) == theReferences.end())
959 if (isFeatureOfResult(aFeature, ModelAPI_ResultPart::group()))
960 aPartFeatureNames.append(aFeature->name().c_str());
962 std::set<FeaturePtr> aRefFeatures;
963 std::set<FeaturePtr> aRefList = theReferences.at(aFeature);
964 std::set<FeaturePtr>::const_iterator aRefIt = aRefList.begin(), aRefLast = aRefList.end();
965 for (; aRefIt != aRefLast; aRefIt++) {
966 FeaturePtr aRefFeature = *aRefIt;
967 if (theFeatures.find(aRefFeature) == theFeatures.end() && // it is not selected
968 aRefFeatures.find(aRefFeature) == aRefFeatures.end()) // it is not added
969 aRefFeatures.insert(aRefFeature);
972 if (isFeatureOfResult(aFeature, ModelAPI_ResultParameter::group())) {
973 aFeaturesRefsToParameter.insert(aRefFeatures.begin(), aRefFeatures.end());
974 aParameterFeatures.insert(aFeature);
977 theReferencesToDelete.insert(aRefFeatures.begin(), aRefFeatures.end());
981 std::set<FeaturePtr> aFeaturesRefsToParameterOnly;
982 anIt = aFeaturesRefsToParameter.begin();
983 aLast = aFeaturesRefsToParameter.end();
984 // separate features to references to parameter features and references to others
985 QStringList aParamFeatureNames;
986 for (; anIt != aLast; anIt++) {
987 FeaturePtr aFeature = *anIt;
988 if (theReferencesToDelete.find(aFeature) == theReferencesToDelete.end()) {
989 aFeaturesRefsToParameterOnly.insert(aFeature);
990 aParamFeatureNames.append(aFeature->name().c_str());
993 aParamFeatureNames.sort();
994 QStringList anOtherFeatureNames;
995 anIt = theReferencesToDelete.begin();
996 aLast = theReferencesToDelete.end();
997 for (; anIt != aLast; anIt++) {
998 FeaturePtr aFeature = *anIt;
999 if (aFeature->getKind() == "RemoveResults")
1000 continue; // skip the remove results feature mentioning: result will be removed anyway
1001 if (isFeatureOfResult(aFeature, ModelAPI_ResultPart::group()))
1002 aPartFeatureNames.append(aFeature->name().c_str());
1004 anOtherFeatureNames.append(aFeature->name().c_str());
1006 aPartFeatureNames.sort();
1007 anOtherFeatureNames.sort();
1009 bool aCanReplaceParameters = !aFeaturesRefsToParameterOnly.empty();
1011 QMessageBox aMessageBox(theParent);
1012 aMessageBox.setWindowTitle(QObject::tr("Delete features"));
1013 aMessageBox.setIcon(QMessageBox::Warning);
1014 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
1015 aMessageBox.setDefaultButton(QMessageBox::No);
1018 if (!thePrefixInfo.empty())
1019 aText = thePrefixInfo.c_str();
1020 QString aSep = ", ";
1021 if (!aPartFeatureNames.empty()) {
1022 aText += QString(QObject::tr("The following parts will be deleted: %1.\n"))
1023 .arg(aPartFeatureNames.join(aSep));
1025 if (!aNotActivatedDocWrn.isEmpty())
1026 aText += aNotActivatedDocWrn;
1027 if (!anOtherFeatureNames.empty()) {
1028 const char* aMsg = "Features are used in the following features: %1.\nThese "
1029 "features will be deleted.\n";
1030 aText += QString(QObject::tr(aMsg))
1031 .arg(anOtherFeatureNames.join(aSep));
1033 if (!aParamFeatureNames.empty()) {
1034 const char* aMsg = "Parameters are used directly and through a sequence "
1035 "of dependencies in the following features: %1.\nThese features will "
1036 "be deleted.\nOr parameters could be replaced by their values.\n";
1037 aText += QString(QObject::tr(aMsg))
1038 .arg(aParamFeatureNames.join(aSep));
1039 QPushButton *aReplaceButton =
1040 aMessageBox.addButton(QObject::tr("Replace"), QMessageBox::ActionRole);
1043 if (!aText.isEmpty()) {
1044 aText += "Would you like to continue?";
1045 aMessageBox.setText(aText);
1047 QMessageBox::ButtonRole aButtonRole = aMessageBox.buttonRole(aMessageBox.clickedButton());
1049 if (aButtonRole == QMessageBox::NoRole)
1052 if (aButtonRole == QMessageBox::ActionRole) {
1053 foreach (FeaturePtr aObj, aParameterFeatures)
1054 ModelAPI_ReplaceParameterMessage::send(aObj, 0);
1057 theReferencesToDelete.insert(aFeaturesRefsToParameterOnly.begin(),
1058 aFeaturesRefsToParameterOnly.end());
1063 //**************************************************************
1064 void convertToFeatures(const QObjectPtrList& theObjects, std::set<FeaturePtr>& theFeatures)
1066 QObjectPtrList::const_iterator anIt = theObjects.begin(), aLast = theObjects.end();
1067 for(; anIt != aLast; anIt++) {
1068 ObjectPtr anObject = *anIt;
1069 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
1070 // for parameter result, use the corresponded reature to be removed
1071 if (!aFeature.get() && anObject->groupName() == ModelAPI_ResultParameter::group()) {
1072 aFeature = ModelAPI_Feature::feature(anObject);
1075 theFeatures.insert(aFeature);
1079 //**************************************************************
1080 void convertToFolders(const QObjectPtrList& theObjects,
1081 std::set<FolderPtr>& theFolders)
1083 QObjectPtrList::const_iterator anIt = theObjects.begin(), aLast = theObjects.end();
1084 for(; anIt != aLast; anIt++) {
1085 ObjectPtr anObject = *anIt;
1086 FolderPtr aFeature = std::dynamic_pointer_cast<ModelAPI_Folder>(anObject);
1088 theFolders.insert(aFeature);
1093 //**************************************************************
1094 QString translate(const Events_InfoMessage& theMessage)
1098 if (!theMessage.empty()) {
1099 std::string aStr = Config_Translator::translate(theMessage);
1100 if (!aStr.empty()) {
1101 std::string aCodec = Config_Translator::codec(theMessage);
1102 aMessage = QTextCodec::codecForName(aCodec.c_str())->toUnicode(aStr.c_str());
1109 QString translate(const std::string& theContext, const std::string& theMessage)
1113 if (!theMessage.empty()) {
1114 std::string aStr = Config_Translator::translate(theContext, theMessage);
1115 if (!aStr.empty()) {
1116 std::string aCodec = Config_Translator::codec(theContext);
1117 aMessage = QTextCodec::codecForName(aCodec.c_str())->toUnicode(aStr.c_str());
1124 void setPointBallHighlighting(AIS_Shape* theAIS)
1126 static Handle(Image_AlienPixMap) aPixMap;
1127 if(aPixMap.IsNull()) {
1128 // Load icon for the presentation
1130 char* anEnv = getenv("SHAPER_ROOT_DIR");
1132 aFile = std::string(anEnv) +
1133 FSEP + "share" + FSEP + "salome" + FSEP + "resources" + FSEP + "shaper";
1135 anEnv = getenv("CADBUILDER_ROOT_DIR");
1137 aFile = std::string(anEnv) + FSEP + "resources";
1141 static const std::string aMarkerName = "marker_dot.png";
1142 aFile += aMarkerName;
1143 aPixMap = new Image_AlienPixMap();
1144 if(!aPixMap->Load(aFile.c_str())) {
1145 // The icon for constraint is not found
1146 static const std::string aMsg =
1147 "Error: Point market not found by path: \"" + aFile + "\". Falling back.";
1148 //Events_InfoMessage("ModuleBase_Tools::setPointBallHighlighting", aMsg).send();
1152 Handle(Graphic3d_AspectMarker3d) anAspect;
1153 Handle(Prs3d_Drawer) aDrawer = theAIS->DynamicHilightAttributes();
1154 if (aDrawer.IsNull()) {
1155 if (ModuleBase_IViewer::DefaultHighlightDrawer.IsNull())
1157 aDrawer = new Prs3d_Drawer(*ModuleBase_IViewer::DefaultHighlightDrawer);
1158 if (!aDrawer->HasOwnPointAspect()) {
1159 aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_BALL, Quantity_NOC_BLACK, 2.0));
1162 if(aDrawer->HasOwnPointAspect()) {
1163 Handle(Prs3d_PointAspect) aPntAspect = aDrawer->PointAspect();
1164 if(aPixMap->IsEmpty()) {
1165 anAspect = aPntAspect->Aspect();
1166 anAspect->SetType(Aspect_TOM_BALL);
1168 if(aPixMap->Format() == Image_PixMap::ImgGray) {
1169 aPixMap->SetFormat (Image_PixMap::ImgAlpha);
1170 } else if(aPixMap->Format() == Image_PixMap::ImgGrayF) {
1171 aPixMap->SetFormat (Image_PixMap::ImgAlphaF);
1173 anAspect = new Graphic3d_AspectMarker3d(aPixMap);
1174 aPntAspect->SetAspect(anAspect);
1176 aDrawer->SetPointAspect(aPntAspect);
1177 theAIS->SetDynamicHilightAttributes(aDrawer);
1181 FeaturePtr createParameter(const QString& theText)
1183 FeaturePtr aParameter;
1184 QStringList aList = theText.split("=");
1185 if (aList.count() != 2) {
1188 QString aParamName = aList.at(0).trimmed();
1190 if (isNameExist(aParamName, FeaturePtr())) {
1194 if (!ModelAPI_Expression::isVariable(aParamName.toStdString())) {
1198 QString aExpression = aList.at(1).trimmed();
1199 if (aExpression.isEmpty()) {
1203 SessionPtr aMgr = ModelAPI_Session::get();
1204 std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
1206 aParameter = aDoc->addFeature("Parameter");
1207 if (aParameter.get()) {
1208 AttributeStringPtr aNameAttr = aParameter->string("variable");
1209 aNameAttr->setValue(aParamName.toStdString());
1211 AttributeStringPtr aExprAttr = aParameter->string("expression");
1212 aExprAttr->setValue(aExpression.toStdString());
1213 aParameter->execute();
1215 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1216 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
1221 void editParameter(FeaturePtr theParam, const QString& theText)
1223 QStringList aList = theText.split("=");
1224 QString aParamName = aList.at(0).trimmed();
1226 QString aExpression = aList.at(1).trimmed();
1227 if (aExpression.isEmpty()) {
1231 if (isNameExist(aParamName, theParam)) {
1234 AttributeStringPtr aNameAttr = theParam->string("variable");
1235 aNameAttr->setValue(aParamName.toStdString());
1237 AttributeStringPtr aExprAttr = theParam->string("expression");
1238 aExprAttr->setValue(aExpression.toStdString());
1239 theParam->execute();
1241 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
1244 bool isNameExist(const QString& theName, FeaturePtr theIgnoreParameter)
1246 SessionPtr aMgr = ModelAPI_Session::get();
1247 std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
1248 FeaturePtr aParamFeature;
1249 int aNbFeatures = aDoc->numInternalFeatures();
1250 std::string aName = theName.toStdString();
1251 for (int i = 0; i < aNbFeatures; i++) {
1252 aParamFeature = aDoc->internalFeature(i);
1253 if (aParamFeature && aParamFeature->getKind() == "Parameter") {
1254 if ((theIgnoreParameter != aParamFeature) && (aParamFeature->name() == aName))
1261 FeaturePtr findParameter(const QString& theName)
1263 SessionPtr aMgr = ModelAPI_Session::get();
1264 std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
1265 FeaturePtr aParamFeature;
1266 int aNbFeatures = aDoc->numInternalFeatures();
1267 std::string aName = theName.toStdString();
1268 for (int i = 0; i < aNbFeatures; i++) {
1269 aParamFeature = aDoc->internalFeature(i);
1270 if (aParamFeature && aParamFeature->getKind() == "Parameter") {
1271 if (aParamFeature->name() == aName)
1272 return aParamFeature;
1275 return FeaturePtr();
1279 //********************************************************************
1280 std::string generateName(const AttributePtr& theAttribute,
1281 ModuleBase_IWorkshop* theWorkshop)
1284 if (theAttribute.get() != NULL) {
1285 ModuleBase_Operation* anOperation = theWorkshop->currentOperation();
1287 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
1288 if (aFeature.get()) {
1289 std::string aXmlCfg, aDescription;
1290 theWorkshop->module()->getXMLRepresentation(aFeature->getKind(), aXmlCfg, aDescription);
1292 ModuleBase_WidgetFactory aFactory(aXmlCfg, theWorkshop);
1293 std::string anAttributeTitle;
1294 aFactory.getAttributeTitle(theAttribute->id(), anAttributeTitle);
1296 std::stringstream aStreamName;
1297 aStreamName << theAttribute->owner()->data()->name() << "/" << anAttributeTitle.c_str();
1298 aName = aStreamName.str();
1304 bool isSameShape(const TopoDS_Shape& theShape1, const TopoDS_Shape& theShape2)
1306 // In case of compound we cannot rely on simple comparison method.
1307 // If the compound is generated by Group feature then this compound is alwais new.
1308 // So, we have to compare content of these compounds
1309 if (theShape1.ShapeType() != theShape2.ShapeType())
1312 if (theShape1.ShapeType() != TopAbs_COMPOUND)
1313 return theShape1.IsSame(theShape2);
1315 TopoDS_Iterator aIt1(theShape1);
1316 TopoDS_Iterator aIt2(theShape2);
1318 for (; aIt1.More() && aIt2.More(); aIt1.Next(), aIt2.Next()) {
1319 if (!(aIt1.Value()).IsSame(aIt2.Value()))
1325 qreal currentPixelRatio()
1327 QWindowList aWnds = qApp->topLevelWindows();
1328 if (aWnds.size() > 0)
1329 return aWnds.first()->devicePixelRatio();
1330 return qApp->primaryScreen()->devicePixelRatio();
1334 } // namespace ModuleBase_Tools