From 61c8d0d8d485404fbdd8a2b6b623c790e56d606c Mon Sep 17 00:00:00 2001 From: dbv Date: Mon, 21 Dec 2015 14:54:15 +0300 Subject: [PATCH] Improvement #1140: Display of replicated Sketch entities with thinner line --- src/GeomAPI/GeomAPI_AISObject.cpp | 10 +++++++++ src/GeomAPI/GeomAPI_AISObject.h | 4 ++++ .../SketchPlugin_ConstraintMirror.cpp | 2 +- .../SketchPlugin_MultiRotation.cpp | 2 +- .../SketchPlugin_MultiTranslation.cpp | 2 +- src/SketchPlugin/SketchPlugin_Sketch.cpp | 5 ++++- src/SketchPlugin/SketchPlugin_Sketch.h | 4 +++- .../SketchPlugin_SketchEntity.cpp | 2 ++ src/SketchPlugin/SketchPlugin_SketchEntity.h | 21 +++++++++++++++++++ 9 files changed, 47 insertions(+), 5 deletions(-) diff --git a/src/GeomAPI/GeomAPI_AISObject.cpp b/src/GeomAPI/GeomAPI_AISObject.cpp index 198a18926..3f7646688 100644 --- a/src/GeomAPI/GeomAPI_AISObject.cpp +++ b/src/GeomAPI/GeomAPI_AISObject.cpp @@ -319,6 +319,16 @@ void GeomAPI_AISObject::setColor(const int& theColor) aContext->SetColor(anAIS, aColor, false); } +double GeomAPI_AISObject::width() +{ + double aWidth = 0.0; + Handle(AIS_InteractiveObject) anAIS = impl(); + if (!anAIS.IsNull()) { + aWidth = anAIS->Width(); + } + return aWidth; +} + bool GeomAPI_AISObject::setWidth(const double& theWidth) { bool isChanged = false; diff --git a/src/GeomAPI/GeomAPI_AISObject.h b/src/GeomAPI/GeomAPI_AISObject.h index c649ba938..18fd8fa94 100644 --- a/src/GeomAPI/GeomAPI_AISObject.h +++ b/src/GeomAPI/GeomAPI_AISObject.h @@ -122,6 +122,10 @@ class GeomAPI_AISObject : public GeomAPI_Interface GEOMAPI_EXPORT void getColor(int& theR, int& theG, int& theB); + /// \return Current width of the lines of shape + GEOMAPI_EXPORT + double width(); + /// \brief Assigns the width of the lines of shape GEOMAPI_EXPORT bool setWidth(const double& theWidth); diff --git a/src/SketchPlugin/SketchPlugin_ConstraintMirror.cpp b/src/SketchPlugin/SketchPlugin_ConstraintMirror.cpp index 371830c76..bfcbf14e7 100755 --- a/src/SketchPlugin/SketchPlugin_ConstraintMirror.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintMirror.cpp @@ -130,7 +130,7 @@ void SketchPlugin_ConstraintMirror::execute() if (aMirrorIter != aMirroredList.end()) break; // the lists are inconsistent // There is no mirrored object yet, create it - FeaturePtr aNewFeature = SketchPlugin_Sketch::addUniqueNamedCopiedFeature(aFeatureIn, sketch()); + FeaturePtr aNewFeature = SketchPlugin_Sketch::addUniqueNamedCopiedFeature(aFeatureIn, sketch(), true); aNewFeature->execute(); ModelAPI_EventCreator::get()->sendUpdated(aNewFeature, aRedisplayEvent); diff --git a/src/SketchPlugin/SketchPlugin_MultiRotation.cpp b/src/SketchPlugin/SketchPlugin_MultiRotation.cpp index 274f8d64a..bd7fec21f 100755 --- a/src/SketchPlugin/SketchPlugin_MultiRotation.cpp +++ b/src/SketchPlugin/SketchPlugin_MultiRotation.cpp @@ -229,7 +229,7 @@ ObjectPtr SketchPlugin_MultiRotation::copyFeature(ObjectPtr theObject) if (!aFeature || !aResult) return ObjectPtr(); - FeaturePtr aNewFeature = SketchPlugin_Sketch::addUniqueNamedCopiedFeature(aFeature, sketch()); + FeaturePtr aNewFeature = SketchPlugin_Sketch::addUniqueNamedCopiedFeature(aFeature, sketch(), true); aNewFeature->execute(); static Events_ID aRedisplayEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY); diff --git a/src/SketchPlugin/SketchPlugin_MultiTranslation.cpp b/src/SketchPlugin/SketchPlugin_MultiTranslation.cpp index 2be40aecb..bc4a16755 100755 --- a/src/SketchPlugin/SketchPlugin_MultiTranslation.cpp +++ b/src/SketchPlugin/SketchPlugin_MultiTranslation.cpp @@ -206,7 +206,7 @@ ObjectPtr SketchPlugin_MultiTranslation::copyFeature(ObjectPtr theObject) if (!aFeature || !aResult) return ObjectPtr(); - FeaturePtr aNewFeature = SketchPlugin_Sketch::addUniqueNamedCopiedFeature(aFeature, sketch()); + FeaturePtr aNewFeature = SketchPlugin_Sketch::addUniqueNamedCopiedFeature(aFeature, sketch(), true); aNewFeature->execute(); static Events_ID aRedisplayEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY); diff --git a/src/SketchPlugin/SketchPlugin_Sketch.cpp b/src/SketchPlugin/SketchPlugin_Sketch.cpp index a63344e58..2117bc8b0 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.cpp +++ b/src/SketchPlugin/SketchPlugin_Sketch.cpp @@ -297,7 +297,8 @@ void SketchPlugin_Sketch::createPoint2DResult(ModelAPI_Feature* theFeature, } FeaturePtr SketchPlugin_Sketch::addUniqueNamedCopiedFeature(FeaturePtr theFeature, - SketchPlugin_Sketch* theSketch) + SketchPlugin_Sketch* theSketch, + const bool theIsCopy) { FeaturePtr aNewFeature = theSketch->addFeature(theFeature->getKind()); // addFeature generates a unique name for the feature, it caches the name @@ -308,6 +309,8 @@ FeaturePtr SketchPlugin_Sketch::addUniqueNamedCopiedFeature(FeaturePtr theFeatur aNewFeature->data()->setName(aUniqueFeatureName); // text expressions could block setValue of some attributes SketchPlugin_Tools::clearExpressions(aNewFeature); + // Set copy attribute + aNewFeature->data()->boolean(SketchPlugin_SketchEntity::COPY_ID())->setValue(theIsCopy); return aNewFeature; } diff --git a/src/SketchPlugin/SketchPlugin_Sketch.h b/src/SketchPlugin/SketchPlugin_Sketch.h index 8a1788c5c..d97ea573d 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.h +++ b/src/SketchPlugin/SketchPlugin_Sketch.h @@ -214,9 +214,11 @@ class SketchPlugin_Sketch : public ModelAPI_CompositeFeature, public GeomAPI_ICu /// The name of the created feature stays unique. /// \param theFeature a source feature /// \param theSketch a sketch intance + /// \param theIsCopy if true sets feature copy attribute to true. /// \return a created feature static FeaturePtr addUniqueNamedCopiedFeature(FeaturePtr theFeature, - SketchPlugin_Sketch* theSketch); + SketchPlugin_Sketch* theSketch, + const bool theIsCopy = false); /// Creates a plane of the sketch. /// \param theSketch a sketch intance diff --git a/src/SketchPlugin/SketchPlugin_SketchEntity.cpp b/src/SketchPlugin/SketchPlugin_SketchEntity.cpp index 9e95496ef..5382b6cc6 100644 --- a/src/SketchPlugin/SketchPlugin_SketchEntity.cpp +++ b/src/SketchPlugin/SketchPlugin_SketchEntity.cpp @@ -14,5 +14,7 @@ SketchPlugin_SketchEntity::SketchPlugin_SketchEntity() void SketchPlugin_SketchEntity::initAttributes() { data()->addAttribute(AUXILIARY_ID(), ModelAPI_AttributeBoolean::typeId()); + data()->addAttribute(COPY_ID(), ModelAPI_AttributeBoolean::typeId()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), AUXILIARY_ID()); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), COPY_ID()); } diff --git a/src/SketchPlugin/SketchPlugin_SketchEntity.h b/src/SketchPlugin/SketchPlugin_SketchEntity.h index b56992b89..3148b0c57 100644 --- a/src/SketchPlugin/SketchPlugin_SketchEntity.h +++ b/src/SketchPlugin/SketchPlugin_SketchEntity.h @@ -46,6 +46,13 @@ class SketchPlugin_SketchEntity : public SketchPlugin_Feature, public GeomAPI_IC return MY_EXTERNAL_ID; } + /// Reference to the copy type of the feature + inline static const std::string& COPY_ID() + { + static const std::string MY_COPY_ID("Copy"); + return MY_COPY_ID; + } + /// Request for initialization of data model of the feature: adding all attributes virtual void initAttributes(); @@ -58,6 +65,16 @@ class SketchPlugin_SketchEntity : public SketchPlugin_Feature, public GeomAPI_IC return false; } + /// Returns true of the feature is a copy of other feature + virtual bool isCopy() const + { + AttributeBooleanPtr anAttr = data()->boolean(COPY_ID()); + if(anAttr.get()) { + return anAttr->value(); + } + return false; + } + /// Customize presentation of the feature virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs, std::shared_ptr theDefaultPrs) @@ -104,6 +121,10 @@ class SketchPlugin_SketchEntity : public SketchPlugin_Feature, public GeomAPI_IC thePrs->setWidth(17); // thePrs->setPointMarker(1, 1.); // Set point as a '+' symbol } + if(isCopy()) { + double aWidth = thePrs->width(); + thePrs->setWidth(aWidth / 2.5); + } return isCustomized; } -- 2.39.2