X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchAPI%2FSketchAPI_Sketch.cpp;h=8058fa5852acb12e0594f734d130c6f783098b7d;hb=f68074b0f3e013e10a9d06016ceac84827a5cdc2;hp=930828a68d9c3173996620db04c1b182738a9237;hpb=bd9d4bb5ec157cf7a6f8118d197d5a4c85706d83;p=modules%2Fshaper.git diff --git a/src/SketchAPI/SketchAPI_Sketch.cpp b/src/SketchAPI/SketchAPI_Sketch.cpp index 930828a68..8058fa585 100644 --- a/src/SketchAPI/SketchAPI_Sketch.cpp +++ b/src/SketchAPI/SketchAPI_Sketch.cpp @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include #include @@ -24,12 +24,14 @@ #include #include #include +#include #include #include #include //-------------------------------------------------------------------------------------- #include #include +#include #include #include #include @@ -37,9 +39,11 @@ #include //-------------------------------------------------------------------------------------- #include "SketchAPI_Arc.h" +#include "SketchAPI_MacroArc.h" #include "SketchAPI_Circle.h" #include "SketchAPI_IntersectionPoint.h" #include "SketchAPI_Line.h" +#include "SketchAPI_MacroCircle.h" #include "SketchAPI_Mirror.h" #include "SketchAPI_Point.h" #include "SketchAPI_Projection.h" @@ -292,23 +296,45 @@ std::shared_ptr SketchAPI_Sketch::addCircle( return CirclePtr(new SketchAPI_Circle(aFeature, theCenter, theRadius)); } -std::shared_ptr SketchAPI_Sketch::addCircle(double theX1, double theY1, - double theX2, double theY2, - double theX3, double theY3) +std::shared_ptr SketchAPI_Sketch::addCircle(double theCenterX, + double theCenterY, + double thePassedX, + double thePassedY) { std::shared_ptr aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID()); - return CirclePtr(new SketchAPI_Circle(aFeature, theX1, theY1, theX2, theY2, theX3, theY3)); + return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterX, theCenterY, + thePassedX, thePassedY)); } -std::shared_ptr SketchAPI_Sketch::addCircle( - const std::shared_ptr& thePoint1, - const std::shared_ptr& thePoint2, - const std::shared_ptr& thePoint3) +std::shared_ptr SketchAPI_Sketch::addCircle( + const std::shared_ptr& theCenterPoint, + const std::shared_ptr& thePassedPoint) +{ + std::shared_ptr aFeature = + compositeFeature()->addFeature(SketchPlugin_Circle::ID()); + return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterPoint, thePassedPoint)); +} + +std::shared_ptr SketchAPI_Sketch::addCircle(double theX1, double theY1, + double theX2, double theY2, + double theX3, double theY3) +{ + std::shared_ptr aFeature = + compositeFeature()->addFeature(SketchPlugin_Circle::ID()); + return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theX1, theY1, + theX2, theY2, + theX3, theY3)); +} + +std::shared_ptr SketchAPI_Sketch::addCircle( + const std::shared_ptr& thePoint1, + const std::shared_ptr& thePoint2, + const std::shared_ptr& thePoint3) { std::shared_ptr aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID()); - return CirclePtr(new SketchAPI_Circle(aFeature, thePoint1, thePoint2, thePoint3)); + return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, thePoint1, thePoint2, thePoint3)); } std::shared_ptr @@ -353,46 +379,47 @@ std::shared_ptr SketchAPI_Sketch::addArc( return ArcPtr(new SketchAPI_Arc(aFeature, theCenter, theStart, theEnd, theInversed)); } -std::shared_ptr SketchAPI_Sketch::addArc(double theStartX, double theStartY, +std::shared_ptr SketchAPI_Sketch::addArc(double theStartX, double theStartY, double theEndX, double theEndY, double thePassedX, double thePassedY) { std::shared_ptr aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID()); - return ArcPtr(new SketchAPI_Arc(aFeature, - theStartX, theStartY, - theEndX, theEndY, - thePassedX, thePassedY)); + return MacroArcPtr(new SketchAPI_MacroArc(aFeature, + theStartX, theStartY, + theEndX, theEndY, + thePassedX, thePassedY)); } -std::shared_ptr SketchAPI_Sketch::addArc( +std::shared_ptr SketchAPI_Sketch::addArc( const std::shared_ptr& theStart, const std::shared_ptr& theEnd, const std::shared_ptr& thePassed) { std::shared_ptr aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID()); - return ArcPtr(new SketchAPI_Arc(aFeature, theStart, theEnd, thePassed)); + return MacroArcPtr(new SketchAPI_MacroArc(aFeature, theStart, theEnd, thePassed)); } -std::shared_ptr SketchAPI_Sketch::addArc( +std::shared_ptr SketchAPI_Sketch::addArc( const ModelHighAPI_RefAttr& theTangentPoint, double theEndX, double theEndY, bool theInversed) { std::shared_ptr aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID()); - return ArcPtr(new SketchAPI_Arc(aFeature, theTangentPoint, theEndX, theEndY, theInversed)); + return MacroArcPtr(new SketchAPI_MacroArc( + aFeature, theTangentPoint, theEndX, theEndY, theInversed)); } -std::shared_ptr SketchAPI_Sketch::addArc( +std::shared_ptr SketchAPI_Sketch::addArc( const ModelHighAPI_RefAttr& theTangentPoint, const std::shared_ptr& theEnd, bool theInversed) { std::shared_ptr aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID()); - return ArcPtr(new SketchAPI_Arc(aFeature, theTangentPoint, theEnd, theInversed)); + return MacroArcPtr(new SketchAPI_MacroArc(aFeature, theTangentPoint, theEnd, theInversed)); } std::shared_ptr SketchAPI_Sketch::addArc(const ModelHighAPI_Selection & theExternal) @@ -481,6 +508,24 @@ std::shared_ptr SketchAPI_Sketch::addSplit( return InterfacePtr(new ModelHighAPI_Interface(aFeature)); } +//-------------------------------------------------------------------------------------- +std::shared_ptr SketchAPI_Sketch::addTrim( + const ModelHighAPI_Reference& theFeature, + const std::shared_ptr& thePositionPoint) +{ + std::shared_ptr aFeature = + compositeFeature()->addFeature(SketchPlugin_Trim::ID()); + fillAttribute(theFeature, aFeature->reference(SketchPlugin_Trim::SELECTED_OBJECT())); + + AttributePtr anAttribute = aFeature->attribute(SketchPlugin_Trim::SELECTED_POINT()); + if (anAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) { + AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast(anAttribute); + fillAttribute(thePositionPoint, aPointAttr); + } + + return InterfacePtr(new ModelHighAPI_Interface(aFeature)); +} + //-------------------------------------------------------------------------------------- std::shared_ptr SketchAPI_Sketch::setAngle( const ModelHighAPI_RefAttr & theLine1, @@ -584,17 +629,33 @@ std::shared_ptr SketchAPI_Sketch::setEqual( } std::shared_ptr SketchAPI_Sketch::setFillet( - const std::list & thePoints, - const ModelHighAPI_Double & theRadius) + const ModelHighAPI_RefAttr & thePoint) { std::shared_ptr aFeature = - compositeFeature()->addFeature(SketchPlugin_ConstraintFillet::ID()); - fillAttribute(thePoints, aFeature->data()->refattrlist(SketchPlugin_Constraint::ENTITY_A())); - fillAttribute(theRadius, aFeature->real(SketchPlugin_Constraint::VALUE())); - aFeature->execute(); + compositeFeature()->addFeature(SketchPlugin_Fillet::ID()); + fillAttribute(thePoint, aFeature->data()->refattr(SketchPlugin_Fillet::FILLET_POINT_ID())); + apply(); // finish operation to remove Fillet feature correcly return InterfacePtr(new ModelHighAPI_Interface(aFeature)); } +std::shared_ptr SketchAPI_Sketch::setFilletWithRadius( + const ModelHighAPI_RefAttr & thePoint, + const ModelHighAPI_Double & theRadius) +{ + CompositeFeaturePtr aSketch = compositeFeature(); + int aNbSubs = aSketch->numberOfSubs(); + + // create fillet + InterfacePtr aFilletFeature = setFillet(thePoint); + + // set radius for just created arc + FeaturePtr anArc = aSketch->subFeature(aNbSubs - 1); + if (anArc->getKind() == SketchPlugin_Arc::ID()) + setRadius(ModelHighAPI_RefAttr(ObjectPtr(anArc->lastResult())), ModelHighAPI_Double(theRadius)); + + return aFilletFeature; +} + std::shared_ptr SketchAPI_Sketch::setFixed( const ModelHighAPI_RefAttr & theObject) { @@ -699,6 +760,22 @@ std::shared_ptr SketchAPI_Sketch::setVertical( //-------------------------------------------------------------------------------------- +std::shared_ptr SketchAPI_Sketch::to2D(const std::shared_ptr& thePoint) +{ + FeaturePtr aBase = feature(); + std::shared_ptr aC = std::dynamic_pointer_cast( + aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID())); + std::shared_ptr aNorm = std::dynamic_pointer_cast( + aBase->attribute(SketchPlugin_Sketch::NORM_ID())); + std::shared_ptr aX = std::dynamic_pointer_cast( + aBase->attribute(SketchPlugin_Sketch::DIRX_ID())); + std::shared_ptr aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir()))); + + return thePoint->to2D(aC->pnt(), aX->dir(), aY); +} + +//-------------------------------------------------------------------------------------- + void SketchAPI_Sketch::dump(ModelHighAPI_Dumper& theDumper) const { FeaturePtr aBase = feature(); @@ -719,8 +796,10 @@ void SketchAPI_Sketch::dump(ModelHighAPI_Dumper& theDumper) const // Check the plane is coordinate plane std::string aPlaneName = defaultPlane(anOrigin, aNormal, aDirX); - if (anExternal->context()) { // checking for selected planes - if (!aPlaneName.empty()) { + if(anExternal->context()) { // checking for selected planes + if (!aPlaneName.empty() + && anExternal->context()->data() + && anExternal->context()->data()->name() == aPlaneName) { // dump sketch based on coordinate plane theDumper << aBase << " = model.addSketch(" << aDocName << ", model.standardPlane(\"" << aPlaneName << "\"))" << std::endl;