X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchPlugin%2FSketchPlugin_Projection.cpp;h=91b45643c5b46e6cf5848b9f9d4fc059d6b5a264;hb=15fc1914159f4671968f56eb32d878a022edcd8b;hp=7c0044a9b18f34d6172be23e67b004f275bcbf41;hpb=2532fb2df83ee1ddd9ff3e8b381d3788eaa15b69;p=modules%2Fshaper.git diff --git a/src/SketchPlugin/SketchPlugin_Projection.cpp b/src/SketchPlugin/SketchPlugin_Projection.cpp index 7c0044a9b..91b45643c 100644 --- a/src/SketchPlugin/SketchPlugin_Projection.cpp +++ b/src/SketchPlugin/SketchPlugin_Projection.cpp @@ -14,7 +14,8 @@ // 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 +// See http://www.salome-platform.org/ or +// email : webmaster.salome@opencascade.com // #include @@ -22,6 +23,7 @@ #include #include #include +#include #include #include @@ -38,6 +40,7 @@ #include #include #include +#include #include #include @@ -60,6 +63,8 @@ void SketchPlugin_Projection::initDerivedClassAttributes() data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::typeId()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID()); + data()->addAttribute(INCLUDE_INTO_RESULT(), ModelAPI_AttributeBoolean::typeId()); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), AUXILIARY_ID()); } @@ -70,14 +75,17 @@ void SketchPlugin_Projection::execute() return; FeaturePtr aProjection = ModelAPI_Feature::feature(aRefAttr->object()); - if (!lastResult().get() && aProjection->lastResult().get()) { + if (!lastResult().get()) { + bool hasProjResult = aProjection->lastResult().get() != NULL; ResultConstructionPtr aConstr = document()->createConstruction(data()); - aConstr->setShape(aProjection->lastResult()->shape()); + if (hasProjResult) + aConstr->setShape(aProjection->lastResult()->shape()); aConstr->setIsInHistory(false); aConstr->setDisplayed(false); setResult(aConstr); - aProjection->selection(EXTERNAL_ID())->setValue(lastResult(), lastResult()->shape()); + if (hasProjResult) + aProjection->selection(EXTERNAL_ID())->setValue(lastResult(), lastResult()->shape()); } // is sketch plane is changed (issue 1791), attribute of projection is not changed, but @@ -85,11 +93,6 @@ void SketchPlugin_Projection::execute() computeProjection(EXTERNAL_FEATURE_ID()); } -void SketchPlugin_Projection::move(double theDeltaX, double theDeltaY) -{ - // feature cannot be moved -} - void SketchPlugin_Projection::attributeChanged(const std::string& theID) { if ((theID == EXTERNAL_FEATURE_ID() || theID == EXTERNAL_ID()) && !myIsComputing) { @@ -99,19 +102,42 @@ void SketchPlugin_Projection::attributeChanged(const std::string& theID) } } +static bool isValidProjectionType(FeaturePtr theProjection, + GeomEdgePtr theEdge, + GeomVertexPtr theVertex) +{ + if (theVertex && theProjection->getKind() == SketchPlugin_Point::ID()) + return true; + if (theEdge) { + if (theEdge->isLine() && theProjection->getKind() == SketchPlugin_Line::ID()) + return true; + else if (theEdge->isCircle() && theProjection->getKind() == SketchPlugin_Circle::ID()) + return true; + else if (theEdge->isArc() && theProjection->getKind() == SketchPlugin_Arc::ID()) + return true; + } + return false; +} + void SketchPlugin_Projection::computeProjection(const std::string& theID) { AttributeSelectionPtr aExtFeature = std::dynamic_pointer_cast(attribute(EXTERNAL_FEATURE_ID())); - std::shared_ptr anEdge; - if (aExtFeature && aExtFeature->value() && aExtFeature->value()->isEdge()) { - anEdge = std::shared_ptr(new GeomAPI_Edge(aExtFeature->value())); - } else if (aExtFeature->context() && aExtFeature->context()->shape() && - aExtFeature->context()->shape()->isEdge()) { - anEdge = std::shared_ptr(new GeomAPI_Edge(aExtFeature->context()->shape())); + GeomShapePtr aShape; + GeomEdgePtr anEdge; + GeomVertexPtr aVertex; + if (aExtFeature) + aShape = aExtFeature->value(); + if (!aShape && aExtFeature->context()) + aShape = aExtFeature->context()->shape(); + if (aShape) { + if (aShape->isEdge()) + anEdge = GeomEdgePtr(new GeomAPI_Edge(aShape)); + else if (aShape->isVertex()) + aVertex = GeomVertexPtr(new GeomAPI_Vertex(aShape)); } - if (!anEdge.get()) + if (!anEdge && !aVertex) return; AttributeRefAttrPtr aRefAttr = data()->refattr(PROJECTED_FEATURE_ID()); @@ -121,18 +147,16 @@ void SketchPlugin_Projection::computeProjection(const std::string& theID) // if the type of feature differs with already selected, remove it and create once again bool hasPrevProj = aProjection.get() != 0; - if (hasPrevProj) { - if ((anEdge->isLine() && aProjection->getKind() != SketchPlugin_Line::ID()) || - (anEdge->isCircle() && aProjection->getKind() != SketchPlugin_Circle::ID()) || - (anEdge->isArc() && aProjection->getKind() != SketchPlugin_Arc::ID())) { - DocumentPtr aDoc = sketch()->document(); - - std::set aFeaturesToBeRemoved; - aFeaturesToBeRemoved.insert(aProjection); - ModelAPI_Tools::removeFeaturesAndReferences(aFeaturesToBeRemoved); - aProjection = FeaturePtr(); - aRefAttr->setObject(aProjection); - } + if (hasPrevProj && !isValidProjectionType(aProjection, anEdge, aVertex)) { + DocumentPtr aDoc = sketch()->document(); + + aRefAttr->setObject(data()->owner()); // to not remove of this remove reference to aProjection + std::set aFeaturesToBeRemoved; + aFeaturesToBeRemoved.insert(aProjection); + ModelAPI_Tools::removeFeaturesAndReferences(aFeaturesToBeRemoved); + aProjection = FeaturePtr(); + aRefAttr->setObject(aProjection); + hasPrevProj = false; } std::shared_ptr aSketchPlane = sketch()->plane(); @@ -141,10 +165,22 @@ void SketchPlugin_Projection::computeProjection(const std::string& theID) std::dynamic_pointer_cast(lastResult()); if (aResult && aResult->shape() && theID == EXTERNAL_FEATURE_ID()) { aResult->setShape(std::shared_ptr()); - aProjection->selection(EXTERNAL_ID())->setValue(lastResult(), lastResult()->shape()); + if (aProjection) + aProjection->selection(EXTERNAL_ID())->setValue(lastResult(), lastResult()->shape()); } - if (anEdge->isLine()) { + if (aVertex) { + std::shared_ptr aPrjPnt = aSketchPlane->project(aVertex->point()); + std::shared_ptr aPntInSketch = sketch()->to2D(aPrjPnt); + + if (!hasPrevProj) + aProjection = sketch()->addFeature(SketchPlugin_Point::ID()); + + // update coordinates of projection + std::dynamic_pointer_cast( + aProjection->attribute(SketchPlugin_Point::COORD_ID()))->setValue(aPntInSketch); + } + else if (anEdge->isLine()) { std::shared_ptr aFirst = aSketchPlane->project(anEdge->firstPoint()); std::shared_ptr aLast = aSketchPlane->project(anEdge->lastPoint()); @@ -168,6 +204,10 @@ void SketchPlugin_Projection::computeProjection(const std::string& theID) std::shared_ptr aCircle = anEdge->circle(); double aRadius = aCircle->radius(); + double aNormalsDot = aCircle->normal()->dot(aSketchPlane->direction()); + if (fabs(fabs(aNormalsDot) - 1.0) > tolerance) + return; // circle is not in the plane, parallel to the sketch plane + std::shared_ptr aCenter = aSketchPlane->project(aCircle->center()); std::shared_ptr aCenterInSketch = sketch()->to2D(aCenter); @@ -191,9 +231,17 @@ void SketchPlugin_Projection::computeProjection(const std::string& theID) std::shared_ptr aCenter = aSketchPlane->project(aCircle->center()); std::shared_ptr aCenterInSketch = sketch()->to2D(aCenter); + double aNormalsDot = aCircle->normal()->dot(aSketchPlane->direction()); + if (fabs(fabs(aNormalsDot) - 1.0) > tolerance) + return; // arc is not in the plane, parallel to the sketch plane + + bool isInversed = aNormalsDot < 0.; + if (!hasPrevProj) aProjection = sketch()->addFeature(SketchPlugin_Arc::ID()); + bool aWasBlocked = aProjection->data()->blockSendAttributeUpdated(true); + // update attributes of projection std::shared_ptr aCenterPnt = std::dynamic_pointer_cast( @@ -207,19 +255,24 @@ void SketchPlugin_Projection::computeProjection(const std::string& theID) aStartPnt->setValue(aFirstInSketch); aEndPnt->setValue(aLastInSketch); aCenterPnt->setValue(aCenterInSketch); - } + aProjection->boolean(SketchPlugin_Arc::REVERSED_ID())->setValue(isInversed); + + aProjection->data()->blockSendAttributeUpdated(aWasBlocked); + } else + return; aProjection->boolean(COPY_ID())->setValue(true); aProjection->execute(); aRefAttr->setObject(aProjection); if (theID == EXTERNAL_FEATURE_ID()) { - selection(EXTERNAL_ID())->setValue(aExtFeature->context(), aExtFeature->value()); + selection(EXTERNAL_ID())->selectValue(aExtFeature); if (aResult) { aResult->setShape(aProjection->lastResult()->shape()); setResult(aResult); - aProjection->selection(EXTERNAL_ID())->setValue(lastResult(), lastResult()->shape()); + GeomShapePtr anEmptyVal; + aProjection->selection(EXTERNAL_ID())->setValue(lastResult(), anEmptyVal); } } }