X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_Tools.cpp;h=0fd66fd4813b96434be19e44642b4e437e5f0054;hb=ccebb4b23e0354829c9636110b903c59923d8e30;hp=2d32f553e341349d33808337ca0eb7f4c8e763fc;hpb=dc7d4d86b58b81684abc9b5a2be8ec30f210c2da;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp old mode 100755 new mode 100644 index 2d32f553e..0fd66fd48 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// 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 @@ -12,10 +12,9 @@ // // 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 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // #include @@ -37,6 +36,7 @@ #include #include +#include #include @@ -49,11 +49,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include @@ -71,6 +73,7 @@ #include #include #include +#include #include #include @@ -119,6 +122,9 @@ gp_Pnt PartSet_Tools::convertClickToPoint(QPoint thePoint, Handle(V3d_View) theV gp_Pnt EyePoint(XEye, YEye, ZEye); gp_Pnt AtPoint(XAt, YAt, ZAt); + if (EyePoint.Distance(AtPoint) < Precision::Confusion()) + return gp_Pnt(); + gp_Vec EyeVector(EyePoint, AtPoint); gp_Dir EyeDir(EyeVector); @@ -128,9 +134,8 @@ gp_Pnt PartSet_Tools::convertClickToPoint(QPoint thePoint, Handle(V3d_View) theV gp_Pnt ConvertedPoint(X, Y, Z); gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project(PlaneOfTheView, ConvertedPoint); - gp_Pnt ResultPoint = ElSLib::Value(ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(), + return ElSLib::Value(ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(), PlaneOfTheView); - return ResultPoint; } void PartSet_Tools::convertTo2D(const gp_Pnt& thePoint, FeaturePtr theSketch, @@ -311,6 +316,17 @@ std::shared_ptr PartSet_Tools::sketchPlane(CompositeFeaturePtr theS return aPlane; } +void PartSet_Tools::nullifySketchPlane(CompositeFeaturePtr theSketch) +{ + std::shared_ptr anOrigin = std::dynamic_pointer_cast( + theSketch->data()->attribute(SketchPlugin_Sketch::ORIGIN_ID())); + std::shared_ptr aNormal = std::dynamic_pointer_cast( + theSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID())); + + aNormal->reset(); + anOrigin->reset(); +} + std::shared_ptr PartSet_Tools::point3D(std::shared_ptr thePoint2D, CompositeFeaturePtr theSketch) { @@ -374,7 +390,13 @@ ResultPtr PartSet_Tools::createFixedObjectByExternal( AttributeRefAttrPtr aRefAttr = aProjectionFeature->data()->refattr( SketchPlugin_Projection::PROJECTED_FEATURE_ID()); if (!aRefAttr || !aRefAttr->isInitialized()) + { + // remove external feature if the attribute is not filled + std::set aFeatures; + aFeatures.insert(aProjectionFeature); + ModelAPI_Tools::removeFeaturesAndReferences(aFeatures); return ResultPtr(); + } FeaturePtr aProjection = ModelAPI_Feature::feature(aRefAttr->object()); if (aProjection.get() && aProjection->lastResult().get()) @@ -424,9 +446,9 @@ GeomShapePtr PartSet_Tools::findShapeBy2DPoint(const AttributePtr& theAttribute, // attribute, returns the shape PartSet_Module* aModule = dynamic_cast(theWorkshop->module()); PartSet_SketcherMgr* aSketchMgr = aModule->sketchMgr(); - AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(anAttributeFeature, - aBRepShape, aSketchMgr->activeSketch()); - if (aPntAttr.get() != NULL && aPntAttr == theAttribute) { + std::pair aPntAttrIndex = PartSet_Tools::findAttributeBy2dPoint( + anAttributeFeature, aBRepShape, aSketchMgr->activeSketch()); + if (aPntAttrIndex.first.get() != NULL && aPntAttrIndex.first == theAttribute) { aShape = std::shared_ptr(new GeomAPI_Shape); aShape->setImpl(new TopoDS_Shape(aBRepShape)); break; @@ -464,6 +486,24 @@ std::shared_ptr PartSet_Tools::getPnt2d(QMouseEvent* theEvent, return std::shared_ptr(new GeomAPI_Pnt2d(aX, anY)); } +std::shared_ptr PartSet_Tools::getPnt2d(const Handle(V3d_View)& theView, + const TopoDS_Shape& theShape, + const FeaturePtr& theSketch) +{ + GeomPnt2dPtr aPoint2D; + if (!theShape.IsNull() && theShape.ShapeType() == TopAbs_VERTEX) { + const TopoDS_Vertex& aVertex = TopoDS::Vertex(theShape); + if (!aVertex.IsNull()) { + // the case when the point is taken from the existing vertex + gp_Pnt aPoint = BRep_Tool::Pnt(aVertex); + double aX, aY; + PartSet_Tools::convertTo2D(aPoint, theSketch, theView, aX, aY); + aPoint2D.reset(new GeomAPI_Pnt2d(aX, aY)); + } + } + return aPoint2D; +} + FeaturePtr findFirstCoincidenceByData(const DataPtr& theData, std::shared_ptr thePoint) { @@ -505,7 +545,7 @@ FeaturePtr PartSet_Tools::findFirstCoincidence(const FeaturePtr& theFeature, for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) { std::shared_ptr aAttr = (*aIt); FeaturePtr aConstrFeature = std::dynamic_pointer_cast(aAttr->owner()); - if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) { + if (aConstrFeature && aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) { std::shared_ptr a2dPnt = PartSet_Tools::getPoint(aConstrFeature, SketchPlugin_ConstraintCoincidence::ENTITY_A()); if (a2dPnt.get() && thePoint->isEqual(a2dPnt)) { @@ -611,12 +651,44 @@ std::shared_ptr PartSet_Tools::getCoincedencePoint(FeaturePtr the return aPnt; } -AttributePtr PartSet_Tools::findAttributeBy2dPoint(ObjectPtr theObj, - const TopoDS_Shape theShape, - FeaturePtr theSketch) +class PointWrapper +{ +public: + PointWrapper(AttributePtr theAttribute) + : myPoint(std::dynamic_pointer_cast(theAttribute)), + myArray(std::dynamic_pointer_cast(theAttribute)) + {} + + int size() const { return myPoint.get() ? 1 : (myArray.get() ? myArray->size() : 0); } + + GeomPointPtr point(int theIndex, FeaturePtr theSketch) + { + GeomPnt2dPtr aP2d; + if (myPoint.get()) + aP2d = myPoint->pnt(); + else if (myArray.get()) + aP2d = myArray->pnt(theIndex); + + GeomPointPtr aP3d; + if (aP2d.get()) + aP3d = PartSet_Tools::convertTo3D(aP2d->x(), aP2d->y(), theSketch); + return aP3d; + } + + bool isArray() const { return myArray.get(); } + +private: + AttributePoint2DPtr myPoint; + AttributePoint2DArrayPtr myArray; +}; + +std::pair PartSet_Tools::findAttributeBy2dPoint(ObjectPtr theObj, + const TopoDS_Shape theShape, + FeaturePtr theSketch) { AttributePtr anAttribute; + int aPointIndex = -1; FeaturePtr aFeature = ModelAPI_Feature::feature(theObj); if (aFeature) { if (theShape.ShapeType() == TopAbs_VERTEX) { @@ -629,25 +701,32 @@ AttributePtr PartSet_Tools::findAttributeBy2dPoint(ObjectPtr theObj, // find the given point in the feature attributes std::list anAttiributes = aFeature->data()->attributes(GeomDataAPI_Point2D::typeId()); + std::list anArrays = + aFeature->data()->attributes(GeomDataAPI_Point2DArray::typeId()); + anAttiributes.insert(anAttiributes.end(), anArrays.begin(), anArrays.end()); + std::list::const_iterator anIt = anAttiributes.begin(), aLast = anAttiributes.end(); + double aMinDistance = 1.e-6; // searching for point with minimal distance and < 1.e-6 for (; anIt != aLast && !anAttribute; anIt++) { - std::shared_ptr aCurPoint = - std::dynamic_pointer_cast(*anIt); - if (!aCurPoint->isInitialized()) - continue; - - std::shared_ptr aPnt = - convertTo3D(aCurPoint->x(), aCurPoint->y(), theSketch); - if (aPnt && (aPnt->distance(aValue) < Precision::Confusion())) { - anAttribute = aCurPoint; - break; + PointWrapper aWrapper(*anIt); + for (int anIndex = 0, aSize = aWrapper.size(); anIndex < aSize; ++anIndex) { + std::shared_ptr aPnt = aWrapper.point(anIndex, theSketch); + if (aPnt) { + double aDistance = aPnt->distance(aValue); + if (aDistance < aMinDistance) { + anAttribute = *anIt; + if (aWrapper.isArray()) + aPointIndex = anIndex; + aMinDistance = aPnt->distance(aValue); + } + } } } } } } - return anAttribute; + return std::pair(anAttribute, aPointIndex); } void PartSet_Tools::sendSubFeaturesEvent(const CompositeFeaturePtr& theComposite, @@ -657,7 +736,8 @@ void PartSet_Tools::sendSubFeaturesEvent(const CompositeFeaturePtr& theComposite return; static Events_Loop* aLoop = Events_Loop::loop(); - for (int i = 0; i < theComposite->numberOfSubs(); i++) { + int aNumberOfSubs = theComposite->numberOfSubs(); + for (int i = 0; i < aNumberOfSubs; i++) { FeaturePtr aSubFeature = theComposite->subFeature(i); static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get(); aECreator->sendUpdated(aSubFeature, theEventId); @@ -680,6 +760,35 @@ bool PartSet_Tools::isAuxiliarySketchEntity(const ObjectPtr& theObject) return isAuxiliaryFeature; } +bool PartSet_Tools::isIncludeIntoSketchResult(const ObjectPtr& theObject) +{ + // check the feature is neither Projection nor IntersectionPoint feature + FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); + if (aFeature->getKind() == SketchPlugin_Projection::ID() || + aFeature->getKind() == SketchPlugin_IntersectionPoint::ID()) + return false; + + // go through the references to the feature to check + // if it was created by Projection or Intersection + const std::set& aRefs = theObject->data()->refsToMe(); + for (std::set::const_iterator aRefIt = aRefs.begin(); + aRefIt != aRefs.end(); ++aRefIt) { + AttributePtr anAttr = *aRefIt; + std::string anIncludeToResultAttrName; + if (anAttr->id() == SketchPlugin_Projection::PROJECTED_FEATURE_ID()) + anIncludeToResultAttrName = SketchPlugin_Projection::INCLUDE_INTO_RESULT(); + else if (anAttr->id() == SketchPlugin_IntersectionPoint::INTERSECTION_POINTS_ID()) + anIncludeToResultAttrName = SketchPlugin_IntersectionPoint::INCLUDE_INTO_RESULT(); + + if (!anIncludeToResultAttrName.empty()) { + // check "include into result" flag + FeaturePtr aParent = ModelAPI_Feature::feature(anAttr->owner()); + return aParent->boolean(anIncludeToResultAttrName)->value(); + } + } + return true; +} + ResultPtr PartSet_Tools::createFixedByExternalCenter( const ObjectPtr& theObject, @@ -716,3 +825,99 @@ ResultPtr PartSet_Tools::createFixedByExternalCenter( return ResultPtr(); } + +void PartSet_Tools::getFirstAndLastIndexInFolder(const ObjectPtr& theFolder, + int& theFirst, int& theLast) +{ + theFirst = -1; + theLast = -1; + + DocumentPtr aDoc = theFolder->document(); + FolderPtr aFolder = std::dynamic_pointer_cast(theFolder); + if (!aFolder.get()) + return; + + AttributeReferencePtr aFirstFeatAttr = + aFolder->data()->reference(ModelAPI_Folder::FIRST_FEATURE_ID()); + if (!aFirstFeatAttr.get()) + return; + FeaturePtr aFirstFeatureInFolder = ModelAPI_Feature::feature(aFirstFeatAttr->value()); + if (!aFirstFeatureInFolder.get()) + return; + + FeaturePtr aLastFeatureInFolder = aFolder->lastVisibleFeature(); + if (!aLastFeatureInFolder.get()) + return; + + theFirst = aDoc->index(aFirstFeatureInFolder); + theLast = aDoc->index(aLastFeatureInFolder); +} + + +void PartSet_Tools::getDefaultColor(ObjectPtr theObject, const bool isEmptyColorValid, + std::vector& theColor) +{ + theColor.clear(); + // get default color from the preferences manager for the given result + if (theColor.empty()) { + std::string aSection, aName, aDefault; + theObject->colorConfigInfo(aSection, aName, aDefault); + if (!aSection.empty() && !aName.empty()) { + theColor = Config_PropManager::color(aSection, aName); + } + } + if (!isEmptyColorValid && theColor.empty()) { + // all AIS objects, where the color is not set, are in black. + // The color should be defined in XML or set in the attribute + theColor = Config_PropManager::color("Visualization", "object_default_color"); + Events_InfoMessage("PartSet_Tools", + "A default color is not defined in the preferences for this result type").send(); + } +} + +double PartSet_Tools::getDefaultDeflection(const ObjectPtr& theObject) +{ + double aDeflection = -1; + ResultPtr aResult = std::dynamic_pointer_cast(theObject); + if (aResult.get()) { + bool isConstruction = false; + + std::string aResultGroup = aResult->groupName(); + if (aResultGroup == ModelAPI_ResultConstruction::group()) + isConstruction = true; + else if (aResultGroup == ModelAPI_ResultBody::group()) { + GeomShapePtr aGeomShape = aResult->shape(); + if (aGeomShape.get()) { + // 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); + isConstruction = !anExp.more(); + } + } + if (isConstruction) + aDeflection = Config_PropManager::real("Visualization", "construction_deflection"); + else + aDeflection = Config_PropManager::real("Visualization", "body_deflection"); + } + return aDeflection; +} + + +double PartSet_Tools::getDefaultTransparency() +{ + return Config_PropManager::integer("Visualization", "shaper_default_transparency") / 100.; +} + +QCursor PartSet_Tools::getOperationCursor() +{ + int aId = Config_PropManager::integer(SKETCH_TAB_NAME, "operation_cursor"); + switch (aId) { + case 0: + return QCursor(Qt::ArrowCursor); + case 1: + return QCursor(Qt::CrossCursor); + case 2: + return QCursor(Qt::PointingHandCursor); + } + return QCursor(); +}