-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File: ModuleBase_Tools.cpp
-// Created: 11 July 2014
-// Author: Vitaly Smetannikov
+// Copyright (C) 2014-2019 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
#include "ModuleBase_Tools.h"
#include <ModuleBase_WidgetFactory.h>
#include <ModuleBase_IWorkshop.h>
#include <ModuleBase_IModule.h>
+#include <ModuleBase_IViewer.h>
#include <ModuleBase_IconFactory.h>
+#include <ModuleBase_ResultPrs.h>
+#include <ModuleBase_ViewerPrs.h>
#include <ModelAPI_Attribute.h>
#include <ModelAPI_AttributeRefAttr.h>
#include <ModelAPI_AttributeRefList.h>
#include <ModelAPI_AttributeRefAttrList.h>
#include <ModelAPI_ResultPart.h>
+#include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_Expression.h>
+#include <ModelAPI_ResultField.h>
#include <Events_Loop.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_Result.h>
-#include <ModelAPI_ResultCompSolid.h>
#include <ModelAPI_ResultParameter.h>
#include <ModelAPI_Tools.h>
#include <ModelAPI_Session.h>
#include <ModelAPI_Events.h>
+#include <ModelAPI_Folder.h>
+
+#include <ModelGeomAlgo_Point2D.h>
+#include <StdSelect_BRepOwner.hxx>
#include <TopoDS_Iterator.hxx>
+#include <AIS_InteractiveContext.hxx>
+#include <Prs3d_LineAspect.hxx>
+#include <Prs3d_PlaneAspect.hxx>
#include <GeomDataAPI_Point2D.h>
#include <Events_InfoMessage.h>
+#include <GeomAPI_ShapeExplorer.h>
#include <Config_PropManager.h>
+#include <Config_Translator.h>
+
+#include <Prs3d_PointAspect.hxx>
+#include <Graphic3d_AspectMarker3d.hxx>
+
+#include <Image_AlienPixMap.hxx>
#include <QWidget>
#include <QLayout>
#include <QApplication>
#include <QMessageBox>
#include <QAction>
+#include <QTextCodec>
+#include <QWindow>
+#include <QScreen>
#include <sstream>
#include <string>
+#ifdef WIN32
+#pragma warning(disable : 4996) // for getenv
+#endif
+
const double tolerance = 1e-7;
+const double DEFAULT_DEVIATION_COEFFICIENT = 1.e-4;
//#define DEBUG_ACTIVATE_WINDOW
//#define DEBUG_SET_FOCUS
+#ifdef WIN32
+# define FSEP "\\"
+#else
+# define FSEP "/"
+#endif
+
namespace ModuleBase_Tools {
//******************************************************************
void activateWindow(QWidget* theWidget, const QString& theInfo)
{
- theWidget->activateWindow();
+ if (theWidget) {
+ theWidget->activateWindow();
+ theWidget->raise();
+ }
#ifdef DEBUG_ACTIVATE_WINDOW
qDebug(QString("activateWindow: %1").arg(theInfo).toStdString().c_str());
void setFocus(QWidget* theWidget, const QString& theInfo)
{
theWidget->setFocus();
-
+ // rectangle of focus is not visible on tool button widgets
+ theWidget->update();
#ifdef DEBUG_SET_FOCUS
qDebug(QString("setFocus: %1").arg(theInfo).toStdString().c_str());
#endif
else {
QGraphicsEffect* anEffect = theWidget->graphicsEffect();
if(anEffect)
- anEffect->deleteLater();
+ anEffect->deleteLater();
theWidget->setGraphicsEffect(NULL);
}
}
{
QImage anIcon = ModuleBase_IconFactory::loadImage(theIcon);
QImage anAditional(theAdditionalIcon);
+ return composite(anAditional, anIcon);
+}
- if (anIcon.isNull())
+QPixmap composite(const QImage& theAdditionalIcon, QImage& theIcon)
+{
+ if (theIcon.isNull())
return QPixmap();
- int anAddWidth = anAditional.width();
- int anAddHeight = anAditional.height();
+ int anAddWidth = theAdditionalIcon.width();
+ int anAddHeight = theAdditionalIcon.height();
- int aWidth = anIcon.width();
- int aHeight = anIcon.height();
+ int aWidth = theIcon.width();
+ int aHeight = theIcon.height();
- int aStartWidthPos = aWidth - anAddWidth - 1;
- int aStartHeightPos = aHeight - anAddHeight - 1;
+ int aStartWidthPos = aWidth - anAddWidth;
+ int aStartHeightPos = aHeight - anAddHeight;
for (int i = 0; i < anAddWidth && i + aStartWidthPos < aWidth; i++)
{
for (int j = 0; j < anAddHeight && j + aStartHeightPos < aHeight; j++)
{
- if (qAlpha(anAditional.pixel(i, j)) > 0)
- anIcon.setPixel(i + aStartWidthPos, j + aStartHeightPos, anAditional.pixel(i, j));
+ if (qAlpha(theAdditionalIcon.pixel(i, j)) > 0)
+ theIcon.setPixel(i + aStartWidthPos, j + aStartHeightPos, theAdditionalIcon.pixel(i, j));
}
}
- return QPixmap::fromImage(anIcon);
+ return QPixmap::fromImage(theIcon);
}
QPixmap lighter(const QString& theIcon, const int theLighterValue)
void setSpinText(ModuleBase_ParamSpinBox* theSpin, const QString& theText)
{
- if (theSpin->text() == theText)
+ if (theSpin->text() == theText)
return;
// In order to avoid extra text setting because it will
// reset cursor position in control
void setSpinValue(ModuleBase_ParamSpinBox* theSpin, double theValue)
{
- if (fabs(theSpin->value() - theValue) < tolerance)
+ if (!theSpin->text().isEmpty() && fabs(theSpin->value() - theValue) < tolerance)
return;
bool isBlocked = theSpin->blockSignals(true);
theSpin->setValue(theValue);
return anAction;
}
+#ifdef _DEBUG
+QString objectName(const ObjectPtr& theObj)
+{
+ if (!theObj.get())
+ return "";
+
+ return theObj->data()->name().c_str();
+}
+
QString objectInfo(const ObjectPtr& theObj, const bool isUseAttributesInfo)
{
QString aFeatureStr = "feature";
if (aFeature.get()) {
aFeatureStr.append(QString(": %1").arg(aFeature->getKind().c_str()).toStdString().c_str());
if (aFeature->data()->isValid()) {
- aFeatureStr.append(QString(", name=%1").arg(aFeature->data()->name().c_str()).toStdString()
+ aFeatureStr.append(QString(", name=%1").arg(theObj->data()->name().c_str()).toStdString()
.c_str());
}
if (isUseAttributesInfo) {
- std::list<AttributePtr> anAttrs = aFeature->data()->attributes("");
- std::list<AttributePtr>::const_iterator anIt = anAttrs.begin(), aLast = anAttrs.end();
- QStringList aValues;
- for(; anIt != aLast; anIt++) {
- AttributePtr anAttr = *anIt;
- QString aValue = "not defined";
- std::string aType = anAttr->attributeType();
- if (aType == GeomDataAPI_Point2D::typeId()) {
- std::shared_ptr<GeomDataAPI_Point2D> aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- anAttr);
- if (aPoint.get())
- aValue = QString("(%1, %2)").arg(aPoint->x()).arg(aPoint->y());
- }
- else if (aType == ModelAPI_AttributeRefAttr::typeId()) {
- }
-
- aValues.push_back(QString("%1: %2").arg(anAttr->id().c_str()).arg(aValue).toStdString().c_str());
- }
- if (!aValues.empty())
- aFeatureStr.append(QString(", attributes: %1").arg(aValues.join(", ").toStdString().c_str()));
+ std::set<std::shared_ptr<ModelAPI_Attribute> > anAttributes;
+ std::string aPointsInfo = ModelGeomAlgo_Point2D::getPontAttributesInfo(aFeature,
+ anAttributes).c_str();
+ if (!aPointsInfo.empty())
+ aFeatureStr.append(QString(", attributes: %1")
+ .arg(aPointsInfo.c_str()).toStdString().c_str());
}
}
return aFeatureStr;
}
+#endif
-typedef QMap<QString, TopAbs_ShapeEnum> ShapeTypes;
-static ShapeTypes MyShapeTypes;
+typedef QMap<QString, int> ShapeTypes;
+static ShapeTypes myShapeTypes;
-TopAbs_ShapeEnum shapeType(const QString& theType)
+int shapeType(const QString& theType)
{
- if (MyShapeTypes.count() == 0) {
- MyShapeTypes["face"] = TopAbs_FACE;
- MyShapeTypes["faces"] = TopAbs_FACE;
- MyShapeTypes["vertex"] = TopAbs_VERTEX;
- MyShapeTypes["vertices"] = TopAbs_VERTEX;
- MyShapeTypes["wire"] = TopAbs_WIRE;
- MyShapeTypes["wires"] = TopAbs_WIRE;
- MyShapeTypes["edge"] = TopAbs_EDGE;
- MyShapeTypes["edges"] = TopAbs_EDGE;
- MyShapeTypes["shell"] = TopAbs_SHELL;
- MyShapeTypes["solid"] = TopAbs_SOLID;
- MyShapeTypes["solids"] = TopAbs_SOLID;
- MyShapeTypes["objects"] = TopAbs_SHAPE;
+ if (myShapeTypes.count() == 0) {
+ myShapeTypes["compound"] = TopAbs_COMPOUND;
+ myShapeTypes["compounds"] = TopAbs_COMPOUND;
+ myShapeTypes["compsolid"] = TopAbs_COMPSOLID;
+ myShapeTypes["compsolids"] = TopAbs_COMPSOLID;
+ myShapeTypes["solid"] = TopAbs_SOLID;
+ myShapeTypes["solids"] = TopAbs_SOLID;
+ myShapeTypes["shell"] = TopAbs_SHELL;
+ myShapeTypes["shells"] = TopAbs_SHELL;
+ myShapeTypes["face"] = TopAbs_FACE;
+ myShapeTypes["faces"] = TopAbs_FACE;
+ myShapeTypes["wire"] = TopAbs_WIRE;
+ myShapeTypes["wires"] = TopAbs_WIRE;
+ myShapeTypes["edge"] = TopAbs_EDGE;
+ myShapeTypes["edges"] = TopAbs_EDGE;
+ myShapeTypes["vertex"] = TopAbs_VERTEX;
+ myShapeTypes["vertices"] = TopAbs_VERTEX;
+ myShapeTypes["object"] = ModuleBase_ResultPrs::Sel_Result;
+ myShapeTypes["objects"] = ModuleBase_ResultPrs::Sel_Result;
}
QString aType = theType.toLower();
- if (MyShapeTypes.contains(aType))
- return MyShapeTypes[aType];
+ if(myShapeTypes.contains(aType))
+ return myShapeTypes[aType];
Events_InfoMessage("ModuleBase_Tools", "Shape type defined in XML is not implemented!").send();
return TopAbs_SHAPE;
}
void checkObjects(const QObjectPtrList& theObjects, bool& hasResult, bool& hasFeature,
- bool& hasParameter, bool& hasCompositeOwner)
+ bool& hasParameter, bool& hasCompositeOwner, bool& hasResultInHistory,
+ bool& hasFolder)
{
hasResult = false;
hasFeature = false;
hasParameter = false;
hasCompositeOwner = false;
+ hasResultInHistory = false;
+ hasFolder = false;
foreach(ObjectPtr aObj, theObjects) {
FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
+ FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(aObj);
ResultParameterPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aResult);
+ FieldStepPtr aStep = std::dynamic_pointer_cast<ModelAPI_ResultField::ModelAPI_FieldStep>(aObj);
- hasResult |= (aResult.get() != NULL);
+ hasResult |= ((aResult.get() != NULL) || (aStep.get() != NULL));
hasFeature |= (aFeature.get() != NULL);
+ hasFolder |= (aFolder.get() != NULL);
hasParameter |= (aConstruction.get() != NULL);
- if (hasFeature)
+ if (hasFeature)
hasCompositeOwner |= (ModelAPI_Tools::compositeOwner(aFeature) != NULL);
- if (hasFeature && hasResult && hasParameter && hasCompositeOwner)
+
+ if (!hasResultInHistory && aResult.get()) {
+ FeaturePtr aFeature = ModelAPI_Feature::feature(aResult);
+ hasResultInHistory = aFeature.get() && aFeature->isInHistory();
+ }
+
+ if (hasFeature && hasResult && hasParameter && hasCompositeOwner && hasFeature)
break;
}
}
+/*bool setDefaultDeviationCoefficient(std::shared_ptr<GeomAPI_Shape> theGeomShape)
+{
+ if (!theGeomShape.get())
+ return false;
+ // if the shape could not be exploded on faces, it contains only wires, edges, and vertices
+ // correction of deviation for them should not influence to the application performance
+ GeomAPI_ShapeExplorer anExp(theGeomShape, GeomAPI_Shape::FACE);
+ bool anEmpty = anExp.empty();
+ return !anExp.more();
+}*/
+
+/*void setDefaultDeviationCoefficient(const std::shared_ptr<ModelAPI_Result>& theResult,
+ const Handle(Prs3d_Drawer)& theDrawer)
+{
+ if (!theResult.get())
+ return;
+ bool aUseDeviation = false;
+
+ std::string aResultGroup = theResult->groupName();
+ if (aResultGroup == ModelAPI_ResultConstruction::group())
+ aUseDeviation = true;
+ else if (aResultGroup == ModelAPI_ResultBody::group()) {
+ GeomShapePtr aGeomShape = theResult->shape();
+ if (aGeomShape.get())
+ aUseDeviation = setDefaultDeviationCoefficient(aGeomShape);
+ }
+ if (aUseDeviation)
+ theDrawer->SetDeviationCoefficient(DEFAULT_DEVIATION_COEFFICIENT);
+}
+*/
void setDefaultDeviationCoefficient(const TopoDS_Shape& theShape,
const Handle(Prs3d_Drawer)& theDrawer)
{
if (theShape.IsNull())
return;
- TopAbs_ShapeEnum aType = theShape.ShapeType();
- if ((aType == TopAbs_EDGE) || (aType == TopAbs_WIRE))
- theDrawer->SetDeviationCoefficient(1.e-4);
+
+ std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape());
+ aGeomShape->setImpl(new TopoDS_Shape(theShape));
+
+ // if the shape could not be exploded on faces, it contains only wires, edges, and vertices
+ // correction of deviation for them should not influence to the application performance
+ GeomAPI_ShapeExplorer anExp(aGeomShape, GeomAPI_Shape::FACE);
+ bool isConstruction = !anExp.more();
+
+ double aDeflection;
+ if (isConstruction)
+ aDeflection = Config_PropManager::real("Visualization", "construction_deflection");
+ else
+ aDeflection = Config_PropManager::real("Visualization", "body_deflection");
+
+ theDrawer->SetDeviationCoefficient(aDeflection);
}
Quantity_Color color(const std::string& theSection,
- const std::string& theName,
- const std::string& theDefault)
+ const std::string& theName)
{
- std::vector<int> aColor = Config_PropManager::color(theSection, theName, theDefault);
+ std::vector<int> aColor = Config_PropManager::color(theSection, theName);
return Quantity_Color(aColor[0] / 255., aColor[1] / 255., aColor[2] / 255., Quantity_TOC_RGB);
}
ObjectPtr anObject;
std::string anAttrType = theAttribute->attributeType();
if (anAttrType == ModelAPI_AttributeRefAttr::typeId()) {
- AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+ AttributeRefAttrPtr anAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
if (anAttr != NULL && anAttr->isObject())
anObject = anAttr->object();
}
if (anAttrType == ModelAPI_AttributeSelection::typeId()) {
- AttributeSelectionPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
+ AttributeSelectionPtr anAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
if (anAttr != NULL)
anObject = anAttr->context();
}
if (anAttrType == ModelAPI_AttributeReference::typeId()) {
- AttributeReferencePtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
+ AttributeReferencePtr anAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
if (anAttr.get() != NULL)
anObject = anAttr->value();
}
return aShapeType;
}
+TopoDS_Shape getSelectedShape(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs)
+{
+ if (thePrs->shape().get())
+ return thePrs->shape()->impl<TopoDS_Shape>();
+
+ Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(thePrs->owner());
+ if (!anOwner.IsNull())
+ return anOwner->Shape();
+
+ return TopoDS_Shape();
+}
+
void getParameters(QStringList& theParameters)
{
theParameters.clear();
}
}
-std::string findGreedAttribute(ModuleBase_IWorkshop* theWorkshop, const FeaturePtr& theFeature)
+std::string findGreedAttribute(ModuleBase_IWorkshop* theWorkshop,
+ const FeaturePtr& theFeature)
{
std::string anAttributeId;
std::string aType = theAttribute->attributeType();
if (aType == ModelAPI_AttributeReference::typeId()) {
- AttributeReferencePtr aRef = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
+ AttributeReferencePtr aRef =
+ std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
ObjectPtr aObject = aRef->value();
aHasObject = aObject && aObject->isSame(theObject);
//if (!(aObject && aObject->isSame(theObject))) {
// aRef->setValue(theObject);
//}
} else if (aType == ModelAPI_AttributeRefAttr::typeId()) {
- AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+ AttributeRefAttrPtr aRefAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
AttributePtr anAttribute = theWorkshop->module()->findAttribute(theObject, theShape);
if (anAttribute.get()) {
std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
aHasObject = aSelectionListAttr->isInList(aResult, theShape, theTemporarily);
- //if (!theCheckIfAttributeHasObject || !aSelectionListAttr->isInList(aResult, theShape, theTemporarily))
- // aSelectionListAttr->append(aResult, theShape, theTemporarily);
}
else if (aType == ModelAPI_AttributeRefList::typeId()) {
- AttributeRefListPtr aRefListAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
+ AttributeRefListPtr aRefListAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
aHasObject = aRefListAttr->isInList(theObject);
//if (!theCheckIfAttributeHasObject || !aRefListAttr->isInList(theObject))
// aRefListAttr->append(theObject);
}
else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
- AttributeRefAttrListPtr aRefAttrListAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(theAttribute);
+ AttributeRefAttrListPtr aRefAttrListAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(theAttribute);
AttributePtr anAttribute = theWorkshop->module()->findAttribute(theObject, theShape);
if (anAttribute.get()) {
return aHasObject;
}
-void setObject(const AttributePtr& theAttribute, const ObjectPtr& theObject,
+bool setObject(const AttributePtr& theAttribute, const ObjectPtr& theObject,
const GeomShapePtr& theShape, ModuleBase_IWorkshop* theWorkshop,
const bool theTemporarily, const bool theCheckIfAttributeHasObject)
{
if (!theAttribute.get())
- return;
+ return false;
+ bool isDone = true;
std::string aType = theAttribute->attributeType();
if (aType == ModelAPI_AttributeReference::typeId()) {
- AttributeReferencePtr aRef = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
+ AttributeReferencePtr aRef =
+ std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
ObjectPtr aObject = aRef->value();
if (!(aObject && aObject->isSame(theObject))) {
aRef->setValue(theObject);
}
} else if (aType == ModelAPI_AttributeRefAttr::typeId()) {
- AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+ AttributeRefAttrPtr aRefAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
AttributePtr anAttribute = theWorkshop->module()->findAttribute(theObject, theShape);
if (anAttribute.get())
} else if (aType == ModelAPI_AttributeSelection::typeId()) {
AttributeSelectionPtr aSelectAttr =
std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
- ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
if (aSelectAttr.get() != NULL) {
- aSelectAttr->setValue(aResult, theShape, theTemporarily);
+ aSelectAttr->setValue(theObject, theShape, theTemporarily);
}
}
if (aType == ModelAPI_AttributeSelectionList::typeId()) {
AttributeSelectionListPtr aSelectionListAttr =
std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
- ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
- if (!theCheckIfAttributeHasObject || !aSelectionListAttr->isInList(aResult, theShape, theTemporarily))
- aSelectionListAttr->append(aResult, theShape, theTemporarily);
+ if (!theCheckIfAttributeHasObject ||
+ !aSelectionListAttr->isInList(theObject, theShape, theTemporarily))
+ aSelectionListAttr->append(theObject, theShape, theTemporarily);
}
else if (aType == ModelAPI_AttributeRefList::typeId()) {
- AttributeRefListPtr aRefListAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
- if (!theCheckIfAttributeHasObject || !aRefListAttr->isInList(theObject))
- aRefListAttr->append(theObject);
+ AttributeRefListPtr aRefListAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
+ if (!theCheckIfAttributeHasObject || !aRefListAttr->isInList(theObject)) {
+ if (theObject.get())
+ aRefListAttr->append(theObject);
+ else
+ isDone = false;
+ }
}
else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
- AttributeRefAttrListPtr aRefAttrListAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(theAttribute);
+ AttributeRefAttrListPtr aRefAttrListAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(theAttribute);
AttributePtr anAttribute = theWorkshop->module()->findAttribute(theObject, theShape);
if (anAttribute.get()) {
aRefAttrListAttr->append(anAttribute);
}
else {
- if (!theCheckIfAttributeHasObject || !aRefAttrListAttr->isInList(theObject))
- aRefAttrListAttr->append(theObject);
+ if (!theCheckIfAttributeHasObject || !aRefAttrListAttr->isInList(theObject)) {
+ if (theObject.get())
+ aRefAttrListAttr->append(theObject);
+ else
+ isDone = false;
+ }
}
}
+ return isDone;
}
GeomShapePtr getShape(const AttributePtr& theAttribute, ModuleBase_IWorkshop* theWorkshop)
std::string aType = theAttribute->attributeType();
if (aType == ModelAPI_AttributeReference::typeId()) {
} else if (aType == ModelAPI_AttributeRefAttr::typeId()) {
- AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+ AttributeRefAttrPtr aRefAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
if (aRefAttr.get() && !aRefAttr->isObject()) {
AttributePtr anAttribute = aRefAttr->attr();
aShape = theWorkshop->module()->findShape(anAttribute);
(theAttribute);
aShape = aSelectAttr->value();
}
+ else // Geom2D point processing
+ aShape = theWorkshop->module()->findShape(theAttribute);
return aShape;
}
{
blockUpdateViewer(true);
+ // Fix the problem of not previewed results of constraints applied. Flush Create/Delete
+ // (for the sketch result) to start processing of the sketch in the solver.
+ // TODO: these flushes should be moved in a separate method provided by Model
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
blockUpdateViewer(false);
}
int n = aWords.count();
QString aLine;
for (int i = 0; i < n; i++) {
- QString aLineExt = aLine + " " + aWords[i];
+ QString aLineExt = i == 0 ? aWords[i] : aLine + " " + aWords[i];
qreal anWidthNonExt = tfm.boundingRect(aLine).width();
qreal anWidthExt = tfm.boundingRect(aLineExt).width();
qreal aDeltaNonExt = fabs(anWidthNonExt-aGoldWidth);
}
//**************************************************************
-void refsToFeatureInFeatureDocument(const ObjectPtr& theObject, std::set<FeaturePtr>& theRefFeatures)
+QLocale doubleLocale()
+{
+ // VSR 01/07/2010: Disable thousands separator for spin box
+ // (to avoid inconsistency of double-2-string and string-2-double conversion)
+ QLocale aLocale;
+ aLocale.setNumberOptions(aLocale.numberOptions() |
+ QLocale::OmitGroupSeparator |
+ QLocale::RejectGroupSeparator);
+ return aLocale;
+}
+
+//**************************************************************
+void refsToFeatureInFeatureDocument(const ObjectPtr& theObject,
+ std::set<FeaturePtr>& theRefFeatures)
{
FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
if (aFeature.get()) {
//**************************************************************
-bool isSubOfComposite(const ObjectPtr& theObject)
+/*bool isSubOfComposite(const ObjectPtr& theObject)
{
bool isSub = false;
std::set<FeaturePtr> aRefFeatures;
isSub = isSubOfComposite(theObject, *anIt);
}
return isSub;
-}
+}*/
//**************************************************************
-bool isSubOfComposite(const ObjectPtr& theObject, const FeaturePtr& theFeature)
+/*bool isSubOfComposite(const ObjectPtr& theObject, const FeaturePtr& theFeature)
{
bool isSub = false;
CompositeFeaturePtr aComposite = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theFeature);
}
}
return isSub;
+}*/
+
+//**************************************************************
+ResultPtr firstResult(const ObjectPtr& theObject)
+{
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+ if (!aResult.get()) {
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
+ if (aFeature.get())
+ aResult = aFeature->firstResult();
+ }
+ return aResult;
}
//**************************************************************
return aFirstResult->groupName() == theGroupOfResult;
}
+//**************************************************************
+bool hasModuleDocumentFeature(const std::set<FeaturePtr>& theFeatures)
+{
+ bool aFoundModuleDocumentObject = false;
+ DocumentPtr aModuleDoc = ModelAPI_Session::get()->moduleDocument();
+
+ std::set<FeaturePtr>::const_iterator anIt = theFeatures.begin(), aLast = theFeatures.end();
+ for (; anIt != aLast && !aFoundModuleDocumentObject; anIt++) {
+ FeaturePtr aFeature = *anIt;
+ ResultPtr aResult = ModuleBase_Tools::firstResult(aFeature);
+ if (aResult.get() && aResult->groupName() == ModelAPI_ResultPart::group())
+ continue;
+ aFoundModuleDocumentObject = aFeature->document() == aModuleDoc;
+ }
+
+ return aFoundModuleDocumentObject;
+}
+
//**************************************************************
bool askToDelete(const std::set<FeaturePtr> theFeatures,
const std::map<FeaturePtr, std::set<FeaturePtr> >& theReferences,
QWidget* theParent,
- std::set<FeaturePtr>& theReferencesToDelete)
+ std::set<FeaturePtr>& theReferencesToDelete,
+ const std::string& thePrefixInfo)
{
+ QString aNotActivatedDocWrn;
+ std::string aNotActivatedNames;
+ if (!ModelAPI_Tools::allDocumentsActivated(aNotActivatedNames)) {
+ if (ModuleBase_Tools::hasModuleDocumentFeature(theFeatures))
+ aNotActivatedDocWrn =
+ QObject::tr("Selected objects can be used in Part documents which are not loaded: %1.\n")
+ .arg(aNotActivatedNames.c_str());
+ }
+
std::set<FeaturePtr> aFeaturesRefsTo;
std::set<FeaturePtr> aFeaturesRefsToParameter;
std::set<FeaturePtr> aParameterFeatures;
+ QStringList aPartFeatureNames;
std::set<FeaturePtr>::const_iterator anIt = theFeatures.begin(),
aLast = theFeatures.end();
// separate features to references to parameter features and references to others
if (theReferences.find(aFeature) == theReferences.end())
continue;
+ if (isFeatureOfResult(aFeature, ModelAPI_ResultPart::group()))
+ aPartFeatureNames.append(aFeature->name().c_str());
+
std::set<FeaturePtr> aRefFeatures;
std::set<FeaturePtr> aRefList = theReferences.at(aFeature);
std::set<FeaturePtr>::const_iterator aRefIt = aRefList.begin(), aRefLast = aRefList.end();
}
}
aParamFeatureNames.sort();
- QStringList aPartFeatureNames, anOtherFeatureNames;
+ QStringList anOtherFeatureNames;
anIt = theReferencesToDelete.begin();
aLast = theReferencesToDelete.end();
for (; anIt != aLast; anIt++) {
FeaturePtr aFeature = *anIt;
+ if (aFeature->getKind() == "RemoveResults")
+ continue; // skip the remove results feature mentioning: result will be removed anyway
if (isFeatureOfResult(aFeature, ModelAPI_ResultPart::group()))
aPartFeatureNames.append(aFeature->name().c_str());
else
aMessageBox.setDefaultButton(QMessageBox::No);
QString aText;
+ if (!thePrefixInfo.empty())
+ aText = thePrefixInfo.c_str();
QString aSep = ", ";
- if (!aPartFeatureNames.empty())
- aText += QString(QObject::tr("The following parts will be deleted: %1.\n")).arg(aPartFeatureNames.join(aSep));
- if (!anOtherFeatureNames.empty())
- aText += QString(QObject::tr("Selected features are used in the following features: %1.\nThese features will be deleted.\n"))
+ if (!aPartFeatureNames.empty()) {
+ aText += QString(QObject::tr("The following parts will be deleted: %1.\n"))
+ .arg(aPartFeatureNames.join(aSep));
+ }
+ if (!aNotActivatedDocWrn.isEmpty())
+ aText += aNotActivatedDocWrn;
+ if (!anOtherFeatureNames.empty()) {
+ const char* aMsg = "Features are used in the following features: %1.\nThese "
+ "features will be deleted.\n";
+ aText += QString(QObject::tr(aMsg))
.arg(anOtherFeatureNames.join(aSep));
+ }
if (!aParamFeatureNames.empty()) {
- aText += QString(QObject::tr("Selected parameters are used in the following features: %1.\nThese features will be deleted.\nOr parameters could be replaced by their values.\n"))
+ const char* aMsg = "Parameters are used directly and through a sequence "
+ "of dependencies in the following features: %1.\nThese features will "
+ "be deleted.\nOr parameters could be replaced by their values.\n";
+ aText += QString(QObject::tr(aMsg))
.arg(aParamFeatureNames.join(aSep));
- QPushButton *aReplaceButton = aMessageBox.addButton(QObject::tr("Replace"), QMessageBox::ActionRole);
+ QPushButton *aReplaceButton =
+ aMessageBox.addButton(QObject::tr("Replace"), QMessageBox::ActionRole);
}
if (!aText.isEmpty()) {
ModelAPI_ReplaceParameterMessage::send(aObj, 0);
}
else
- theReferencesToDelete.insert(aFeaturesRefsToParameterOnly.begin(), aFeaturesRefsToParameterOnly.end());
+ theReferencesToDelete.insert(aFeaturesRefsToParameterOnly.begin(),
+ aFeaturesRefsToParameterOnly.end());
}
return true;
}
if (!aFeature.get() && anObject->groupName() == ModelAPI_ResultParameter::group()) {
aFeature = ModelAPI_Feature::feature(anObject);
}
- theFeatures.insert(aFeature);
+ if (aFeature.get())
+ theFeatures.insert(aFeature);
+ }
+}
+
+//**************************************************************
+void convertToFolders(const QObjectPtrList& theObjects,
+ std::set<FolderPtr>& theFolders)
+{
+ QObjectPtrList::const_iterator anIt = theObjects.begin(), aLast = theObjects.end();
+ for(; anIt != aLast; anIt++) {
+ ObjectPtr anObject = *anIt;
+ FolderPtr aFeature = std::dynamic_pointer_cast<ModelAPI_Folder>(anObject);
+ if (aFeature.get())
+ theFolders.insert(aFeature);
}
}
+
+//**************************************************************
+QString translate(const Events_InfoMessage& theMessage)
+{
+ QString aMessage;
+
+ if (!theMessage.empty()) {
+ std::string aStr = Config_Translator::translate(theMessage);
+ if (!aStr.empty()) {
+ std::string aCodec = Config_Translator::codec(theMessage);
+ aMessage = QTextCodec::codecForName(aCodec.c_str())->toUnicode(aStr.c_str());
+ }
+ }
+
+ return aMessage;
+}
+
+QString translate(const std::string& theContext, const std::string& theMessage)
+{
+ QString aMessage;
+
+ if (!theMessage.empty()) {
+ std::string aStr = Config_Translator::translate(theContext, theMessage);
+ if (!aStr.empty()) {
+ std::string aCodec = Config_Translator::codec(theContext);
+ aMessage = QTextCodec::codecForName(aCodec.c_str())->toUnicode(aStr.c_str());
+ }
+ }
+
+ return aMessage;
+}
+
+void setPointBallHighlighting(AIS_Shape* theAIS)
+{
+ static Handle(Image_AlienPixMap) aPixMap;
+ if(aPixMap.IsNull()) {
+ // Load icon for the presentation
+ std::string aFile;
+ char* anEnv = getenv("SHAPER_ROOT_DIR");
+ if(anEnv) {
+ aFile = std::string(anEnv) +
+ FSEP + "share" + FSEP + "salome" + FSEP + "resources" + FSEP + "shaper";
+ } else {
+ anEnv = getenv("CADBUILDER_ROOT_DIR");
+ if (anEnv)
+ aFile = std::string(anEnv) + FSEP + "resources";
+ }
+
+ aFile += FSEP;
+ static const std::string aMarkerName = "marker_dot.png";
+ aFile += aMarkerName;
+ aPixMap = new Image_AlienPixMap();
+ if(!aPixMap->Load(aFile.c_str())) {
+ // The icon for constraint is not found
+ static const std::string aMsg =
+ "Error: Point market not found by path: \"" + aFile + "\". Falling back.";
+ //Events_InfoMessage("ModuleBase_Tools::setPointBallHighlighting", aMsg).send();
+ }
+ }
+
+ Handle(Graphic3d_AspectMarker3d) anAspect;
+ Handle(Prs3d_Drawer) aDrawer = theAIS->DynamicHilightAttributes();
+ if (aDrawer.IsNull()) {
+ if (ModuleBase_IViewer::DefaultHighlightDrawer.IsNull())
+ return;
+ aDrawer = new Prs3d_Drawer(*ModuleBase_IViewer::DefaultHighlightDrawer);
+ if (!aDrawer->HasOwnPointAspect()) {
+ aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_BALL, Quantity_NOC_BLACK, 2.0));
+ }
+ }
+ if(aDrawer->HasOwnPointAspect()) {
+ Handle(Prs3d_PointAspect) aPntAspect = aDrawer->PointAspect();
+ if(aPixMap->IsEmpty()) {
+ anAspect = aPntAspect->Aspect();
+ anAspect->SetType(Aspect_TOM_BALL);
+ } else {
+ if(aPixMap->Format() == Image_PixMap::ImgGray) {
+ aPixMap->SetFormat (Image_PixMap::ImgAlpha);
+ } else if(aPixMap->Format() == Image_PixMap::ImgGrayF) {
+ aPixMap->SetFormat (Image_PixMap::ImgAlphaF);
+ }
+ anAspect = new Graphic3d_AspectMarker3d(aPixMap);
+ aPntAspect->SetAspect(anAspect);
+ }
+ aDrawer->SetPointAspect(aPntAspect);
+ theAIS->SetDynamicHilightAttributes(aDrawer);
+ }
+}
+
+FeaturePtr createParameter(const QString& theText)
+{
+ FeaturePtr aParameter;
+ QStringList aList = theText.split("=");
+ if (aList.count() != 2) {
+ return aParameter;
+ }
+ QString aParamName = aList.at(0).trimmed();
+
+ if (isNameExist(aParamName, FeaturePtr())) {
+ return aParameter;
+ }
+
+ if (!ModelAPI_Expression::isVariable(aParamName.toStdString())) {
+ return aParameter;
+ }
+
+ QString aExpression = aList.at(1).trimmed();
+ if (aExpression.isEmpty()) {
+ return aParameter;
+ }
+
+ SessionPtr aMgr = ModelAPI_Session::get();
+ std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
+
+ aParameter = aDoc->addFeature("Parameter");
+ if (aParameter.get()) {
+ AttributeStringPtr aNameAttr = aParameter->string("variable");
+ aNameAttr->setValue(aParamName.toStdString());
+
+ AttributeStringPtr aExprAttr = aParameter->string("expression");
+ aExprAttr->setValue(aExpression.toStdString());
+ aParameter->execute();
+
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+ }
+ return aParameter;
+}
+
+void editParameter(FeaturePtr theParam, const QString& theText)
+{
+ QStringList aList = theText.split("=");
+ QString aParamName = aList.at(0).trimmed();
+
+ QString aExpression = aList.at(1).trimmed();
+ if (aExpression.isEmpty()) {
+ return;
+ }
+
+ if (isNameExist(aParamName, theParam)) {
+ return;
+ }
+ AttributeStringPtr aNameAttr = theParam->string("variable");
+ aNameAttr->setValue(aParamName.toStdString());
+
+ AttributeStringPtr aExprAttr = theParam->string("expression");
+ aExprAttr->setValue(aExpression.toStdString());
+ theParam->execute();
+
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+}
+
+bool isNameExist(const QString& theName, FeaturePtr theIgnoreParameter)
+{
+ SessionPtr aMgr = ModelAPI_Session::get();
+ std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
+ FeaturePtr aParamFeature;
+ int aNbFeatures = aDoc->numInternalFeatures();
+ std::string aName = theName.toStdString();
+ for (int i = 0; i < aNbFeatures; i++) {
+ aParamFeature = aDoc->internalFeature(i);
+ if (aParamFeature && aParamFeature->getKind() == "Parameter") {
+ if ((theIgnoreParameter != aParamFeature) && (aParamFeature->name() == aName))
+ return true;
+ }
+ }
+ return false;
+}
+
+FeaturePtr findParameter(const QString& theName)
+{
+ SessionPtr aMgr = ModelAPI_Session::get();
+ std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
+ FeaturePtr aParamFeature;
+ int aNbFeatures = aDoc->numInternalFeatures();
+ std::string aName = theName.toStdString();
+ for (int i = 0; i < aNbFeatures; i++) {
+ aParamFeature = aDoc->internalFeature(i);
+ if (aParamFeature && aParamFeature->getKind() == "Parameter") {
+ if (aParamFeature->name() == aName)
+ return aParamFeature;
+ }
+ }
+ return FeaturePtr();
+}
+
+
+//********************************************************************
+std::string generateName(const AttributePtr& theAttribute,
+ ModuleBase_IWorkshop* theWorkshop)
+{
+ std::string aName;
+ if (theAttribute.get() != NULL) {
+ ModuleBase_Operation* anOperation = theWorkshop->currentOperation();
+
+ FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
+ if (aFeature.get()) {
+ std::string aXmlCfg, aDescription;
+ theWorkshop->module()->getXMLRepresentation(aFeature->getKind(), aXmlCfg, aDescription);
+
+ ModuleBase_WidgetFactory aFactory(aXmlCfg, theWorkshop);
+ std::string anAttributeTitle;
+ aFactory.getAttributeTitle(theAttribute->id(), anAttributeTitle);
+
+ std::stringstream aStreamName;
+ aStreamName << theAttribute->owner()->data()->name() << "/" << anAttributeTitle.c_str();
+ aName = aStreamName.str();
+ }
+ }
+ return aName;
+}
+
+bool isSameShape(const TopoDS_Shape& theShape1, const TopoDS_Shape& theShape2)
+{
+ // In case of compound we cannot rely on simple comparison method.
+ // If the compound is generated by Group feature then this compound is alwais new.
+ // So, we have to compare content of these compounds
+ if (theShape1.ShapeType() != theShape2.ShapeType())
+ return false;
+
+ if (theShape1.ShapeType() != TopAbs_COMPOUND)
+ return theShape1.IsSame(theShape2);
+
+ TopoDS_Iterator aIt1(theShape1);
+ TopoDS_Iterator aIt2(theShape2);
+
+ for (; aIt1.More() && aIt2.More(); aIt1.Next(), aIt2.Next()) {
+ if (!(aIt1.Value()).IsSame(aIt2.Value()))
+ return false;
+ }
+ return true;
+}
+
+qreal currentPixelRatio()
+{
+ QWindowList aWnds = qApp->topLevelWindows();
+ if (aWnds.size() > 0)
+ return aWnds.first()->devicePixelRatio();
+ return qApp->primaryScreen()->devicePixelRatio();
+}
+
+
} // namespace ModuleBase_Tools