X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FFeaturesAPI%2FFeaturesAPI_Fillet.cpp;h=59c1c8e29a287fee81f4e857d59f8e147256734e;hb=06e7f5859095193fc7f498bd89a7d28009794f53;hp=d84e0017540195506e9f04f2f325d9817a6d0334;hpb=6a23207a9154dac27c710190281aa5bfcf2bd498;p=modules%2Fshaper.git diff --git a/src/FeaturesAPI/FeaturesAPI_Fillet.cpp b/src/FeaturesAPI/FeaturesAPI_Fillet.cpp index d84e00175..59c1c8e29 100644 --- a/src/FeaturesAPI/FeaturesAPI_Fillet.cpp +++ b/src/FeaturesAPI/FeaturesAPI_Fillet.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2017-2019 CEA/DEN, EDF R&D +// Copyright (C) 2017-2023 CEA, EDF // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -21,19 +21,111 @@ #include #include -////#include +#include #include +static GeomAPI_Shape::ShapeType typeOfSelection( + const std::list& theBaseObjects) +{ + std::string aType = theBaseObjects.empty() ? "SHAPE" : theBaseObjects.front().shapeType(); + return GeomAPI_Shape::shapeTypeByStr(aType); +} + +//================================================================================================== + FeaturesAPI_Fillet::FeaturesAPI_Fillet(const std::shared_ptr& theFeature) : ModelHighAPI_Interface(theFeature) +{ +} + +//================================================================================================== + +FeaturesAPI_Fillet1D::FeaturesAPI_Fillet1D(const std::shared_ptr& theFeature) + : FeaturesAPI_Fillet(theFeature) { initialize(); } -FeaturesAPI_Fillet::FeaturesAPI_Fillet(const std::shared_ptr& theFeature, - const std::list& theBaseObjects, - const ModelHighAPI_Double& theRadius) - : ModelHighAPI_Interface(theFeature) +FeaturesAPI_Fillet1D::FeaturesAPI_Fillet1D(const std::shared_ptr& theFeature, + const std::list& theBaseObjects, + const ModelHighAPI_Double& theRadius) + : FeaturesAPI_Fillet(theFeature) +{ + if (initialize()) { + setBase(theBaseObjects); + fillAttribute(theRadius, myradius); + + execIfBaseNotEmpty(); + } +} + +FeaturesAPI_Fillet1D::~FeaturesAPI_Fillet1D() +{ +} + +void FeaturesAPI_Fillet1D::setBase(const std::list& theBaseObjects) +{ + mybaseWires->clear(); + mybaseVertices->clear(); + + if (typeOfSelection(theBaseObjects) == GeomAPI_Shape::WIRE) { + fillAttribute(FeaturesPlugin_Fillet1D::CREATION_BY_WIRES(), mycreationMethod); + fillAttribute(theBaseObjects, mybaseWires); + } + else { + fillAttribute(FeaturesPlugin_Fillet1D::CREATION_BY_VERTICES(), mycreationMethod); + fillAttribute(theBaseObjects, mybaseVertices); + } + + execIfBaseNotEmpty(); +} + +void FeaturesAPI_Fillet1D::setRadius(const ModelHighAPI_Double& theRadius) +{ + fillAttribute(theRadius, myradius); + execIfBaseNotEmpty(); +} + +void FeaturesAPI_Fillet1D::execIfBaseNotEmpty() +{ + if (mybaseWires->size() > 0 || mybaseVertices->size() > 0) + execute(); +} + +void FeaturesAPI_Fillet1D::dump(ModelHighAPI_Dumper& theDumper) const +{ + FeaturePtr aBase = feature(); + const std::string& aDocName = theDumper.name(aBase->document()); + + AttributeSelectionListPtr anAttrObjects; + if (creationMethod()->value() == FeaturesPlugin_Fillet1D::CREATION_BY_WIRES()) + anAttrObjects = aBase->selectionList(FeaturesPlugin_Fillet1D::WIRE_LIST_ID()); + else if (creationMethod()->value() == FeaturesPlugin_Fillet1D::CREATION_BY_VERTICES()) + anAttrObjects = aBase->selectionList(FeaturesPlugin_Fillet1D::VERTEX_LIST_ID()); + + AttributeDoublePtr anAttrRadius = aBase->real(FeaturesPlugin_Fillet1D::RADIUS_ID()); + + theDumper << aBase << " = model.addFillet(" << aDocName << ", " << anAttrObjects + << ", " << anAttrRadius; + + if (!aBase->data()->version().empty()) + theDumper << ", keepSubResults = True"; + + theDumper << ")" << std::endl; +} + +//================================================================================================== + +FeaturesAPI_Fillet2D::FeaturesAPI_Fillet2D(const std::shared_ptr& theFeature) + : FeaturesAPI_Fillet(theFeature) +{ + initialize(); +} + +FeaturesAPI_Fillet2D::FeaturesAPI_Fillet2D(const std::shared_ptr& theFeature, + const std::list& theBaseObjects, + const ModelHighAPI_Double& theRadius) + : FeaturesAPI_Fillet(theFeature) { if (initialize()) { fillAttribute(FeaturesPlugin_Fillet::CREATION_METHOD_SINGLE_RADIUS(), mycreationMethod); @@ -44,11 +136,11 @@ FeaturesAPI_Fillet::FeaturesAPI_Fillet(const std::shared_ptr& } } -FeaturesAPI_Fillet::FeaturesAPI_Fillet(const std::shared_ptr& theFeature, - const std::list& theBaseObjects, - const ModelHighAPI_Double& theRadius1, - const ModelHighAPI_Double& theRadius2) - : ModelHighAPI_Interface(theFeature) +FeaturesAPI_Fillet2D::FeaturesAPI_Fillet2D(const std::shared_ptr& theFeature, + const std::list& theBaseObjects, + const ModelHighAPI_Double& theRadius1, + const ModelHighAPI_Double& theRadius2) + : FeaturesAPI_Fillet(theFeature) { if (initialize()) { fillAttribute(FeaturesPlugin_Fillet::CREATION_METHOD_VARYING_RADIUS(), mycreationMethod); @@ -60,12 +152,11 @@ FeaturesAPI_Fillet::FeaturesAPI_Fillet(const std::shared_ptr& } } -FeaturesAPI_Fillet::~FeaturesAPI_Fillet() +FeaturesAPI_Fillet2D::~FeaturesAPI_Fillet2D() { } -//================================================================================================== -void FeaturesAPI_Fillet::setBase(const std::list& theBaseObjects) +void FeaturesAPI_Fillet2D::setBase(const std::list& theBaseObjects) { mybaseObjects->clear(); fillAttribute(theBaseObjects, mybaseObjects); @@ -73,7 +164,7 @@ void FeaturesAPI_Fillet::setBase(const std::list& theBas execIfBaseNotEmpty(); } -void FeaturesAPI_Fillet::setRadius(const ModelHighAPI_Double& theRadius) +void FeaturesAPI_Fillet2D::setRadius(const ModelHighAPI_Double& theRadius) { fillAttribute(FeaturesPlugin_Fillet::CREATION_METHOD_SINGLE_RADIUS(), mycreationMethod); fillAttribute(theRadius, myradius); @@ -81,8 +172,8 @@ void FeaturesAPI_Fillet::setRadius(const ModelHighAPI_Double& theRadius) execIfBaseNotEmpty(); } -void FeaturesAPI_Fillet::setRadius(const ModelHighAPI_Double& theRadius1, - const ModelHighAPI_Double& theRadius2) +void FeaturesAPI_Fillet2D::setRadius(const ModelHighAPI_Double& theRadius1, + const ModelHighAPI_Double& theRadius2) { fillAttribute(FeaturesPlugin_Fillet::CREATION_METHOD_VARYING_RADIUS(), mycreationMethod); fillAttribute(theRadius1, mystartRadius); @@ -91,7 +182,7 @@ void FeaturesAPI_Fillet::setRadius(const ModelHighAPI_Double& theRadius1, execIfBaseNotEmpty(); } -void FeaturesAPI_Fillet::dump(ModelHighAPI_Dumper& theDumper) const +void FeaturesAPI_Fillet2D::dump(ModelHighAPI_Dumper& theDumper) const { FeaturePtr aBase = feature(); const std::string& aDocName = theDumper.name(aBase->document()); @@ -118,7 +209,7 @@ void FeaturesAPI_Fillet::dump(ModelHighAPI_Dumper& theDumper) const theDumper << ")" << std::endl; } -void FeaturesAPI_Fillet::execIfBaseNotEmpty() +void FeaturesAPI_Fillet2D::execIfBaseNotEmpty() { if (mybaseObjects->size() > 0) execute(); @@ -133,14 +224,20 @@ FilletPtr addFillet(const std::shared_ptr& thePart, const ModelHighAPI_Double& theRadius2, const bool keepSubResults) { - std::shared_ptr aFeature = thePart->addFeature(FeaturesAPI_Fillet::ID()); + GeomAPI_Shape::ShapeType aType = typeOfSelection(theBaseObjects); + bool is1D = aType == GeomAPI_Shape::WIRE || aType == GeomAPI_Shape::VERTEX; + + FeaturePtr aFeature = + thePart->addFeature(is1D ? FeaturesAPI_Fillet1D::ID() : FeaturesAPI_Fillet2D::ID()); if (!keepSubResults) aFeature->data()->setVersion(""); FilletPtr aFillet; - if (theRadius2.value() < 0.0) - aFillet.reset(new FeaturesAPI_Fillet(aFeature, theBaseObjects, theRadius1)); + if (is1D) + aFillet.reset(new FeaturesAPI_Fillet1D(aFeature, theBaseObjects, theRadius1)); + else if (theRadius2.value() < 0.0) + aFillet.reset(new FeaturesAPI_Fillet2D(aFeature, theBaseObjects, theRadius1)); else - aFillet.reset(new FeaturesAPI_Fillet(aFeature, theBaseObjects, theRadius1, theRadius2)); + aFillet.reset(new FeaturesAPI_Fillet2D(aFeature, theBaseObjects, theRadius1, theRadius2)); return aFillet; }