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 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 FeaturePtr 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())
460 std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape());
461 aGeomShape->setImpl(new TopoDS_Shape(theShape));
463 // if the shape could not be exploded on faces, it contains only wires, edges, and vertices
464 // correction of deviation for them should not influence to the application performance
465 GeomAPI_ShapeExplorer anExp(aGeomShape, GeomAPI_Shape::FACE);
466 bool isConstruction = !anExp.more();
470 aDeflection = Config_PropManager::real("Visualization", "construction_deflection");
472 aDeflection = Config_PropManager::real("Visualization", "body_deflection");
474 theDrawer->SetDeviationCoefficient(aDeflection);
477 Quantity_Color color(const std::string& theSection,
478 const std::string& theName)
480 std::vector<int> aColor = Config_PropManager::color(theSection, theName);
481 return Quantity_Color(aColor[0] / 255., aColor[1] / 255., aColor[2] / 255., Quantity_TOC_RGB);
484 ObjectPtr getObject(const AttributePtr& theAttribute)
487 std::string anAttrType = theAttribute->attributeType();
488 if (anAttrType == ModelAPI_AttributeRefAttr::typeId()) {
489 AttributeRefAttrPtr anAttr =
490 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
491 if (anAttr != NULL && anAttr->isObject())
492 anObject = anAttr->object();
494 if (anAttrType == ModelAPI_AttributeSelection::typeId()) {
495 AttributeSelectionPtr anAttr =
496 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
498 anObject = anAttr->context();
500 if (anAttrType == ModelAPI_AttributeReference::typeId()) {
501 AttributeReferencePtr anAttr =
502 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
503 if (anAttr.get() != NULL)
504 anObject = anAttr->value();
509 TopAbs_ShapeEnum getCompoundSubType(const TopoDS_Shape& theShape)
511 TopAbs_ShapeEnum aShapeType = theShape.ShapeType();
513 // for compounds check sub-shapes: it may be compound of needed type:
514 // Booleans may produce compounds of Solids
515 if (aShapeType == TopAbs_COMPOUND) {
516 for(TopoDS_Iterator aSubs(theShape); aSubs.More(); aSubs.Next()) {
517 if (!aSubs.Value().IsNull()) {
518 TopAbs_ShapeEnum aSubType = aSubs.Value().ShapeType();
519 if (aSubType == TopAbs_COMPOUND) { // compound of compound(s)
520 aShapeType = TopAbs_COMPOUND;
523 if (aShapeType == TopAbs_COMPOUND) {
524 aShapeType = aSubType;
525 } else if (aShapeType != aSubType) { // compound of shapes of different types
526 aShapeType = TopAbs_COMPOUND;
535 TopoDS_Shape getSelectedShape(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs)
537 if (thePrs->shape().get())
538 return thePrs->shape()->impl<TopoDS_Shape>();
540 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(thePrs->owner());
541 if (!anOwner.IsNull())
542 return anOwner->Shape();
544 return TopoDS_Shape();
547 void getParameters(QStringList& theParameters)
549 theParameters.clear();
551 SessionPtr aSession = ModelAPI_Session::get();
552 std::list<DocumentPtr> aDocList;
553 DocumentPtr anActiveDocument = aSession->activeDocument();
554 DocumentPtr aRootDocument = aSession->moduleDocument();
555 aDocList.push_back(anActiveDocument);
556 if (anActiveDocument != aRootDocument) {
557 aDocList.push_back(aRootDocument);
559 std::string aGroupId = ModelAPI_ResultParameter::group();
560 for(std::list<DocumentPtr>::const_iterator it = aDocList.begin(); it != aDocList.end(); ++it) {
561 DocumentPtr aDocument = *it;
562 int aSize = aDocument->size(aGroupId);
563 for (int i = 0; i < aSize; i++) {
564 ObjectPtr anObject = aDocument->object(aGroupId, i);
565 std::string aParameterName = anObject->data()->name();
566 theParameters.append(aParameterName.c_str());
571 std::string findGreedAttribute(ModuleBase_IWorkshop* theWorkshop,
572 const FeaturePtr& theFeature)
574 std::string anAttributeId;
576 std::string aXmlCfg, aDescription;
577 theWorkshop->module()->getXMLRepresentation(theFeature->getKind(), aXmlCfg, aDescription);
579 ModuleBase_WidgetFactory aFactory(aXmlCfg, theWorkshop);
580 std::string anAttributeTitle;
581 aFactory.getGreedAttribute(anAttributeId);
583 return anAttributeId;
586 bool hasObject(const AttributePtr& theAttribute, const ObjectPtr& theObject,
587 const std::shared_ptr<GeomAPI_Shape>& theShape,
588 ModuleBase_IWorkshop* theWorkshop,
589 const bool theTemporarily)
591 bool aHasObject = false;
592 if (!theAttribute.get())
595 std::string aType = theAttribute->attributeType();
596 if (aType == ModelAPI_AttributeReference::typeId()) {
597 AttributeReferencePtr aRef =
598 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
599 ObjectPtr aObject = aRef->value();
600 aHasObject = aObject && aObject->isSame(theObject);
601 //if (!(aObject && aObject->isSame(theObject))) {
602 // aRef->setValue(theObject);
604 } else if (aType == ModelAPI_AttributeRefAttr::typeId()) {
605 AttributeRefAttrPtr aRefAttr =
606 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
608 AttributePtr anAttribute = theWorkshop->module()->findAttribute(theObject, theShape);
609 if (anAttribute.get()) {
610 //aRefAttr->setAttr(anAttribute);
613 ObjectPtr aObject = aRefAttr->object();
614 aHasObject = aObject && aObject->isSame(theObject);
615 //if (!(aObject && aObject->isSame(theObject))) {
616 // aRefAttr->setObject(theObject);
619 } else if (aType == ModelAPI_AttributeSelection::typeId()) {
620 /*AttributeSelectionPtr aSelectAttr =
621 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
622 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
623 if (aSelectAttr.get() != NULL) {
624 aSelectAttr->setValue(aResult, theShape, theTemporarily);
627 if (aType == ModelAPI_AttributeSelectionList::typeId()) {
628 AttributeSelectionListPtr aSelectionListAttr =
629 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
630 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
631 aHasObject = aSelectionListAttr->isInList(aResult, theShape, theTemporarily);
633 else if (aType == ModelAPI_AttributeRefList::typeId()) {
634 AttributeRefListPtr aRefListAttr =
635 std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
636 aHasObject = aRefListAttr->isInList(theObject);
637 //if (!theCheckIfAttributeHasObject || !aRefListAttr->isInList(theObject))
638 // aRefListAttr->append(theObject);
640 else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
641 AttributeRefAttrListPtr aRefAttrListAttr =
642 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(theAttribute);
643 AttributePtr anAttribute = theWorkshop->module()->findAttribute(theObject, theShape);
645 if (anAttribute.get()) {
646 aHasObject = aRefAttrListAttr->isInList(anAttribute);
647 //if (!theCheckIfAttributeHasObject || !aRefAttrListAttr->isInList(anAttribute))
648 // aRefAttrListAttr->append(anAttribute);
651 aHasObject = aRefAttrListAttr->isInList(theObject);
652 //if (!theCheckIfAttributeHasObject || !aRefAttrListAttr->isInList(theObject))
653 // aRefAttrListAttr->append(theObject);
659 bool setObject(const AttributePtr& theAttribute, const ObjectPtr& theObject,
660 const GeomShapePtr& theShape, ModuleBase_IWorkshop* theWorkshop,
661 const bool theTemporarily, const bool theCheckIfAttributeHasObject)
663 if (!theAttribute.get())
667 std::string aType = theAttribute->attributeType();
668 if (aType == ModelAPI_AttributeReference::typeId()) {
669 AttributeReferencePtr aRef =
670 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
671 ObjectPtr aObject = aRef->value();
672 if (!(aObject && aObject->isSame(theObject))) {
673 aRef->setValue(theObject);
675 } else if (aType == ModelAPI_AttributeRefAttr::typeId()) {
676 AttributeRefAttrPtr aRefAttr =
677 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
679 AttributePtr anAttribute = theWorkshop->module()->findAttribute(theObject, theShape);
680 if (anAttribute.get())
681 aRefAttr->setAttr(anAttribute);
683 ObjectPtr aObject = aRefAttr->object();
684 if (!(aObject && aObject->isSame(theObject))) {
685 aRefAttr->setObject(theObject);
688 } else if (aType == ModelAPI_AttributeSelection::typeId()) {
689 AttributeSelectionPtr aSelectAttr =
690 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
691 if (aSelectAttr.get() != NULL) {
692 aSelectAttr->setValue(theObject, theShape, theTemporarily);
695 if (aType == ModelAPI_AttributeSelectionList::typeId()) {
696 AttributeSelectionListPtr aSelectionListAttr =
697 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
698 if (!theCheckIfAttributeHasObject ||
699 !aSelectionListAttr->isInList(theObject, theShape, theTemporarily))
700 aSelectionListAttr->append(theObject, theShape, theTemporarily);
702 else if (aType == ModelAPI_AttributeRefList::typeId()) {
703 AttributeRefListPtr aRefListAttr =
704 std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
705 if (!theCheckIfAttributeHasObject || !aRefListAttr->isInList(theObject)) {
707 aRefListAttr->append(theObject);
712 else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
713 AttributeRefAttrListPtr aRefAttrListAttr =
714 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(theAttribute);
715 AttributePtr anAttribute = theWorkshop->module()->findAttribute(theObject, theShape);
717 if (anAttribute.get()) {
718 if (!theCheckIfAttributeHasObject || !aRefAttrListAttr->isInList(anAttribute))
719 aRefAttrListAttr->append(anAttribute);
722 if (!theCheckIfAttributeHasObject || !aRefAttrListAttr->isInList(theObject)) {
724 aRefAttrListAttr->append(theObject);
733 GeomShapePtr getShape(const AttributePtr& theAttribute, ModuleBase_IWorkshop* theWorkshop)
736 if (!theAttribute.get())
739 std::string aType = theAttribute->attributeType();
740 if (aType == ModelAPI_AttributeReference::typeId()) {
741 } else if (aType == ModelAPI_AttributeRefAttr::typeId()) {
742 AttributeRefAttrPtr aRefAttr =
743 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
744 if (aRefAttr.get() && !aRefAttr->isObject()) {
745 AttributePtr anAttribute = aRefAttr->attr();
746 aShape = theWorkshop->module()->findShape(anAttribute);
748 } else if (aType == ModelAPI_AttributeSelection::typeId()) {
749 AttributeSelectionPtr aSelectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
751 aShape = aSelectAttr->value();
753 else // Geom2D point processing
754 aShape = theWorkshop->module()->findShape(theAttribute);
758 void flushUpdated(ObjectPtr theObject)
760 blockUpdateViewer(true);
762 // Fix the problem of not previewed results of constraints applied. Flush Create/Delete
763 // (for the sketch result) to start processing of the sketch in the solver.
764 // TODO: these flushes should be moved in a separate method provided by Model
765 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
766 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_VISUAL_ATTRIBUTES));
767 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
768 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
770 blockUpdateViewer(false);
773 void blockUpdateViewer(const bool theValue)
775 // the viewer update should be blocked in order to avoid the temporary feature content
776 // when the solver processes the feature, the redisplay message can be flushed
777 // what caused the display in the viewer preliminary states of object
778 // e.g. fillet feature, angle value change
779 std::shared_ptr<Events_Message> aMsg;
781 aMsg = std::shared_ptr<Events_Message>(
782 new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_BLOCKED)));
785 // the viewer update should be unblocked
786 aMsg = std::shared_ptr<Events_Message>(
787 new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_UNBLOCKED)));
789 Events_Loop::loop()->send(aMsg);
792 QString wrapTextByWords(const QString& theValue, QWidget* theWidget,
793 int theMaxLineInPixels)
795 static QFontMetrics tfm(theWidget ? theWidget->font() : QApplication::font());
796 static qreal phi = 2.618;
798 QRect aBounds = tfm.boundingRect(theValue);
799 if(aBounds.width() <= theMaxLineInPixels)
802 qreal s = aBounds.width() * aBounds.height();
803 qreal aGoldWidth = sqrt(s*phi);
805 QStringList aWords = theValue.split(" ", QString::SkipEmptyParts);
807 int n = aWords.count();
809 for (int i = 0; i < n; i++) {
810 QString aLineExt = i == 0 ? aWords[i] : aLine + " " + aWords[i];
811 qreal anWidthNonExt = tfm.boundingRect(aLine).width();
812 qreal anWidthExt = tfm.boundingRect(aLineExt).width();
813 qreal aDeltaNonExt = fabs(anWidthNonExt-aGoldWidth);
814 qreal aDeltaExt = fabs(anWidthExt-aGoldWidth);
815 if(aDeltaNonExt < aDeltaExt) {
817 aLines.append(aLine);
825 aLines.append(aLine);
827 QString aResult = aLines.join("\n");
831 //**************************************************************
832 QLocale doubleLocale()
834 // VSR 01/07/2010: Disable thousands separator for spin box
835 // (to avoid inconsistency of double-2-string and string-2-double conversion)
837 aLocale.setNumberOptions(aLocale.numberOptions() |
838 QLocale::OmitGroupSeparator |
839 QLocale::RejectGroupSeparator);
843 //**************************************************************
844 void refsToFeatureInFeatureDocument(const ObjectPtr& theObject,
845 std::set<FeaturePtr>& theRefFeatures)
847 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
848 if (aFeature.get()) {
849 DocumentPtr aFeatureDoc = aFeature->document();
850 // 1. find references in the current document
851 aFeatureDoc->refsToFeature(aFeature, theRefFeatures, false);
856 //**************************************************************
857 /*bool isSubOfComposite(const ObjectPtr& theObject)
860 std::set<FeaturePtr> aRefFeatures;
861 refsToFeatureInFeatureDocument(theObject, aRefFeatures);
862 std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
863 aLast = aRefFeatures.end();
864 for (; anIt != aLast && !isSub; anIt++) {
865 isSub = isSubOfComposite(theObject, *anIt);
870 //**************************************************************
871 /*bool isSubOfComposite(const ObjectPtr& theObject, const FeaturePtr& theFeature)
874 CompositeFeaturePtr aComposite = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theFeature);
875 if (aComposite.get()) {
876 isSub = aComposite->isSub(theObject);
877 // the recursive is possible, the parameters are sketch circle and extrusion cut. They are
878 // separated by composite sketch feature
880 int aNbSubs = aComposite->numberOfSubs();
881 for (int aSub = 0; aSub < aNbSubs && !isSub; aSub++) {
882 isSub = isSubOfComposite(theObject, aComposite->subFeature(aSub));
889 //**************************************************************
890 ResultPtr firstResult(const ObjectPtr& theObject)
892 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
893 if (!aResult.get()) {
894 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
896 aResult = aFeature->firstResult();
901 //**************************************************************
902 bool isFeatureOfResult(const FeaturePtr& theFeature, const std::string& theGroupOfResult)
904 bool isResult = false;
906 if (!theFeature->data()->isValid())
909 ResultPtr aFirstResult = theFeature->firstResult();
910 if (!aFirstResult.get())
913 return aFirstResult->groupName() == theGroupOfResult;
916 //**************************************************************
917 bool hasModuleDocumentFeature(const std::set<FeaturePtr>& theFeatures)
919 bool aFoundModuleDocumentObject = false;
920 DocumentPtr aModuleDoc = ModelAPI_Session::get()->moduleDocument();
922 std::set<FeaturePtr>::const_iterator anIt = theFeatures.begin(), aLast = theFeatures.end();
923 for (; anIt != aLast && !aFoundModuleDocumentObject; anIt++) {
924 FeaturePtr aFeature = *anIt;
925 ResultPtr aResult = ModuleBase_Tools::firstResult(aFeature);
926 if (aResult.get() && aResult->groupName() == ModelAPI_ResultPart::group())
928 aFoundModuleDocumentObject = aFeature->document() == aModuleDoc;
931 return aFoundModuleDocumentObject;
934 //**************************************************************
935 bool askToDelete(const std::set<FeaturePtr> theFeatures,
936 const std::map<FeaturePtr, std::set<FeaturePtr> >& theReferences,
938 std::set<FeaturePtr>& theReferencesToDelete,
939 const std::string& thePrefixInfo)
941 QString aNotActivatedDocWrn;
942 std::string aNotActivatedNames;
943 if (!ModelAPI_Tools::allDocumentsActivated(aNotActivatedNames)) {
944 if (ModuleBase_Tools::hasModuleDocumentFeature(theFeatures))
945 aNotActivatedDocWrn =
946 QObject::tr("Selected objects can be used in Part documents which are not loaded: %1.\n")
947 .arg(aNotActivatedNames.c_str());
950 std::set<FeaturePtr> aFeaturesRefsTo;
951 std::set<FeaturePtr> aFeaturesRefsToParameter;
952 std::set<FeaturePtr> aParameterFeatures;
953 QStringList aPartFeatureNames;
954 std::set<FeaturePtr>::const_iterator anIt = theFeatures.begin(),
955 aLast = theFeatures.end();
956 // separate features to references to parameter features and references to others
957 for (; anIt != aLast; anIt++) {
958 FeaturePtr aFeature = *anIt;
959 if (theReferences.find(aFeature) == theReferences.end())
962 if (isFeatureOfResult(aFeature, ModelAPI_ResultPart::group()))
963 aPartFeatureNames.append(aFeature->name().c_str());
965 std::set<FeaturePtr> aRefFeatures;
966 std::set<FeaturePtr> aRefList = theReferences.at(aFeature);
967 std::set<FeaturePtr>::const_iterator aRefIt = aRefList.begin(), aRefLast = aRefList.end();
968 for (; aRefIt != aRefLast; aRefIt++) {
969 FeaturePtr aRefFeature = *aRefIt;
970 if (theFeatures.find(aRefFeature) == theFeatures.end() && // it is not selected
971 aRefFeatures.find(aRefFeature) == aRefFeatures.end()) // it is not added
972 aRefFeatures.insert(aRefFeature);
975 if (isFeatureOfResult(aFeature, ModelAPI_ResultParameter::group())) {
976 aFeaturesRefsToParameter.insert(aRefFeatures.begin(), aRefFeatures.end());
977 aParameterFeatures.insert(aFeature);
980 theReferencesToDelete.insert(aRefFeatures.begin(), aRefFeatures.end());
984 std::set<FeaturePtr> aFeaturesRefsToParameterOnly;
985 anIt = aFeaturesRefsToParameter.begin();
986 aLast = aFeaturesRefsToParameter.end();
987 // separate features to references to parameter features and references to others
988 QStringList aParamFeatureNames;
989 for (; anIt != aLast; anIt++) {
990 FeaturePtr aFeature = *anIt;
991 if (theReferencesToDelete.find(aFeature) == theReferencesToDelete.end()) {
992 aFeaturesRefsToParameterOnly.insert(aFeature);
993 aParamFeatureNames.append(aFeature->name().c_str());
996 aParamFeatureNames.sort();
997 QStringList anOtherFeatureNames;
998 anIt = theReferencesToDelete.begin();
999 aLast = theReferencesToDelete.end();
1000 for (; anIt != aLast; anIt++) {
1001 FeaturePtr aFeature = *anIt;
1002 if (aFeature->getKind() == "RemoveResults")
1003 continue; // skip the remove results feature mentioning: result will be removed anyway
1004 if (isFeatureOfResult(aFeature, ModelAPI_ResultPart::group()))
1005 aPartFeatureNames.append(aFeature->name().c_str());
1007 anOtherFeatureNames.append(aFeature->name().c_str());
1009 aPartFeatureNames.sort();
1010 anOtherFeatureNames.sort();
1012 bool aCanReplaceParameters = !aFeaturesRefsToParameterOnly.empty();
1014 QMessageBox aMessageBox(theParent);
1015 aMessageBox.setWindowTitle(QObject::tr("Delete features"));
1016 aMessageBox.setIcon(QMessageBox::Warning);
1017 aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
1018 aMessageBox.setDefaultButton(QMessageBox::No);
1021 if (!thePrefixInfo.empty())
1022 aText = thePrefixInfo.c_str();
1023 QString aSep = ", ";
1024 if (!aPartFeatureNames.empty()) {
1025 aText += QString(QObject::tr("The following parts will be deleted: %1.\n"))
1026 .arg(aPartFeatureNames.join(aSep));
1028 if (!aNotActivatedDocWrn.isEmpty())
1029 aText += aNotActivatedDocWrn;
1030 if (!anOtherFeatureNames.empty()) {
1031 const char* aMsg = "Features are used in the following features: %1.\nThese "
1032 "features will be deleted.\n";
1033 aText += QString(QObject::tr(aMsg))
1034 .arg(anOtherFeatureNames.join(aSep));
1036 if (!aParamFeatureNames.empty()) {
1037 const char* aMsg = "Parameters are used directly and through a sequence "
1038 "of dependencies in the following features: %1.\nThese features will "
1039 "be deleted.\nOr parameters could be replaced by their values.\n";
1040 aText += QString(QObject::tr(aMsg))
1041 .arg(aParamFeatureNames.join(aSep));
1042 QPushButton *aReplaceButton =
1043 aMessageBox.addButton(QObject::tr("Replace"), QMessageBox::ActionRole);
1046 if (!aText.isEmpty()) {
1047 aText += "Would you like to continue?";
1048 aMessageBox.setText(aText);
1050 QMessageBox::ButtonRole aButtonRole = aMessageBox.buttonRole(aMessageBox.clickedButton());
1052 if (aButtonRole == QMessageBox::NoRole)
1055 if (aButtonRole == QMessageBox::ActionRole) {
1056 foreach (FeaturePtr aObj, aParameterFeatures)
1057 ModelAPI_ReplaceParameterMessage::send(aObj, 0);
1060 theReferencesToDelete.insert(aFeaturesRefsToParameterOnly.begin(),
1061 aFeaturesRefsToParameterOnly.end());
1066 //**************************************************************
1067 void convertToFeatures(const QObjectPtrList& theObjects, std::set<FeaturePtr>& theFeatures)
1069 QObjectPtrList::const_iterator anIt = theObjects.begin(), aLast = theObjects.end();
1070 for(; anIt != aLast; anIt++) {
1071 ObjectPtr anObject = *anIt;
1072 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
1073 // for parameter result, use the corresponded reature to be removed
1074 if (!aFeature.get() && anObject->groupName() == ModelAPI_ResultParameter::group()) {
1075 aFeature = ModelAPI_Feature::feature(anObject);
1078 theFeatures.insert(aFeature);
1082 //**************************************************************
1083 void convertToFolders(const QObjectPtrList& theObjects,
1084 std::set<FolderPtr>& theFolders)
1086 QObjectPtrList::const_iterator anIt = theObjects.begin(), aLast = theObjects.end();
1087 for(; anIt != aLast; anIt++) {
1088 ObjectPtr anObject = *anIt;
1089 FolderPtr aFeature = std::dynamic_pointer_cast<ModelAPI_Folder>(anObject);
1091 theFolders.insert(aFeature);
1096 //**************************************************************
1097 QString translate(const Events_InfoMessage& theMessage)
1101 if (!theMessage.empty()) {
1102 std::string aStr = Config_Translator::translate(theMessage);
1103 if (!aStr.empty()) {
1104 std::string aCodec = Config_Translator::codec(theMessage);
1105 aMessage = QTextCodec::codecForName(aCodec.c_str())->toUnicode(aStr.c_str());
1112 QString translate(const std::string& theContext, const std::string& theMessage)
1116 if (!theMessage.empty()) {
1117 std::string aStr = Config_Translator::translate(theContext, theMessage);
1118 if (!aStr.empty()) {
1119 std::string aCodec = Config_Translator::codec(theContext);
1120 aMessage = QTextCodec::codecForName(aCodec.c_str())->toUnicode(aStr.c_str());
1127 void setPointBallHighlighting(AIS_Shape* theAIS)
1129 static Handle(Image_AlienPixMap) aPixMap;
1130 if(aPixMap.IsNull()) {
1131 // Load icon for the presentation
1133 char* anEnv = getenv("SHAPER_ROOT_DIR");
1135 aFile = std::string(anEnv) +
1136 FSEP + "share" + FSEP + "salome" + FSEP + "resources" + FSEP + "shaper";
1138 anEnv = getenv("CADBUILDER_ROOT_DIR");
1140 aFile = std::string(anEnv) + FSEP + "resources";
1144 static const std::string aMarkerName = "marker_dot.png";
1145 aFile += aMarkerName;
1146 aPixMap = new Image_AlienPixMap();
1147 if(!aPixMap->Load(aFile.c_str())) {
1148 // The icon for constraint is not found
1149 static const std::string aMsg =
1150 "Error: Point market not found by path: \"" + aFile + "\". Falling back.";
1151 //Events_InfoMessage("ModuleBase_Tools::setPointBallHighlighting", aMsg).send();
1155 Handle(Graphic3d_AspectMarker3d) anAspect;
1156 Handle(Prs3d_Drawer) aDrawer = theAIS->DynamicHilightAttributes();
1157 if (aDrawer.IsNull()) {
1158 if (ModuleBase_IViewer::DefaultHighlightDrawer.IsNull())
1160 aDrawer = new Prs3d_Drawer(*ModuleBase_IViewer::DefaultHighlightDrawer);
1161 if (!aDrawer->HasOwnPointAspect()) {
1162 aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_BALL, Quantity_NOC_BLACK, 2.0));
1165 if(aDrawer->HasOwnPointAspect()) {
1166 Handle(Prs3d_PointAspect) aPntAspect = aDrawer->PointAspect();
1167 if(aPixMap->IsEmpty()) {
1168 anAspect = aPntAspect->Aspect();
1169 anAspect->SetType(Aspect_TOM_BALL);
1171 if(aPixMap->Format() == Image_PixMap::ImgGray) {
1172 aPixMap->SetFormat (Image_PixMap::ImgAlpha);
1173 } else if(aPixMap->Format() == Image_PixMap::ImgGrayF) {
1174 aPixMap->SetFormat (Image_PixMap::ImgAlphaF);
1176 anAspect = new Graphic3d_AspectMarker3d(aPixMap);
1177 aPntAspect->SetAspect(anAspect);
1179 aDrawer->SetPointAspect(aPntAspect);
1180 theAIS->SetDynamicHilightAttributes(aDrawer);
1184 FeaturePtr createParameter(const QString& theText)
1186 FeaturePtr aParameter;
1187 QStringList aList = theText.split("=");
1188 if (aList.count() != 2) {
1191 QString aParamName = aList.at(0).trimmed();
1193 if (isNameExist(aParamName, FeaturePtr())) {
1197 if (!ModelAPI_Expression::isVariable(aParamName.toStdString())) {
1201 QString aExpression = aList.at(1).trimmed();
1202 if (aExpression.isEmpty()) {
1206 SessionPtr aMgr = ModelAPI_Session::get();
1207 std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
1209 aParameter = aDoc->addFeature("Parameter");
1210 if (aParameter.get()) {
1211 AttributeStringPtr aNameAttr = aParameter->string("variable");
1212 aNameAttr->setValue(aParamName.toStdString());
1214 AttributeStringPtr aExprAttr = aParameter->string("expression");
1215 aExprAttr->setValue(aExpression.toStdString());
1216 aParameter->execute();
1218 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1219 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
1224 void editParameter(FeaturePtr theParam, const QString& theText)
1226 QStringList aList = theText.split("=");
1227 QString aParamName = aList.at(0).trimmed();
1229 QString aExpression = aList.at(1).trimmed();
1230 if (aExpression.isEmpty()) {
1234 if (isNameExist(aParamName, theParam)) {
1237 AttributeStringPtr aNameAttr = theParam->string("variable");
1238 aNameAttr->setValue(aParamName.toStdString());
1240 AttributeStringPtr aExprAttr = theParam->string("expression");
1241 aExprAttr->setValue(aExpression.toStdString());
1242 theParam->execute();
1244 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
1247 bool isNameExist(const QString& theName, FeaturePtr theIgnoreParameter)
1249 SessionPtr aMgr = ModelAPI_Session::get();
1250 std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
1251 FeaturePtr aParamFeature;
1252 int aNbFeatures = aDoc->numInternalFeatures();
1253 std::string aName = theName.toStdString();
1254 for (int i = 0; i < aNbFeatures; i++) {
1255 aParamFeature = aDoc->internalFeature(i);
1256 if (aParamFeature && aParamFeature->getKind() == "Parameter") {
1257 if ((theIgnoreParameter != aParamFeature) && (aParamFeature->name() == aName))
1264 FeaturePtr findParameter(const QString& theName)
1266 SessionPtr aMgr = ModelAPI_Session::get();
1267 std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
1268 FeaturePtr aParamFeature;
1269 int aNbFeatures = aDoc->numInternalFeatures();
1270 std::string aName = theName.toStdString();
1271 for (int i = 0; i < aNbFeatures; i++) {
1272 aParamFeature = aDoc->internalFeature(i);
1273 if (aParamFeature && aParamFeature->getKind() == "Parameter") {
1274 if (aParamFeature->name() == aName)
1275 return aParamFeature;
1278 return FeaturePtr();
1282 //********************************************************************
1283 std::string generateName(const AttributePtr& theAttribute,
1284 ModuleBase_IWorkshop* theWorkshop)
1287 if (theAttribute.get() != NULL) {
1288 ModuleBase_Operation* anOperation = theWorkshop->currentOperation();
1290 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
1291 if (aFeature.get()) {
1292 std::string aXmlCfg, aDescription;
1293 theWorkshop->module()->getXMLRepresentation(aFeature->getKind(), aXmlCfg, aDescription);
1295 ModuleBase_WidgetFactory aFactory(aXmlCfg, theWorkshop);
1296 std::string anAttributeTitle;
1297 aFactory.getAttributeTitle(theAttribute->id(), anAttributeTitle);
1299 std::stringstream aStreamName;
1300 aStreamName << theAttribute->owner()->data()->name() << "/" << anAttributeTitle.c_str();
1301 aName = aStreamName.str();
1307 bool isSameShape(const TopoDS_Shape& theShape1, const TopoDS_Shape& theShape2)
1309 // In case of compound we cannot rely on simple comparison method.
1310 // If the compound is generated by Group feature then this compound is alwais new.
1311 // So, we have to compare content of these compounds
1312 if (theShape1.ShapeType() != theShape2.ShapeType())
1315 if (theShape1.ShapeType() != TopAbs_COMPOUND)
1316 return theShape1.IsSame(theShape2);
1318 TopoDS_Iterator aIt1(theShape1);
1319 TopoDS_Iterator aIt2(theShape2);
1321 for (; aIt1.More() && aIt2.More(); aIt1.Next(), aIt2.Next()) {
1322 if (!(aIt1.Value()).IsSame(aIt2.Value()))
1328 qreal currentPixelRatio()
1330 QWindowList aWnds = qApp->topLevelWindows();
1331 if (aWnds.size() > 0)
1332 return aWnds.first()->devicePixelRatio();
1333 return qApp->primaryScreen()->devicePixelRatio();
1337 } // namespace ModuleBase_Tools