1 // Copyright (C) 2014-2020 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 activateWindow(theWidget);
158 theWidget->setFocus();
159 // rectangle of focus is not visible on tool button widgets
161 #ifdef DEBUG_SET_FOCUS
162 qDebug(QString("setFocus: %1").arg(theInfo).toStdString().c_str());
166 void setShadowEffect(QWidget* theWidget, const bool isSetEffect)
169 QGraphicsDropShadowEffect* aGlowEffect = new QGraphicsDropShadowEffect();
170 aGlowEffect->setOffset(.0);
171 aGlowEffect->setBlurRadius(10.0);
172 aGlowEffect->setColor(QColor(0, 170, 255)); // Light-blue color, #00AAFF
173 theWidget->setGraphicsEffect(aGlowEffect);
176 QGraphicsEffect* anEffect = theWidget->graphicsEffect();
178 anEffect->deleteLater();
179 theWidget->setGraphicsEffect(NULL);
183 QPixmap composite(const QString& theAdditionalIcon, const QString& theIcon)
185 QImage anIcon = ModuleBase_IconFactory::loadImage(theIcon);
186 QImage anAditional(theAdditionalIcon);
187 return composite(anAditional, anIcon);
190 QPixmap composite(const QImage& theAdditionalIcon, QImage& theIcon)
192 if (theIcon.isNull())
195 int anAddWidth = theAdditionalIcon.width();
196 int anAddHeight = theAdditionalIcon.height();
198 int aWidth = theIcon.width();
199 int aHeight = theIcon.height();
201 int aStartWidthPos = aWidth - anAddWidth;
202 int aStartHeightPos = aHeight - anAddHeight;
204 for (int i = 0; i < anAddWidth && i + aStartWidthPos < aWidth; i++)
206 for (int j = 0; j < anAddHeight && j + aStartHeightPos < aHeight; j++)
208 if (qAlpha(theAdditionalIcon.pixel(i, j)) > 0)
209 theIcon.setPixel(i + aStartWidthPos, j + aStartHeightPos, theAdditionalIcon.pixel(i, j));
212 return QPixmap::fromImage(theIcon);
215 QPixmap lighter(const QString& theIcon, const int theLighterValue)
217 QImage anIcon = ModuleBase_IconFactory::loadImage(theIcon);
221 QImage aResult = ModuleBase_IconFactory::loadImage(theIcon);
222 for (int i = 0; i < anIcon.width(); i++)
224 for (int j = 0; j < anIcon.height(); j++)
226 QRgb anRgb = anIcon.pixel(i, j);
227 QColor aPixelColor(qRed(anRgb), qGreen(anRgb), qBlue(anRgb),
228 qAlpha(aResult.pixel(i, j)));
230 QColor aLighterColor = aPixelColor.lighter(theLighterValue);
231 aResult.setPixel(i, j, qRgba(aLighterColor.red(), aLighterColor.green(),
232 aLighterColor.blue(), aLighterColor.alpha()));
235 return QPixmap::fromImage(aResult);
238 void setSpinText(ModuleBase_ParamSpinBox* theSpin, const QString& theText)
240 if (theSpin->text() == theText)
242 // In order to avoid extra text setting because it will
243 // reset cursor position in control
244 bool isBlocked = theSpin->blockSignals(true);
245 theSpin->setText(theText);
246 theSpin->blockSignals(isBlocked);
249 void setSpinValue(QDoubleSpinBox* theSpin, double theValue)
251 if (fabs(theSpin->value() - theValue) < tolerance)
253 bool isBlocked = theSpin->blockSignals(true);
254 theSpin->setValue(theValue);
255 theSpin->blockSignals(isBlocked);
258 void setSpinValue(ModuleBase_ParamSpinBox* theSpin, double theValue)
260 if (!theSpin->text().isEmpty() && fabs(theSpin->value() - theValue) < tolerance)
262 bool isBlocked = theSpin->blockSignals(true);
263 theSpin->setValue(theValue);
264 theSpin->blockSignals(isBlocked);
267 void setSpinText(ModuleBase_ParamIntSpinBox* theSpin, const QString& theText)
269 // In order to avoid extra text setting because it will
270 // reset cursor position in control
271 if (theSpin->text() == theText)
273 bool isBlocked = theSpin->blockSignals(true);
274 theSpin->setText(theText);
275 theSpin->blockSignals(isBlocked);
278 void setSpinValue(ModuleBase_ParamIntSpinBox* theSpin, int theValue)
280 if (theSpin->value() == theValue)
282 bool isBlocked = theSpin->blockSignals(true);
283 theSpin->setValue(theValue);
284 theSpin->blockSignals(isBlocked);
287 QAction* createAction(const QIcon& theIcon, const QString& theText,
288 QObject* theParent, const QObject* theReceiver,
289 const char* theMember, const QString& theToolTip,
290 const QString& theStatusTip)
292 QAction* anAction = new QAction(theIcon, theText, theParent);
293 anAction->setToolTip(theToolTip.isEmpty() ? theText : theToolTip);
294 anAction->setStatusTip(!theStatusTip.isEmpty() ? theStatusTip :
295 (!theToolTip.isEmpty() ? theToolTip : theText));
297 QObject::connect(anAction, SIGNAL(triggered(bool)), theReceiver, theMember);
303 QString objectName(const ObjectPtr& theObj)
308 return theObj->data()->name().c_str();
311 QString objectInfo(const ObjectPtr& theObj, const bool isUseAttributesInfo)
313 QString aFeatureStr = "feature";
317 std::ostringstream aPtrStr;
318 aPtrStr << "[" << theObj.get() << "]";
320 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObj);
321 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObj);
323 aFeatureStr.append(QString("(result%1)").arg(aPtrStr.str().c_str()).toStdString() .c_str());
324 if (aRes->isDisabled())
325 aFeatureStr.append("[disabled]");
326 if (aRes->isConcealed())
327 aFeatureStr.append("[concealed]");
328 if (ModelAPI_Tools::hasSubResults(aRes))
329 aFeatureStr.append("[hasSubResults]");
331 aFeature = ModelAPI_Feature::feature(aRes);
334 aFeatureStr.append(aPtrStr.str().c_str());
336 if (aFeature.get()) {
337 aFeatureStr.append(QString(": %1").arg(aFeature->getKind().c_str()).toStdString().c_str());
338 if (aFeature->data()->isValid()) {
339 aFeatureStr.append(QString(", name=%1").arg(theObj->data()->name().c_str()).toStdString()
342 if (isUseAttributesInfo) {
343 std::set<std::shared_ptr<ModelAPI_Attribute> > anAttributes;
344 std::string aPointsInfo = ModelGeomAlgo_Point2D::getPontAttributesInfo(aFeature,
345 anAttributes).c_str();
346 if (!aPointsInfo.empty())
347 aFeatureStr.append(QString(", attributes: %1")
348 .arg(aPointsInfo.c_str()).toStdString().c_str());
356 typedef QMap<QString, int> ShapeTypes;
357 static ShapeTypes myShapeTypes;
359 int shapeType(const QString& theType)
361 if (myShapeTypes.count() == 0) {
362 myShapeTypes["compound"] = TopAbs_COMPOUND;
363 myShapeTypes["compounds"] = TopAbs_COMPOUND;
364 myShapeTypes["compsolid"] = TopAbs_COMPSOLID;
365 myShapeTypes["compsolids"] = TopAbs_COMPSOLID;
366 myShapeTypes["solid"] = TopAbs_SOLID;
367 myShapeTypes["solids"] = TopAbs_SOLID;
368 myShapeTypes["shell"] = TopAbs_SHELL;
369 myShapeTypes["shells"] = TopAbs_SHELL;
370 myShapeTypes["face"] = TopAbs_FACE;
371 myShapeTypes["faces"] = TopAbs_FACE;
372 myShapeTypes["wire"] = TopAbs_WIRE;
373 myShapeTypes["wires"] = TopAbs_WIRE;
374 myShapeTypes["edge"] = TopAbs_EDGE;
375 myShapeTypes["edges"] = TopAbs_EDGE;
376 myShapeTypes["vertex"] = TopAbs_VERTEX;
377 myShapeTypes["vertices"] = TopAbs_VERTEX;
378 myShapeTypes["object"] = ModuleBase_ResultPrs::Sel_Result;
379 myShapeTypes["objects"] = ModuleBase_ResultPrs::Sel_Result;
381 QString aType = theType.toLower();
382 if(myShapeTypes.contains(aType))
383 return myShapeTypes[aType];
384 Events_InfoMessage("ModuleBase_Tools", "Shape type defined in XML is not implemented!").send();
388 void checkObjects(const QObjectPtrList& theObjects, bool& hasResult, bool& hasFeature,
389 bool& hasParameter, bool& hasCompositeOwner, bool& hasResultInHistory,
394 hasParameter = false;
395 hasCompositeOwner = false;
396 hasResultInHistory = false;
398 foreach(ObjectPtr aObj, theObjects) {
399 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
400 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
401 FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(aObj);
402 ResultParameterPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aResult);
403 FieldStepPtr aStep = std::dynamic_pointer_cast<ModelAPI_ResultField::ModelAPI_FieldStep>(aObj);
405 hasResult |= ((aResult.get() != NULL) || (aStep.get() != NULL));
406 hasFeature |= (aFeature.get() != NULL);
407 hasFolder |= (aFolder.get() != NULL);
408 hasParameter |= (aConstruction.get() != NULL);
410 hasCompositeOwner |= (ModelAPI_Tools::compositeOwner(aFeature) != NULL);
411 else if (aResult.get())
412 hasCompositeOwner |= (ModelAPI_Tools::bodyOwner(aResult) != NULL);
414 if (!hasResultInHistory && aResult.get()) {
415 aFeature = ModelAPI_Feature::feature(aResult);
416 hasResultInHistory = aFeature.get() && aFeature->isInHistory();
419 if (hasFeature && hasResult && hasParameter && hasCompositeOwner)
424 /*bool setDefaultDeviationCoefficient(std::shared_ptr<GeomAPI_Shape> theGeomShape)
426 if (!theGeomShape.get())
428 // if the shape could not be exploded on faces, it contains only wires, edges, and vertices
429 // correction of deviation for them should not influence to the application performance
430 GeomAPI_ShapeExplorer anExp(theGeomShape, GeomAPI_Shape::FACE);
431 bool anEmpty = anExp.empty();
432 return !anExp.more();
435 /*void setDefaultDeviationCoefficient(const std::shared_ptr<ModelAPI_Result>& theResult,
436 const Handle(Prs3d_Drawer)& theDrawer)
438 if (!theResult.get())
440 bool aUseDeviation = false;
442 std::string aResultGroup = theResult->groupName();
443 if (aResultGroup == ModelAPI_ResultConstruction::group())
444 aUseDeviation = true;
445 else if (aResultGroup == ModelAPI_ResultBody::group()) {
446 GeomShapePtr aGeomShape = theResult->shape();
447 if (aGeomShape.get())
448 aUseDeviation = setDefaultDeviationCoefficient(aGeomShape);
451 theDrawer->SetDeviationCoefficient(DEFAULT_DEVIATION_COEFFICIENT);
454 void setDefaultDeviationCoefficient(const TopoDS_Shape& theShape,
455 const Handle(Prs3d_Drawer)& theDrawer)
457 if (theShape.IsNull())
459 if (theDrawer.IsNull())
462 std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape());
463 aGeomShape->setImpl(new TopoDS_Shape(theShape));
465 // if the shape could not be exploded on faces, it contains only wires, edges, and vertices
466 // correction of deviation for them should not influence to the application performance
467 GeomAPI_ShapeExplorer anExp(aGeomShape, GeomAPI_Shape::FACE);
468 bool isConstruction = !anExp.more();
472 aDeflection = Config_PropManager::real("Visualization", "construction_deflection");
474 aDeflection = Config_PropManager::real("Visualization", "body_deflection");
475 // workaround (issue #3256): to avoid hang up on one of restricted models
476 // set the maximal deflection to be the same as a default body deflection
477 theDrawer->SetMaximalChordialDeviation(aDeflection);
480 theDrawer->SetDeviationCoefficient(aDeflection);
483 Quantity_Color color(const std::string& theSection,
484 const std::string& theName)
486 std::vector<int> aColor = Config_PropManager::color(theSection, theName);
487 return Quantity_Color(aColor[0] / 255., aColor[1] / 255., aColor[2] / 255., Quantity_TOC_RGB);
490 ObjectPtr getObject(const AttributePtr& theAttribute)
493 std::string anAttrType = theAttribute->attributeType();
494 if (anAttrType == ModelAPI_AttributeRefAttr::typeId()) {
495 AttributeRefAttrPtr anAttr =
496 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
497 if (anAttr != NULL && anAttr->isObject())
498 anObject = anAttr->object();
500 if (anAttrType == ModelAPI_AttributeSelection::typeId()) {
501 AttributeSelectionPtr anAttr =
502 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
504 anObject = anAttr->context();
506 if (anAttrType == ModelAPI_AttributeReference::typeId()) {
507 AttributeReferencePtr anAttr =
508 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
509 if (anAttr.get() != NULL)
510 anObject = anAttr->value();
515 TopAbs_ShapeEnum getCompoundSubType(const TopoDS_Shape& theShape)
517 TopAbs_ShapeEnum aShapeType = theShape.ShapeType();
519 // for compounds check sub-shapes: it may be compound of needed type:
520 // Booleans may produce compounds of Solids
521 if (aShapeType == TopAbs_COMPOUND) {
522 for(TopoDS_Iterator aSubs(theShape); aSubs.More(); aSubs.Next()) {
523 if (!aSubs.Value().IsNull()) {
524 TopAbs_ShapeEnum aSubType = aSubs.Value().ShapeType();
525 if (aSubType == TopAbs_COMPOUND) { // compound of compound(s)
526 aShapeType = TopAbs_COMPOUND;
529 if (aShapeType == TopAbs_COMPOUND) {
530 aShapeType = aSubType;
531 } else if (aShapeType != aSubType) { // compound of shapes of different types
532 aShapeType = TopAbs_COMPOUND;
541 TopoDS_Shape getSelectedShape(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs)
543 if (thePrs->shape().get())
544 return thePrs->shape()->impl<TopoDS_Shape>();
546 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(thePrs->owner());
547 if (!anOwner.IsNull())
548 return anOwner->Shape();
550 return TopoDS_Shape();
553 void getParameters(QStringList& theParameters)
555 theParameters.clear();
557 SessionPtr aSession = ModelAPI_Session::get();
558 std::list<DocumentPtr> aDocList;
559 DocumentPtr anActiveDocument = aSession->activeDocument();
560 DocumentPtr aRootDocument = aSession->moduleDocument();
561 aDocList.push_back(anActiveDocument);
562 if (anActiveDocument != aRootDocument) {
563 aDocList.push_back(aRootDocument);
565 std::string aGroupId = ModelAPI_ResultParameter::group();
566 for(std::list<DocumentPtr>::const_iterator it = aDocList.begin(); it != aDocList.end(); ++it) {
567 DocumentPtr aDocument = *it;
568 int aSize = aDocument->size(aGroupId);
569 for (int i = 0; i < aSize; i++) {
570 ObjectPtr anObject = aDocument->object(aGroupId, i);
571 std::string aParameterName = anObject->data()->name();
572 theParameters.append(aParameterName.c_str());
577 std::string findGreedAttribute(ModuleBase_IWorkshop* theWorkshop,
578 const FeaturePtr& theFeature)
580 std::string anAttributeId;
582 std::string aXmlCfg, aDescription;
583 theWorkshop->module()->getXMLRepresentation(theFeature->getKind(), aXmlCfg, aDescription);
585 ModuleBase_WidgetFactory aFactory(aXmlCfg, theWorkshop);
586 std::string anAttributeTitle;
587 aFactory.getGreedAttribute(anAttributeId);
589 return anAttributeId;
592 bool hasObject(const AttributePtr& theAttribute, const ObjectPtr& theObject,
593 const std::shared_ptr<GeomAPI_Shape>& theShape,
594 ModuleBase_IWorkshop* theWorkshop,
595 const bool theTemporarily)
597 bool aHasObject = false;
598 if (!theAttribute.get())
601 std::string aType = theAttribute->attributeType();
602 if (aType == ModelAPI_AttributeReference::typeId()) {
603 AttributeReferencePtr aRef =
604 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
605 ObjectPtr aObject = aRef->value();
606 aHasObject = aObject && aObject->isSame(theObject);
607 //if (!(aObject && aObject->isSame(theObject))) {
608 // aRef->setValue(theObject);
610 } else if (aType == ModelAPI_AttributeRefAttr::typeId()) {
611 AttributeRefAttrPtr aRefAttr =
612 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
614 AttributePtr anAttribute = theWorkshop->module()->findAttribute(theObject, theShape);
615 if (anAttribute.get()) {
616 //aRefAttr->setAttr(anAttribute);
619 ObjectPtr aObject = aRefAttr->object();
620 aHasObject = aObject && aObject->isSame(theObject);
621 //if (!(aObject && aObject->isSame(theObject))) {
622 // aRefAttr->setObject(theObject);
625 } else if (aType == ModelAPI_AttributeSelection::typeId()) {
626 /*AttributeSelectionPtr aSelectAttr =
627 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
628 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
629 if (aSelectAttr.get() != NULL) {
630 aSelectAttr->setValue(aResult, theShape, theTemporarily);
633 if (aType == ModelAPI_AttributeSelectionList::typeId()) {
634 AttributeSelectionListPtr aSelectionListAttr =
635 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
636 aHasObject = aSelectionListAttr->isInList(theObject, theShape, theTemporarily);
638 else if (aType == ModelAPI_AttributeRefList::typeId()) {
639 AttributeRefListPtr aRefListAttr =
640 std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
641 aHasObject = aRefListAttr->isInList(theObject);
642 //if (!theCheckIfAttributeHasObject || !aRefListAttr->isInList(theObject))
643 // aRefListAttr->append(theObject);
645 else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
646 AttributeRefAttrListPtr aRefAttrListAttr =
647 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(theAttribute);
648 AttributePtr anAttribute = theWorkshop->module()->findAttribute(theObject, theShape);
650 if (anAttribute.get()) {
651 aHasObject = aRefAttrListAttr->isInList(anAttribute);
652 //if (!theCheckIfAttributeHasObject || !aRefAttrListAttr->isInList(anAttribute))
653 // aRefAttrListAttr->append(anAttribute);
656 aHasObject = aRefAttrListAttr->isInList(theObject);
657 //if (!theCheckIfAttributeHasObject || !aRefAttrListAttr->isInList(theObject))
658 // aRefAttrListAttr->append(theObject);
664 bool setObject(const AttributePtr& theAttribute, const ObjectPtr& theObject,
665 const GeomShapePtr& theShape, ModuleBase_IWorkshop* theWorkshop,
666 const bool theTemporarily, const bool theCheckIfAttributeHasObject)
668 if (!theAttribute.get())
672 std::string aType = theAttribute->attributeType();
673 if (aType == ModelAPI_AttributeReference::typeId()) {
674 AttributeReferencePtr aRef =
675 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
676 ObjectPtr aObject = aRef->value();
677 if (!(aObject && aObject->isSame(theObject))) {
678 aRef->setValue(theObject);
680 } else if (aType == ModelAPI_AttributeRefAttr::typeId()) {
681 AttributeRefAttrPtr aRefAttr =
682 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
684 AttributePtr anAttribute = theWorkshop->module()->findAttribute(theObject, theShape);
685 if (anAttribute.get())
686 aRefAttr->setAttr(anAttribute);
688 ObjectPtr aObject = aRefAttr->object();
689 if (!(aObject && aObject->isSame(theObject))) {
690 aRefAttr->setObject(theObject);
693 } else if (aType == ModelAPI_AttributeSelection::typeId()) {
694 AttributeSelectionPtr aSelectAttr =
695 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
696 if (aSelectAttr.get() != NULL) {
697 aSelectAttr->setValue(theObject, theShape, theTemporarily);
700 if (aType == ModelAPI_AttributeSelectionList::typeId()) {
701 AttributeSelectionListPtr aSelectionListAttr =
702 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
703 if (!theCheckIfAttributeHasObject ||
704 !aSelectionListAttr->isInList(theObject, theShape, theTemporarily))
705 aSelectionListAttr->append(theObject, theShape, theTemporarily);
707 else if (aType == ModelAPI_AttributeRefList::typeId()) {
708 AttributeRefListPtr aRefListAttr =
709 std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
710 if (!theCheckIfAttributeHasObject || !aRefListAttr->isInList(theObject)) {
712 aRefListAttr->append(theObject);
717 else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
718 AttributeRefAttrListPtr aRefAttrListAttr =
719 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(theAttribute);
720 AttributePtr anAttribute = theWorkshop->module()->findAttribute(theObject, theShape);
722 if (anAttribute.get()) {
723 if (!theCheckIfAttributeHasObject || !aRefAttrListAttr->isInList(anAttribute))
724 aRefAttrListAttr->append(anAttribute);
727 if (!theCheckIfAttributeHasObject || !aRefAttrListAttr->isInList(theObject)) {
729 aRefAttrListAttr->append(theObject);
738 GeomShapePtr getShape(const AttributePtr& theAttribute, ModuleBase_IWorkshop* theWorkshop)
741 if (!theAttribute.get())
744 std::string aType = theAttribute->attributeType();
745 if (aType == ModelAPI_AttributeReference::typeId()) {
746 } else if (aType == ModelAPI_AttributeRefAttr::typeId()) {
747 AttributeRefAttrPtr aRefAttr =
748 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
749 if (aRefAttr.get() && !aRefAttr->isObject()) {
750 AttributePtr anAttribute = aRefAttr->attr();
751 aShape = theWorkshop->module()->findShape(anAttribute);
753 } else if (aType == ModelAPI_AttributeSelection::typeId()) {
754 AttributeSelectionPtr aSelectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
756 aShape = aSelectAttr->value();
758 else // Geom2D point processing
759 aShape = theWorkshop->module()->findShape(theAttribute);
763 void flushUpdated(ObjectPtr theObject)
765 blockUpdateViewer(true);
767 // Fix the problem of not previewed results of constraints applied. Flush Create/Delete
768 // (for the sketch result) to start processing of the sketch in the solver.
769 // TODO: these flushes should be moved in a separate method provided by Model
770 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
771 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_VISUAL_ATTRIBUTES));
772 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
773 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_UPDATE_SELECTION));
774 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
776 blockUpdateViewer(false);
779 void blockUpdateViewer(const bool theValue)
781 // the viewer update should be blocked in order to avoid the temporary feature content
782 // when the solver processes the feature, the redisplay message can be flushed
783 // what caused the display in the viewer preliminary states of object
784 // e.g. fillet feature, angle value change
785 std::shared_ptr<Events_Message> aMsg;
787 aMsg = std::shared_ptr<Events_Message>(
788 new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_BLOCKED)));
791 // the viewer update should be unblocked
792 aMsg = std::shared_ptr<Events_Message>(
793 new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_UNBLOCKED)));
795 Events_Loop::loop()->send(aMsg);
798 QString wrapTextByWords(const QString& theValue, QWidget* theWidget,
799 int theMaxLineInPixels)
801 static QFontMetrics tfm(theWidget ? theWidget->font() : QApplication::font());
802 static qreal phi = 2.618;
804 QRect aBounds = tfm.boundingRect(theValue);
805 if(aBounds.width() <= theMaxLineInPixels)
808 qreal s = aBounds.width() * aBounds.height();
809 qreal aGoldWidth = sqrt(s*phi);
811 QStringList aWords = theValue.split(" ", QString::SkipEmptyParts);
813 int n = aWords.count();
815 for (int i = 0; i < n; i++) {
816 QString aLineExt = i == 0 ? aWords[i] : aLine + " " + aWords[i];
817 qreal anWidthNonExt = tfm.boundingRect(aLine).width();
818 qreal anWidthExt = tfm.boundingRect(aLineExt).width();
819 qreal aDeltaNonExt = fabs(anWidthNonExt-aGoldWidth);
820 qreal aDeltaExt = fabs(anWidthExt-aGoldWidth);
821 if(aDeltaNonExt < aDeltaExt) {
823 aLines.append(aLine);
831 aLines.append(aLine);
833 QString aResult = aLines.join("\n");
837 //**************************************************************
838 QLocale doubleLocale()
840 // VSR 01/07/2010: Disable thousands separator for spin box
841 // (to avoid inconsistency of double-2-string and string-2-double conversion)
843 aLocale.setNumberOptions(aLocale.numberOptions() |
844 QLocale::OmitGroupSeparator |
845 QLocale::RejectGroupSeparator);
849 //**************************************************************
850 void refsToFeatureInFeatureDocument(const ObjectPtr& theObject,
851 std::set<FeaturePtr>& theRefFeatures)
853 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
854 if (aFeature.get()) {
855 DocumentPtr aFeatureDoc = aFeature->document();
856 // 1. find references in the current document
857 aFeatureDoc->refsToFeature(aFeature, theRefFeatures, false);
862 //**************************************************************
863 /*bool isSubOfComposite(const ObjectPtr& theObject)
866 std::set<FeaturePtr> aRefFeatures;
867 refsToFeatureInFeatureDocument(theObject, aRefFeatures);
868 std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
869 aLast = aRefFeatures.end();
870 for (; anIt != aLast && !isSub; anIt++) {
871 isSub = isSubOfComposite(theObject, *anIt);
876 //**************************************************************
877 /*bool isSubOfComposite(const ObjectPtr& theObject, const FeaturePtr& theFeature)
880 CompositeFeaturePtr aComposite = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theFeature);
881 if (aComposite.get()) {
882 isSub = aComposite->isSub(theObject);
883 // the recursive is possible, the parameters are sketch circle and extrusion cut. They are
884 // separated by composite sketch feature
886 int aNbSubs = aComposite->numberOfSubs();
887 for (int aSub = 0; aSub < aNbSubs && !isSub; aSub++) {
888 isSub = isSubOfComposite(theObject, aComposite->subFeature(aSub));
895 //**************************************************************
896 ResultPtr firstResult(const ObjectPtr& theObject)
898 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
899 if (!aResult.get()) {
900 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
902 aResult = aFeature->firstResult();
907 //**************************************************************
908 bool isFeatureOfResult(const FeaturePtr& theFeature, const std::string& theGroupOfResult)
910 bool isResult = false;
912 if (!theFeature->data()->isValid())
915 ResultPtr aFirstResult = theFeature->firstResult();
916 if (!aFirstResult.get())
919 return aFirstResult->groupName() == theGroupOfResult;
922 //**************************************************************
923 bool hasModuleDocumentFeature(const std::set<FeaturePtr>& theFeatures)
925 bool aFoundModuleDocumentObject = false;
926 DocumentPtr aModuleDoc = ModelAPI_Session::get()->moduleDocument();
928 std::set<FeaturePtr>::const_iterator anIt = theFeatures.begin(), aLast = theFeatures.end();
929 for (; anIt != aLast && !aFoundModuleDocumentObject; anIt++) {
930 FeaturePtr aFeature = *anIt;
931 ResultPtr aResult = ModuleBase_Tools::firstResult(aFeature);
932 if (aResult.get() && aResult->groupName() == ModelAPI_ResultPart::group())
934 aFoundModuleDocumentObject = aFeature->document() == aModuleDoc;
937 return aFoundModuleDocumentObject;
940 //**************************************************************
941 bool askToDelete(const std::set<FeaturePtr> theFeatures,
942 const std::map<FeaturePtr, std::set<FeaturePtr> >& theReferences,
944 std::set<FeaturePtr>& theReferencesToDelete,
945 const std::string& thePrefixInfo)
947 QString aNotActivatedDocWrn;
948 std::string aNotActivatedNames;
949 if (!ModelAPI_Tools::allDocumentsActivated(aNotActivatedNames)) {
950 if (ModuleBase_Tools::hasModuleDocumentFeature(theFeatures))
951 aNotActivatedDocWrn =
952 QObject::tr("Selected objects can be used in Part documents which are not loaded: %1.\n")
953 .arg(aNotActivatedNames.c_str());
956 std::set<FeaturePtr> aFeaturesRefsTo;
957 std::set<FeaturePtr> aFeaturesRefsToParameter;
958 std::set<FeaturePtr> aParameterFeatures;
959 QStringList aPartFeatureNames;
960 std::set<FeaturePtr>::const_iterator anIt = theFeatures.begin(),
961 aLast = theFeatures.end();
962 // separate features to references to parameter features and references to others
963 for (; anIt != aLast; anIt++) {
964 FeaturePtr aFeature = *anIt;
965 if (theReferences.find(aFeature) == theReferences.end())
968 if (isFeatureOfResult(aFeature, ModelAPI_ResultPart::group()))
969 aPartFeatureNames.append(aFeature->name().c_str());
971 std::set<FeaturePtr> aRefFeatures;
972 std::set<FeaturePtr> aRefList = theReferences.at(aFeature);
973 std::set<FeaturePtr>::const_iterator aRefIt = aRefList.begin(), aRefLast = aRefList.end();
974 for (; aRefIt != aRefLast; aRefIt++) {
975 FeaturePtr aRefFeature = *aRefIt;
976 if (theFeatures.find(aRefFeature) == theFeatures.end() && // it is not selected
977 aRefFeatures.find(aRefFeature) == aRefFeatures.end()) // it is not added
978 aRefFeatures.insert(aRefFeature);
981 if (isFeatureOfResult(aFeature, ModelAPI_ResultParameter::group())) {
982 aFeaturesRefsToParameter.insert(aRefFeatures.begin(), aRefFeatures.end());
983 aParameterFeatures.insert(aFeature);
986 theReferencesToDelete.insert(aRefFeatures.begin(), aRefFeatures.end());
990 std::set<FeaturePtr> aFeaturesRefsToParameterOnly;
991 anIt = aFeaturesRefsToParameter.begin();
992 aLast = aFeaturesRefsToParameter.end();
993 // separate features to references to parameter features and references to others
994 QStringList aParamFeatureNames;
995 for (; anIt != aLast; anIt++) {
996 FeaturePtr aFeature = *anIt;
997 if (theReferencesToDelete.find(aFeature) == theReferencesToDelete.end()) {
998 aFeaturesRefsToParameterOnly.insert(aFeature);
999 aParamFeatureNames.append(aFeature->name().c_str());
1002 aParamFeatureNames.sort();
1003 QStringList anOtherFeatureNames;
1004 anIt = theReferencesToDelete.begin();
1005 aLast = theReferencesToDelete.end();
1006 for (; anIt != aLast; anIt++) {
1007 FeaturePtr aFeature = *anIt;
1008 if (aFeature->getKind() == "RemoveResults")
1009 continue; // skip the remove results feature mentioning: result will be removed anyway
1010 if (isFeatureOfResult(aFeature, ModelAPI_ResultPart::group()))
1011 aPartFeatureNames.append(aFeature->name().c_str());
1013 anOtherFeatureNames.append(aFeature->name().c_str());
1015 aPartFeatureNames.sort();
1016 anOtherFeatureNames.sort();
1018 QMessageBox aMessageBox(theParent);
1019 aMessageBox.setWindowTitle(QObject::tr("Delete features"));
1020 aMessageBox.setIcon(QMessageBox::Warning);
1021 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
1022 aMessageBox.setDefaultButton(QMessageBox::No);
1025 if (!thePrefixInfo.empty())
1026 aText = thePrefixInfo.c_str();
1027 QString aSep = ", ";
1028 if (!aPartFeatureNames.empty()) {
1029 aText += QString(QObject::tr("The following parts will be deleted: %1.\n"))
1030 .arg(aPartFeatureNames.join(aSep));
1032 if (!aNotActivatedDocWrn.isEmpty())
1033 aText += aNotActivatedDocWrn;
1034 if (!anOtherFeatureNames.empty()) {
1035 const char* aMsg = "Features are used in the following features: %1.\nThese "
1036 "features will be deleted.\n";
1037 aText += QString(QObject::tr(aMsg))
1038 .arg(anOtherFeatureNames.join(aSep));
1040 if (!aParamFeatureNames.empty()) {
1041 const char* aMsg = "Parameters are used directly and through a sequence "
1042 "of dependencies in the following features: %1.\nThese features will "
1043 "be deleted.\nOr parameters could be replaced by their values.\n";
1044 aText += QString(QObject::tr(aMsg))
1045 .arg(aParamFeatureNames.join(aSep));
1047 QPushButton *aReplaceButton =
1049 aMessageBox.addButton(QObject::tr("Replace"), QMessageBox::ActionRole);
1052 if (!aText.isEmpty()) {
1053 aText += "Would you like to continue?";
1054 aMessageBox.setText(aText);
1056 QMessageBox::ButtonRole aButtonRole = aMessageBox.buttonRole(aMessageBox.clickedButton());
1058 if (aButtonRole == QMessageBox::NoRole)
1061 if (aButtonRole == QMessageBox::ActionRole) {
1062 foreach (FeaturePtr aObj, aParameterFeatures)
1063 ModelAPI_ReplaceParameterMessage::send(aObj, 0);
1066 theReferencesToDelete.insert(aFeaturesRefsToParameterOnly.begin(),
1067 aFeaturesRefsToParameterOnly.end());
1072 //**************************************************************
1073 void convertToFeatures(const QObjectPtrList& theObjects, std::set<FeaturePtr>& theFeatures)
1075 QObjectPtrList::const_iterator anIt = theObjects.begin(), aLast = theObjects.end();
1076 for(; anIt != aLast; anIt++) {
1077 ObjectPtr anObject = *anIt;
1078 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
1079 // for parameter result, use the corresponded reature to be removed
1080 if (!aFeature.get() && anObject->groupName() == ModelAPI_ResultParameter::group()) {
1081 aFeature = ModelAPI_Feature::feature(anObject);
1084 theFeatures.insert(aFeature);
1088 //**************************************************************
1089 void convertToFolders(const QObjectPtrList& theObjects,
1090 std::set<FolderPtr>& theFolders)
1092 QObjectPtrList::const_iterator anIt = theObjects.begin(), aLast = theObjects.end();
1093 for(; anIt != aLast; anIt++) {
1094 ObjectPtr anObject = *anIt;
1095 FolderPtr aFeature = std::dynamic_pointer_cast<ModelAPI_Folder>(anObject);
1097 theFolders.insert(aFeature);
1102 //**************************************************************
1103 QString translate(const Events_InfoMessage& theMessage)
1107 if (!theMessage.empty()) {
1108 std::string aStr = Config_Translator::translate(theMessage);
1109 if (!aStr.empty()) {
1110 std::string aCodec = Config_Translator::codec(theMessage);
1111 aMessage = QTextCodec::codecForName(aCodec.c_str())->toUnicode(aStr.c_str());
1118 QString translate(const std::string& theContext, const std::string& theMessage)
1122 if (!theMessage.empty()) {
1123 std::string aStr = Config_Translator::translate(theContext, theMessage);
1124 if (!aStr.empty()) {
1125 std::string aCodec = Config_Translator::codec(theContext);
1126 aMessage = QTextCodec::codecForName(aCodec.c_str())->toUnicode(aStr.c_str());
1133 void setPointBallHighlighting(AIS_InteractiveObject* theAIS)
1135 static Handle(Image_AlienPixMap) aPixMap;
1136 if(aPixMap.IsNull()) {
1137 // Load icon for the presentation
1139 char* anEnv = getenv("SHAPER_ROOT_DIR");
1141 aFile = std::string(anEnv) +
1142 FSEP + "share" + FSEP + "salome" + FSEP + "resources" + FSEP + "shaper";
1144 anEnv = getenv("CADBUILDER_ROOT_DIR");
1146 aFile = std::string(anEnv) + FSEP + "resources";
1150 static const std::string aMarkerName = "marker_dot.png";
1151 aFile += aMarkerName;
1152 aPixMap = new Image_AlienPixMap();
1153 if(!aPixMap->Load(aFile.c_str())) {
1154 // The icon for constraint is not found
1155 static const std::string aMsg =
1156 "Error: Point market not found by path: \"" + aFile + "\". Falling back.";
1157 //Events_InfoMessage("ModuleBase_Tools::setPointBallHighlighting", aMsg).send();
1161 Handle(Graphic3d_AspectMarker3d) anAspect;
1162 Handle(Prs3d_Drawer) aDrawer = theAIS->DynamicHilightAttributes();
1163 if (aDrawer.IsNull()) {
1164 if (ModuleBase_IViewer::DefaultHighlightDrawer.IsNull())
1166 aDrawer = new Prs3d_Drawer(*ModuleBase_IViewer::DefaultHighlightDrawer);
1167 if (!aDrawer->HasOwnPointAspect()) {
1168 aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_BALL, Quantity_NOC_BLACK, 2.0));
1171 if(aDrawer->HasOwnPointAspect()) {
1172 Handle(Prs3d_PointAspect) aPntAspect = aDrawer->PointAspect();
1173 if(aPixMap->IsEmpty()) {
1174 anAspect = aPntAspect->Aspect();
1175 anAspect->SetType(Aspect_TOM_BALL);
1177 if(aPixMap->Format() == Image_PixMap::ImgGray) {
1178 aPixMap->SetFormat (Image_PixMap::ImgAlpha);
1179 } else if(aPixMap->Format() == Image_PixMap::ImgGrayF) {
1180 aPixMap->SetFormat (Image_PixMap::ImgAlphaF);
1182 anAspect = new Graphic3d_AspectMarker3d(aPixMap);
1183 aPntAspect->SetAspect(anAspect);
1185 aDrawer->SetPointAspect(aPntAspect);
1186 theAIS->SetDynamicHilightAttributes(aDrawer);
1190 FeaturePtr createParameter(const QString& theText)
1192 FeaturePtr aParameter;
1193 QStringList aList = theText.split("=");
1194 if (aList.count() != 2) {
1197 QString aParamName = aList.at(0).trimmed();
1199 if (isNameExist(aParamName, FeaturePtr())) {
1203 if (!ModelAPI_Expression::isVariable(aParamName.toStdString())) {
1207 QString aExpression = aList.at(1).trimmed();
1208 if (aExpression.isEmpty()) {
1212 SessionPtr aMgr = ModelAPI_Session::get();
1213 std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
1215 aParameter = aDoc->addFeature("Parameter");
1216 if (aParameter.get()) {
1217 AttributeStringPtr aNameAttr = aParameter->string("variable");
1218 aNameAttr->setValue(aParamName.toStdString());
1220 AttributeStringPtr aExprAttr = aParameter->string("expression");
1221 aExprAttr->setValue(aExpression.toStdString());
1222 aParameter->execute();
1224 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1225 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
1230 void editParameter(FeaturePtr theParam, const QString& theText)
1232 QStringList aList = theText.split("=");
1233 QString aParamName = aList.at(0).trimmed();
1235 QString aExpression = aList.at(1).trimmed();
1236 if (aExpression.isEmpty()) {
1240 if (isNameExist(aParamName, theParam)) {
1243 AttributeStringPtr aNameAttr = theParam->string("variable");
1244 aNameAttr->setValue(aParamName.toStdString());
1246 AttributeStringPtr aExprAttr = theParam->string("expression");
1247 aExprAttr->setValue(aExpression.toStdString());
1248 theParam->execute();
1250 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
1253 bool isNameExist(const QString& theName, FeaturePtr theIgnoreParameter)
1255 SessionPtr aMgr = ModelAPI_Session::get();
1256 std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
1257 FeaturePtr aParamFeature;
1258 int aNbFeatures = aDoc->numInternalFeatures();
1259 std::string aName = theName.toStdString();
1260 for (int i = 0; i < aNbFeatures; i++) {
1261 aParamFeature = aDoc->internalFeature(i);
1262 if (aParamFeature && aParamFeature->getKind() == "Parameter") {
1263 if ((theIgnoreParameter != aParamFeature) && (aParamFeature->name() == aName))
1270 FeaturePtr findParameter(const QString& theName)
1272 SessionPtr aMgr = ModelAPI_Session::get();
1273 std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
1274 FeaturePtr aParamFeature;
1275 int aNbFeatures = aDoc->numInternalFeatures();
1276 std::string aName = theName.toStdString();
1277 for (int i = 0; i < aNbFeatures; i++) {
1278 aParamFeature = aDoc->internalFeature(i);
1279 if (aParamFeature && aParamFeature->getKind() == "Parameter") {
1280 if (aParamFeature->name() == aName)
1281 return aParamFeature;
1284 return FeaturePtr();
1288 //********************************************************************
1289 std::string generateName(const AttributePtr& theAttribute,
1290 ModuleBase_IWorkshop* theWorkshop)
1293 if (theAttribute.get() != NULL) {
1294 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
1295 if (aFeature.get()) {
1296 std::string aXmlCfg, aDescription;
1297 theWorkshop->module()->getXMLRepresentation(aFeature->getKind(), aXmlCfg, aDescription);
1299 ModuleBase_WidgetFactory aFactory(aXmlCfg, theWorkshop);
1300 std::string anAttributeTitle;
1301 aFactory.getAttributeTitle(theAttribute->id(), anAttributeTitle);
1303 std::stringstream aStreamName;
1304 aStreamName << theAttribute->owner()->data()->name() << "/" << anAttributeTitle.c_str();
1305 aName = aStreamName.str();
1311 bool isSameShape(const TopoDS_Shape& theShape1, const TopoDS_Shape& theShape2)
1313 // In case of compound we cannot rely on simple comparison method.
1314 // If the compound is generated by Group feature then this compound is alwais new.
1315 // So, we have to compare content of these compounds
1316 if (theShape1.ShapeType() != theShape2.ShapeType())
1319 if (theShape1.ShapeType() != TopAbs_COMPOUND)
1320 return theShape1.IsSame(theShape2);
1322 TopoDS_Iterator aIt1(theShape1);
1323 TopoDS_Iterator aIt2(theShape2);
1325 for (; aIt1.More() && aIt2.More(); aIt1.Next(), aIt2.Next()) {
1326 if (!(aIt1.Value()).IsSame(aIt2.Value()))
1332 qreal currentPixelRatio()
1334 QWindowList aWnds = qApp->topLevelWindows();
1335 if (aWnds.size() > 0)
1336 return aWnds.first()->devicePixelRatio();
1337 return qApp->primaryScreen()->devicePixelRatio();
1341 } // namespace ModuleBase_Tools