Salome HOME
Improvement #1140: Display of replicated Sketch entities with thinner line
authordbv <dbv@opencascade.com>
Mon, 21 Dec 2015 11:54:15 +0000 (14:54 +0300)
committerdbv <dbv@opencascade.com>
Mon, 21 Dec 2015 11:54:31 +0000 (14:54 +0300)
src/GeomAPI/GeomAPI_AISObject.cpp
src/GeomAPI/GeomAPI_AISObject.h
src/SketchPlugin/SketchPlugin_ConstraintMirror.cpp
src/SketchPlugin/SketchPlugin_MultiRotation.cpp
src/SketchPlugin/SketchPlugin_MultiTranslation.cpp
src/SketchPlugin/SketchPlugin_Sketch.cpp
src/SketchPlugin/SketchPlugin_Sketch.h
src/SketchPlugin/SketchPlugin_SketchEntity.cpp
src/SketchPlugin/SketchPlugin_SketchEntity.h

index 198a1892631ded1ab512bfaaf282d6f7b9473160..3f7646688b80eab7f6c9736522d5c8b05eec0de3 100644 (file)
@@ -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<Handle(AIS_InteractiveObject)>();
+  if (!anAIS.IsNull()) {
+    aWidth = anAIS->Width();
+  }
+  return aWidth;
+}
+
 bool GeomAPI_AISObject::setWidth(const double& theWidth)
 {
   bool isChanged = false;
index c649ba93862dbb829cb3b7c4ef67b5fed18dfca1..18fd8fa94ff576a38c69d0048d96d3996c088419 100644 (file)
@@ -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);
index 371830c761471fb377899b28a46ab18599913f74..bfcbf14e72d2110bfa7e03e8f800406fc55a0af9 100755 (executable)
@@ -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);
 
index 274f8d64a03c6346e99f83a3999891b88e407775..bd7fec21fbeb3e5f7064b8fe53b4c72191cf908c 100755 (executable)
@@ -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);
index 2be40aecbec2e5f1541887614507d6abfdd6199d..bc4a1675580c4d4019d10e6a62ec74b9d4b11781 100755 (executable)
@@ -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);
index a63344e58fda66b21299919bd574339b87b9fcad..2117bc8b0f1b12a109aaa9ccfdee818e09fc144c 100644 (file)
@@ -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;
 }
index 8a1788c5c0a18d863f38dacfff28e08f482f86d2..d97ea573dc1dcc30c1821c1d85802b2f390f87fc 100644 (file)
@@ -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
index 9e95496ef455fa95572ba3c4f53c1a0c82b3ac47..5382b6cc638fc1b6e24d7b32cc9dcc99f97174ac 100644 (file)
@@ -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());
 }
index b56992b893ccb06b8e398e3c0f64da326096e8fe..3148b0c57705a1d18a89f2ab8d1c168c442dfe30 100644 (file)
@@ -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<GeomAPI_ICustomPrs> 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;
   }