X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchPlugin%2FSketchPlugin_Sketch.cpp;h=a66bd9ffb1b6a3040a79c005147862739e5db233;hb=d2c592943592ae2d6118e1881ea899df81d692dc;hp=5342bf832b68bdecfff05747602d976b0cee614a;hpb=cd9217d7e87997ec8bc150a6d8c389e742ca0f84;p=modules%2Fshaper.git diff --git a/src/SketchPlugin/SketchPlugin_Sketch.cpp b/src/SketchPlugin/SketchPlugin_Sketch.cpp index 5342bf832..a66bd9ffb 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.cpp +++ b/src/SketchPlugin/SketchPlugin_Sketch.cpp @@ -2,19 +2,31 @@ // Created: 27 Mar 2014 // Author: Mikhail PONIKAROV -#include "SketchPlugin_Sketch.h" -#include -#include +#include + +#include +#include + #include +#include +#include #include + #include #include -#include -#include -#include + +#include +#include +#include +#include +#include #include -#include +#include + +#include + +#include using namespace std; @@ -74,22 +86,49 @@ void SketchPlugin_Sketch::execute() if (aFeaturesPreview.empty()) return; - std::list > aLoops; - std::list > aWires; - GeomAlgoAPI_SketchBuilder::createFaces(anOrigin->pnt(), aDirX->dir(), aDirY->dir(), aNorm->dir(), - aFeaturesPreview, aLoops, aWires); - aLoops.insert(aLoops.end(), aWires.begin(), aWires.end()); - boost::shared_ptr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aLoops); + // Collect all edges as one big wire + boost::shared_ptr aBigWire(new GeomAPI_PlanarEdges); + std::list >::const_iterator aShapeIt = aFeaturesPreview.begin(); + for (; aShapeIt != aFeaturesPreview.end(); ++aShapeIt) { + aBigWire->addEdge(*aShapeIt); + } + aBigWire->setOrigin(anOrigin->pnt()); + aBigWire->setDirX(aDirX->dir()); + aBigWire->setDirY(aDirY->dir()); + aBigWire->setNorm(aNorm->dir()); + +// GeomAlgoAPI_SketchBuilder::createFaces(anOrigin->pnt(), aDirX->dir(), aDirY->dir(), aNorm->dir(), +// aFeaturesPreview, aLoops, aWires); boost::shared_ptr aConstr = document()->createConstruction(data()); - aConstr->setShape(aCompound); + aConstr->setShape(aBigWire); setResult(aConstr); } -const void SketchPlugin_Sketch::addSub(const FeaturePtr& theFeature) +boost::shared_ptr SketchPlugin_Sketch::addFeature(std::string theID) { - boost::dynamic_pointer_cast(theFeature)->setSketch(this); - data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->append(theFeature); + boost::shared_ptr aNew = document()->addFeature(theID); + if (aNew) { + boost::dynamic_pointer_cast(aNew)->setSketch(this); + data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->append(aNew); + } + return aNew; +} + +int SketchPlugin_Sketch::numberOfSubs() const +{ + return data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->size(); +} + +boost::shared_ptr SketchPlugin_Sketch::subFeature(const int theIndex) const +{ + ObjectPtr anObj = data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->object(theIndex); + return boost::dynamic_pointer_cast(anObj); +} + +int SketchPlugin_Sketch::subFeatureId(const int theIndex) const +{ + return subFeature(theIndex)->data()->featureId(); } boost::shared_ptr SketchPlugin_Sketch::to3D(const double theX, const double theY) @@ -133,7 +172,7 @@ void addPlane(double theX, double theY, double theZ, { boost::shared_ptr anOrigin(new GeomAPI_Pnt(0, 0, 0)); boost::shared_ptr aNormal(new GeomAPI_Dir(theX, theY, theZ)); - double aSize = Config_PropManager::integer("Sketch definition", "Size of planes", PLANE_SIZE); + double aSize = Config_PropManager::integer("Sketch planes", "Size of planes", PLANE_SIZE); boost::shared_ptr aFace = GeomAlgoAPI_FaceBuilder::square(anOrigin, aNormal, aSize); theShapes.push_back(aFace); @@ -156,14 +195,30 @@ AISObjectPtr SketchPlugin_Sketch::getAISObject(AISObjectPtr thePrevious) aAIS = AISObjectPtr(new GeomAPI_AISObject()); aAIS->createShape(aCompound); - std::vector aRGB = Config_PropManager::color("Sketch definition", "planes_color", + std::vector aRGB = Config_PropManager::color("Sketch planes", "planes_color", SKETCH_PLANE_COLOR); aAIS->setColor(aRGB[0], aRGB[1], aRGB[2]); - aAIS->setWidth(Config_PropManager::integer("Sketch definition", "planes_thikness", + aAIS->setWidth(Config_PropManager::integer("Sketch planes", "planes_thickness", SKETCH_WIDTH)); } return aAIS; } return AISObjectPtr(); } + +void SketchPlugin_Sketch::erase() +{ + boost::shared_ptr aRefList = boost::dynamic_pointer_cast< + ModelAPI_AttributeRefList>(data()->attribute(SketchPlugin_Sketch::FEATURES_ID())); + std::list aFeatures = aRefList->list(); + std::list::const_iterator anIt = aFeatures.begin(); + for (; anIt != aFeatures.end(); anIt++) { + FeaturePtr aFeature = boost::dynamic_pointer_cast(*anIt); + if (aFeature) { + // subs are referenced from sketch, but must be removed for sure, so not checkings + document()->removeFeature(aFeature, false); + } + } + ModelAPI_CompositeFeature::erase(); +}