]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom.git into Dev_1.1.0
authorsbh <sergey.belash@opencascade.com>
Wed, 11 Mar 2015 15:52:21 +0000 (18:52 +0300)
committersbh <sergey.belash@opencascade.com>
Wed, 11 Mar 2015 15:52:21 +0000 (18:52 +0300)
68 files changed:
CMakeLists.txt
src/ConstructionPlugin/ConstructionPlugin_Axis.cpp
src/ConstructionPlugin/ConstructionPlugin_Axis.h
src/ConstructionPlugin/ConstructionPlugin_Plane.cpp
src/ConstructionPlugin/ConstructionPlugin_Plane.h
src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp
src/ConstructionPlugin/ConstructionPlugin_Point.cpp
src/ConstructionPlugin/ConstructionPlugin_Point.h
src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp
src/ExchangePlugin/ExchangePlugin_ImportFeature.h
src/ExchangePlugin/ExchangePlugin_Plugin.cpp
src/GeomAPI/CMakeLists.txt
src/GeomAPI/GeomAPI_AISObject.cpp
src/GeomAPI/GeomAPI_AISObject.h
src/GeomAPI/GeomAPI_Ax3.cpp [new file with mode: 0644]
src/GeomAPI/GeomAPI_Ax3.h [new file with mode: 0644]
src/GeomAPI/GeomAPI_ICustomPrs.h
src/GeomAPI/GeomAPI_PlanarEdges.cpp
src/GeomAPI/GeomAPI_PlanarEdges.h
src/GeomAlgoAPI/GeomAlgoAPI_DFLoader.cpp
src/Model/CMakeLists.txt
src/Model/Model_AttributeColor.cpp [deleted file]
src/Model/Model_AttributeColor.h [deleted file]
src/Model/Model_AttributeIntArray.cpp [new file with mode: 0644]
src/Model/Model_AttributeIntArray.h [new file with mode: 0644]
src/Model/Model_Data.cpp
src/Model/Model_Data.h
src/Model/Model_ResultBody.cpp
src/Model/Model_ResultBody.h
src/Model/Model_ResultConstruction.cpp
src/Model/Model_ResultConstruction.h
src/Model/Model_ResultGroup.cpp
src/Model/Model_ResultGroup.h
src/ModelAPI/CMakeLists.txt
src/ModelAPI/ModelAPI_AttributeColor.cpp [deleted file]
src/ModelAPI/ModelAPI_AttributeColor.h [deleted file]
src/ModelAPI/ModelAPI_AttributeIntArray.cpp [new file with mode: 0644]
src/ModelAPI/ModelAPI_AttributeIntArray.h [new file with mode: 0644]
src/ModelAPI/ModelAPI_Data.h
src/ModelAPI/ModelAPI_Result.h
src/ModuleBase/ModuleBase_Preferences.cpp
src/SketchPlugin/CMakeLists.txt
src/SketchPlugin/SketchPlugin_ConstraintCoincidence.cpp
src/SketchPlugin/SketchPlugin_ConstraintCoincidence.h
src/SketchPlugin/SketchPlugin_ConstraintParallel.cpp
src/SketchPlugin/SketchPlugin_ConstraintParallel.h
src/SketchPlugin/SketchPlugin_Sketch.cpp
src/SketchPlugin/SketchPlugin_Sketch.h
src/SketchPlugin/SketchPlugin_SketchEntity.cpp
src/SketchPlugin/SketchPlugin_SketchEntity.h
src/SketchPlugin/plugin-Sketch.xml
src/SketcherPrs/CMakeLists.txt [new file with mode: 0644]
src/SketcherPrs/SketcherPrs.h [new file with mode: 0644]
src/SketcherPrs/SketcherPrs_Coincident.cpp [new file with mode: 0644]
src/SketcherPrs/SketcherPrs_Coincident.h [new file with mode: 0644]
src/SketcherPrs/SketcherPrs_Factory.cpp [new file with mode: 0644]
src/SketcherPrs/SketcherPrs_Factory.h [new file with mode: 0644]
src/SketcherPrs/SketcherPrs_Parallel.cpp [new file with mode: 0644]
src/SketcherPrs/SketcherPrs_Parallel.h [new file with mode: 0644]
src/SketcherPrs/SketcherPrs_Tools.cpp [new file with mode: 0644]
src/SketcherPrs/SketcherPrs_Tools.h [new file with mode: 0644]
src/SketcherPrs/icons/parallel.png [new file with mode: 0644]
src/XGUI/CMakeLists.txt
src/XGUI/XGUI_CustomPrs.cpp [new file with mode: 0644]
src/XGUI/XGUI_CustomPrs.h [new file with mode: 0644]
src/XGUI/XGUI_Displayer.cpp
src/XGUI/XGUI_Displayer.h
src/XGUI/XGUI_Workshop.cpp

index 895c8e8ed9e47cf473dae443216b49ee69493319..8406c7645f9741309ac3644da6618d2156c0fdc4 100644 (file)
@@ -54,6 +54,7 @@ ADD_SUBDIRECTORY (src/GeomDataAPI)
 ADD_SUBDIRECTORY (src/PartSetPlugin)
 ADD_SUBDIRECTORY (src/ConstructionPlugin)
 ADD_SUBDIRECTORY (src/FeaturesPlugin)
+ADD_SUBDIRECTORY (src/SketcherPrs)
 ADD_SUBDIRECTORY (src/SketchPlugin)
 ADD_SUBDIRECTORY (src/SketchSolver)
 ADD_SUBDIRECTORY (src/ModuleBase)
index 258ed85e94e9404945072a0ce17ab5d145127d76..7678b51a4d222bdc62d35860900183c6f9eb5f35 100644 (file)
@@ -55,11 +55,13 @@ void ConstructionPlugin_Axis::execute()
   }
 }
 
-void ConstructionPlugin_Axis::customisePresentation(AISObjectPtr thePrs)
+bool ConstructionPlugin_Axis::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
+                                                    std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
 {
-  std::vector<int> aRGB = Config_PropManager::color("Visualization", "construction_axis_color",
-                                                    ConstructionPlugin_Axis::DEFAULT_COLOR());
-  thePrs->setColor(aRGB[0], aRGB[1], aRGB[2]);
-  thePrs->setLineStyle(3);
-  thePrs->redisplay();
+  bool isCustomized = theDefaultPrs.get() != NULL &&
+                      theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs);
+
+  isCustomized = thePrs->setLineStyle(3);
+
+  return isCustomized;
 }
index 473d3e3524e18f86435d88e3e9df969656fb4a29..b92e0842c4ed9b595adc017156c5f10a1e458dfd 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "ConstructionPlugin.h"
 #include <ModelAPI_Feature.h>
+#include <ModelAPI_Result.h>
 #include <GeomAPI_ICustomPrs.h>
 
 /**\class ConstructionPlugin_Axis
@@ -56,12 +57,6 @@ class ConstructionPlugin_Axis : public ModelAPI_Feature, public GeomAPI_ICustomP
     static const std::string CYLINDRICAL_FACE_ATTR("cylindricalFace");
     return CYLINDRICAL_FACE_ATTR;
   }
-  /// default color for an axis
-  inline static const std::string& DEFAULT_COLOR()
-  {
-    static const std::string CONSTRUCTION_AXIS_COLOR("#000000");
-    return CONSTRUCTION_AXIS_COLOR;
-  }
 
   inline static const double MINIMAL_LENGTH() { return 1.e-5; }
 
@@ -78,7 +73,8 @@ class ConstructionPlugin_Axis : public ModelAPI_Feature, public GeomAPI_ICustomP
   ConstructionPlugin_Axis();
 
   /// Customize presentation of the feature
-  virtual void customisePresentation(AISObjectPtr thePrs);
+  virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
+                                     std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs);
 };
 
 
index d0ecc4d7ee88012e5f239c892402f118851862a1..501d9664e7762c01e75548bf4a8c275445a181b7 100644 (file)
@@ -11,6 +11,7 @@
 #include <ModelAPI_AttributeSelection.h>
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_AttributeIntArray.h>
 #include <GeomAlgoAPI_FaceBuilder.h>
 
 #include <GeomAPI_Pnt2d.h>
@@ -73,10 +74,28 @@ void ConstructionPlugin_Plane::execute()
   }
 }
 
-void ConstructionPlugin_Plane::customisePresentation(AISObjectPtr thePrs)
+bool ConstructionPlugin_Plane::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
+                                                     std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
 {
-  std::vector<int> aRGB = Config_PropManager::color("Visualization", "construction_plane_color",
-                                                    ConstructionPlugin_Plane::DEFAULT_COLOR());
-  thePrs->setColor(aRGB[0], aRGB[1], aRGB[2]);
-  thePrs->setTransparensy(0.6);
+  std::vector<int> aColor;
+  // get color from the attribute of the result
+  if (theResult.get() != NULL && theResult->data()->attribute(ModelAPI_Result::COLOR_ID()).get() != NULL) {
+    AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
+    if (aColorAttr.get() && aColorAttr->size()) {
+      aColor.push_back(aColorAttr->value(0));
+      aColor.push_back(aColorAttr->value(1));
+      aColor.push_back(aColorAttr->value(2));
+    }
+  }
+  if (aColor.empty())
+    aColor = Config_PropManager::color("Visualization", "construction_plane_color",
+                                       ConstructionPlugin_Plane::DEFAULT_COLOR());
+
+  bool isCustomized = false;
+  if (aColor.size() == 3)
+    isCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
+
+  isCustomized = thePrs->setTransparensy(0.6) || isCustomized;
+
+  return isCustomized;
 }
index f57ff1eb10099565f71d87486d4da7465c0ccb85..2ff71979a32780c69cfdeda3ebb3848488322955 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "ConstructionPlugin.h"
 #include <ModelAPI_Feature.h>
+#include <ModelAPI_Result.h>
 #include <GeomAPI_ICustomPrs.h>
 
 
@@ -91,7 +92,8 @@ class ConstructionPlugin_Plane : public ModelAPI_Feature, public GeomAPI_ICustom
   ConstructionPlugin_Plane();
 
   /// Customize presentation of the feature
-  virtual void customisePresentation(AISObjectPtr thePrs);
+  virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
+                                     std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs);
 };
 
 #endif
index 4731cc4c8c766fea1a5e00d6398838618711dd49..c60c022b4311028afd31a9c801159ed0d1158822 100644 (file)
@@ -21,10 +21,6 @@ ConstructionPlugin_Plugin::ConstructionPlugin_Plugin()
   ModelAPI_Session::get()->registerPlugin(this);
 
   // register construction properties
-  Config_PropManager::registerProp("Visualization", "construction_point_color", "Construction point color",
-                                   Config_Prop::Color, ConstructionPlugin_Point::DEFAULT_COLOR());
-  Config_PropManager::registerProp("Visualization", "construction_axis_color", "Construction axis color",
-                                   Config_Prop::Color, ConstructionPlugin_Axis::DEFAULT_COLOR());
   Config_PropManager::registerProp("Visualization", "construction_plane_color", "Construction plane color",
                                    Config_Prop::Color, ConstructionPlugin_Plane::DEFAULT_COLOR());
 }
index 231e54fb2cddaa70bbcfbeb0b7d9f0adfe269791..671a38cd7a1daf72a4d802470e5f3e60d2f02bdd 100644 (file)
@@ -45,11 +45,3 @@ void ConstructionPlugin_Point::execute()
   aConstr->setShape(GeomAlgoAPI_PointBuilder::point(aPnt));
   setResult(aConstr);
 }
-
-void ConstructionPlugin_Point::customisePresentation(AISObjectPtr thePrs)
-{
-  std::vector<int> aRGB = Config_PropManager::color("Visualization", "construction_point_color",
-                                                    ConstructionPlugin_Point::DEFAULT_COLOR());
-  thePrs->setColor(aRGB[0], aRGB[1], aRGB[2]);
-  thePrs->redisplay();
-}
index f4bf39a1186fdc61b3ee35e42f3665a8b7a609fa..84cb35cb35085d1b7461b84cf3da54ca5ea7f07f 100644 (file)
@@ -9,13 +9,13 @@
 
 #include "ConstructionPlugin.h"
 #include <ModelAPI_Feature.h>
-#include <GeomAPI_ICustomPrs.h>
+#include <ModelAPI_Result.h>
 
 /**\class ConstructionPlugin_Point
  * \ingroup Plugins
  * \brief Feature for creation of the new part in PartSet.
  */
-class ConstructionPlugin_Point : public ModelAPI_Feature, public GeomAPI_ICustomPrs
+class ConstructionPlugin_Point : public ModelAPI_Feature
 {
  public:
   /// Returns the kind of a feature
@@ -27,13 +27,6 @@ class ConstructionPlugin_Point : public ModelAPI_Feature, public GeomAPI_ICustom
     return CONSTRUCTION_POINT_KIND;
   }
 
-  /// default color for a point
-  inline static const std::string& DEFAULT_COLOR()
-  {
-    static const std::string CONSTRUCTION_POINT_COLOR("#ffff00");
-    return CONSTRUCTION_POINT_COLOR;
-  }
-
   /// attribute name for X coordinate
   inline static const std::string& X()
   {
@@ -64,10 +57,6 @@ class ConstructionPlugin_Point : public ModelAPI_Feature, public GeomAPI_ICustom
 
   /// Use plugin manager for features creation
   ConstructionPlugin_Point();
-
-  /// Modifies the given presentation in the custom way.
-  virtual void customisePresentation(AISObjectPtr thePrs);
-
 };
 
 #endif
index 11d45e7854aa0fecba09c74b3645e17e67816963..7fe93e09022b7b962ade8ce358258507c844bab7 100644 (file)
@@ -70,14 +70,6 @@ void ExchangePlugin_ImportFeature::execute()
   importFile(aFilePath);
 }
 
-void ExchangePlugin_ImportFeature::customisePresentation(AISObjectPtr thePrs)
-{
-  std::vector<int> aRGB = Config_PropManager::color("Visualization", "import_feature_color",
-                                                    IMPORTED_FEATURE_COLOR);
-  thePrs->setColor(aRGB[0], aRGB[1], aRGB[2]);
-  thePrs->redisplay();
-}
-
 bool ExchangePlugin_ImportFeature::importFile(const std::string& theFileName)
 {
   // retrieve the file and plugin library names
index 54ed715213ce7c2ea7c4800e7a95e8a3afed1904..673a6d9509955ac69ccd9298798b1ea936a7f8a7 100644 (file)
@@ -5,20 +5,17 @@
 
 #include <ExchangePlugin.h>
 #include <ModelAPI_Feature.h>
-
-#include <GeomAPI_ICustomPrs.h>
+#include <ModelAPI_Result.h>
 
 #include <map>
 
-#define IMPORTED_FEATURE_COLOR "#E0A01B"
-
   /**\class ExchangePlugin_ImportFeature
  * \ingroup Plugins
  * \brief Feature for import shapes from the external files in CAD formats.
  *
  * The set of supported formats is defined in the configuration file.
  */
-class ExchangePlugin_ImportFeature : public ModelAPI_Feature, public GeomAPI_ICustomPrs
+class ExchangePlugin_ImportFeature : public ModelAPI_Feature
 {
  public:
   /// Extrusion kind
@@ -52,9 +49,6 @@ class ExchangePlugin_ImportFeature : public ModelAPI_Feature, public GeomAPI_ICu
     return true;
   }
 
-  /// Modifies the given presentation in the custom way.
-  virtual void customisePresentation(AISObjectPtr thePrs);
-
  protected:
   /// POerforms the import of the file
   EXCHANGEPLUGIN_EXPORT bool importFile(const std::string& theFileName);
index 11034f4f6b11d0ac072b0cd98a068ab9d666c2d1..58b214b47c96522dcfcf5df123e5f27b7e1251fe 100644 (file)
@@ -30,12 +30,8 @@ ExchangePlugin_Plugin::ExchangePlugin_Plugin()
                               new ExchangePlugin_ImportFormatValidator);
 
   // register construction properties
-  Config_PropManager::registerProp("Visualization", "import_feature_color", "Imported feature color",
-                                   Config_Prop::Color, IMPORTED_FEATURE_COLOR);
-
-  // register random result color properties
-  Config_PropManager::registerProp("Visualization", "random_result_color", "Use random color for results",
-                                   Config_Prop::Bool, "false");
+  //Config_PropManager::registerProp("Visualization", "import_feature_color", "Imported feature color",
+  //                                 Config_Prop::Color, ExchangePlugin_ImportFeature::DEFAULT_COLOR());
 }
 
 FeaturePtr ExchangePlugin_Plugin::createFeature(string theFeatureID)
index ef0f5b1a97f453f5828c6242dce9486e1416f858..e1726ca506616a4d427fcf096c58dc212fc1c1db 100644 (file)
@@ -29,6 +29,7 @@ SET(PROJECT_HEADERS
     GeomAPI_DataMapOfShapeShape.h
     GeomAPI_ICustomPrs.h
     GeomAPI_Vertex.h
+       GeomAPI_Ax3.h
 )
 
 SET(PROJECT_SOURCES
@@ -53,6 +54,7 @@ SET(PROJECT_SOURCES
     GeomAPI_DataMapOfShapeShape.cpp
     GeomAPI_Vertex.cpp
     GeomAPI_ICustomPrs.cpp
+       GeomAPI_Ax3.cpp
 )
 
 SET(PROJECT_LIBRARIES
index 5e0c21b44ae344824eff4008ce15cf299a561dab..f4ae420490bada6d8d4b177459ba93c67198fb94 100644 (file)
@@ -29,6 +29,8 @@
 #include <AIS_FixRelation.hxx>
 #include <Prs3d_PointAspect.hxx>
 
+#include <Graphic3d_AspectLine3d.hxx>
+
 const double tolerance = 1e-7;
 
 const int CONSTRAINT_TEXT_HEIGHT = 28;  /// the text height of the constraint
@@ -96,9 +98,9 @@ void GeomAPI_AISObject::createDistance(std::shared_ptr<GeomAPI_Pnt> theStartPoin
 
     Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
     anAspect->MakeArrows3d(Standard_False);
-    anAspect->MakeText3d(false);
+    anAspect->MakeText3d(Standard_False);
     anAspect->TextAspect()->SetHeight(CONSTRAINT_TEXT_HEIGHT);
-    anAspect->MakeTextShaded(false);
+    anAspect->MakeTextShaded(Standard_True);
     anAspect->ArrowAspect()->SetLength(theDistance / 10.);
     aDimAIS->DimensionAspect()->MakeUnitsDisplayed(false);
     aDimAIS->SetDimensionAspect(anAspect);
@@ -253,16 +255,6 @@ void GeomAPI_AISObject::createFixed(std::shared_ptr<GeomAPI_Shape> theShape,
   }
 }
 
-void GeomAPI_AISObject::redisplay()
-{
-  Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
-  if (!anAIS.IsNull()) {
-    Handle(AIS_InteractiveContext) aContext = anAIS->GetContext();
-    aContext->Redisplay(anAIS, false);
-  }
-}
-
-
 void GeomAPI_AISObject::setColor(const int& theColor)
 {
   Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
@@ -278,21 +270,30 @@ void GeomAPI_AISObject::setColor(const int& theColor)
   aContext->SetColor(anAIS, aColor, false);
 }
 
-void GeomAPI_AISObject::setWidth(const double& theWidth)
+bool GeomAPI_AISObject::setWidth(const double& theWidth)
 {
+  bool isChanged = false;
   Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
-  if (anAIS.IsNull())
-    return;
-  anAIS->SetWidth(theWidth);
-  anAIS->Redisplay();
+  if (!anAIS.IsNull()) {
+    isChanged = anAIS->Width() != theWidth;
+    if (isChanged)
+      anAIS->SetWidth(theWidth);
+  }
+  return isChanged;
 }
 
-void GeomAPI_AISObject::setColor(int theR, int theG, int theB)
+bool GeomAPI_AISObject::setColor(int theR, int theG, int theB)
 {
   Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
   if (anAIS.IsNull())
-    return;
+    return false;
   Quantity_Color aColor(theR / 255., theG / 255., theB / 255., Quantity_TOC_RGB);
+  Quantity_Color aCurrentColor;
+  anAIS->Color(aCurrentColor);
+  // do not set the same color to the presentation
+  if (aColor.IsEqual(aCurrentColor))
+    return false;
+
   anAIS->SetColor(aColor);
   Handle(AIS_Dimension) aDimAIS = Handle(AIS_Dimension)::DownCast(anAIS);
   if (!aDimAIS.IsNull()) {
@@ -300,6 +301,19 @@ void GeomAPI_AISObject::setColor(int theR, int theG, int theB)
   }
   Handle(AIS_InteractiveContext) aContext = anAIS->GetContext();
   aContext->SetColor(anAIS, aColor, false);
+  return true;
+}
+
+void GeomAPI_AISObject::getColor(int& theR, int& theG, int& theB)
+{
+  Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
+  if (anAIS.IsNull())
+    return;
+
+  Quantity_Color aColor = anAIS->Color();
+  theR = aColor.Red()*255.;
+  theG = aColor.Green()*255.;
+  theB = aColor.Blue()*255.;
 }
 
 bool GeomAPI_AISObject::empty() const
@@ -340,26 +354,46 @@ void GeomAPI_AISObject::setPointMarker(int theType, double theScale)
   }
 }
 
-
-void GeomAPI_AISObject::setLineStyle(int theStyle)
+bool GeomAPI_AISObject::setLineStyle(int theStyle)
 {
+  bool isChanged = false;
   Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
   if (!anAIS.IsNull()) {
     Handle(AIS_Drawer) aDrawer = anAIS->Attributes();
-    if (aDrawer->HasLineAspect())
-      aDrawer->LineAspect()->SetTypeOfLine((Aspect_TypeOfLine)theStyle);
-    if (aDrawer->HasWireAspect())
-      aDrawer->WireAspect()->SetTypeOfLine((Aspect_TypeOfLine)theStyle);
+    Handle(Prs3d_LineAspect) aLineAspect;
+
+    Aspect_TypeOfLine aType = (Aspect_TypeOfLine)theStyle;
+    if (aDrawer->HasLineAspect()) {
+      aLineAspect = aDrawer->LineAspect();
+    }
+    if (aDrawer->HasWireAspect()) {
+      aLineAspect = aDrawer->WireAspect();
+    }
+    Quantity_Color aCurrentColor;
+    Aspect_TypeOfLine aCurrentType;
+    Standard_Real aCurrentWidth;
+    aLineAspect->Aspect()->Values(aCurrentColor, aCurrentType, aCurrentWidth);
+    isChanged = aType != aCurrentType;
+    if (isChanged) {
+      aLineAspect->SetTypeOfLine(aType);
+    }
   }
+  return isChanged;
 }
 
 
-void GeomAPI_AISObject::setTransparensy(double theVal)
+bool GeomAPI_AISObject::setTransparensy(double theVal)
 {
+  bool isChanged = false;
   Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
   if (!anAIS.IsNull()) {
     Handle(AIS_InteractiveContext) aContext = anAIS->GetContext();
-    if (!aContext.IsNull())
-      aContext->SetTransparency(anAIS, theVal, false);
+    if (!aContext.IsNull()) {
+      double aCurrentValue = anAIS->Transparency();
+      isChanged = aCurrentValue != theVal;
+      if (isChanged)
+        aContext->SetTransparency(anAIS, theVal, false);
+    }
   }
+ return isChanged;
 }
index c916320c093b70c4bfd9306df2fbee7c064ea3aa..ad879d1dbc790d70d9735194bcb57bf6449f01ef 100644 (file)
@@ -78,24 +78,28 @@ class GEOMAPI_EXPORT GeomAPI_AISObject : public GeomAPI_Interface
   void createFixed(std::shared_ptr<GeomAPI_Shape> theShape,
                    std::shared_ptr<GeomAPI_Pln> thePlane);
 
-  /** \brief Redisplays the current AIS object in the context
-   */
-  void redisplay();
-
   /** \brief Assigns the color for the shape
    *  \param[in] theColor index of the color
    */
   void setColor(const int& theColor);
 
   /** \brief Assigns the color for the shape
+   *  \param[in] theR value of the red component
+   *  \param[in] theG value of the green component
+   *  \param[in] theB value of the blue component
+   *  \returns true if the presentation color is changed
+   */
+  bool setColor(int theR, int theG, int theB);
+
+  /** \brief Returns the color for the shape
    *  \param[in] theR value of the red component
    *  \param[in] theG value of the green component
    *  \param[in] theB value of the blue component
    */
-  void setColor(int theR, int theG, int theB);
+  void getColor(int& theR, int& theG, int& theB);
 
   /// \brief Assigns the width of the lines of shape
-  void setWidth(const double& theWidth);
+  bool setWidth(const double& theWidth);
 
   /// \brief Checks if the object is empty
   bool empty() const;
@@ -110,10 +114,12 @@ class GEOMAPI_EXPORT GeomAPI_AISObject : public GeomAPI_Interface
 
   /// Set line type of edges
   /// Has to be defined according to Aspect_TypeOfLine
-  void setLineStyle(int theStyle);
+  /// \returns true if the object value differs from the current
+  bool setLineStyle(int theStyle);
 
   /// Set transparency of the presentation (theVal = 0 ... 1)
-  void setTransparensy(double theVal);
+  /// \returns true if the object value differs from the current
+  bool setTransparensy(double theVal);
 };
 
 //! Pointer on attribute object
diff --git a/src/GeomAPI/GeomAPI_Ax3.cpp b/src/GeomAPI/GeomAPI_Ax3.cpp
new file mode 100644 (file)
index 0000000..d7950b5
--- /dev/null
@@ -0,0 +1,107 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        GeomAPI_Ax3.cpp
+// Created:     16 February 2015
+// Author:      Vitaly SMETANNIKOV
+
+
+#include "GeomAPI_Ax3.h"
+#include "GeomAPI_XYZ.h"
+#include "GeomAPI_Pnt2d.h"
+
+#include <gp_Dir.hxx>
+#include <gp_Pnt.hxx>
+#include <gp_Ax3.hxx>
+#include <Precision.hxx>
+
+
+#define MY_AX3 static_cast<gp_Ax3*>(myImpl)
+
+
+GeomAPI_Ax3::GeomAPI_Ax3()
+: GeomAPI_Interface(new gp_Ax3())
+{
+}
+
+GeomAPI_Ax3::GeomAPI_Ax3(std::shared_ptr<GeomAPI_Pnt> theOrigin,
+                         std::shared_ptr<GeomAPI_Dir> theDirX,
+                         std::shared_ptr<GeomAPI_Dir> theDirY,
+                         std::shared_ptr<GeomAPI_Dir> theNorm)
+: GeomAPI_Interface(new gp_Ax3(theOrigin->impl<gp_Pnt>(), 
+                               theNorm->impl<gp_Dir>(), 
+                               theDirX->impl<gp_Dir>()))
+ {
+   MY_AX3->SetYDirection(theDirY->impl<gp_Dir>());
+ }
+
+void GeomAPI_Ax3::setOrigin(const std::shared_ptr<GeomAPI_Pnt>& theOrigin)
+{
+  gp_Ax1 aAx1 = MY_AX3->Axis();
+  aAx1.SetLocation(theOrigin->impl<gp_Pnt>());
+  MY_AX3->SetAxis(aAx1);
+}
+
+std::shared_ptr<GeomAPI_Pnt> GeomAPI_Ax3::origin() const
+{
+  gp_Pnt aPnt = MY_AX3->Axis().Location();
+  return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aPnt.X(),aPnt.Y(),aPnt.Z()));
+}
+
+void GeomAPI_Ax3::setDirX(const std::shared_ptr<GeomAPI_Dir>& theDirX)
+{
+  MY_AX3->SetXDirection(theDirX->impl<gp_Dir>());
+}
+
+std::shared_ptr<GeomAPI_Dir> GeomAPI_Ax3::dirX() const
+{
+  gp_Dir aDir = MY_AX3->XDirection();
+  return std::shared_ptr<GeomAPI_Dir>(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z()));
+}
+
+void GeomAPI_Ax3::setDirY(const std::shared_ptr<GeomAPI_Dir>& theDirY)
+{
+  MY_AX3->SetYDirection(theDirY->impl<gp_Dir>());
+}
+
+std::shared_ptr<GeomAPI_Dir> GeomAPI_Ax3::dirY() const
+{
+  gp_Dir aDir = MY_AX3->YDirection();
+  return std::shared_ptr<GeomAPI_Dir>(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z()));
+}
+
+void GeomAPI_Ax3::setNorm(const std::shared_ptr<GeomAPI_Dir>& theNorm)
+{
+  gp_Ax1 aAx1 = MY_AX3->Axis();
+  aAx1.SetDirection(theNorm->impl<gp_Dir>());
+  MY_AX3->SetAxis(aAx1);
+}
+
+std::shared_ptr<GeomAPI_Dir> GeomAPI_Ax3::norm() const
+{
+  gp_Dir aDir = MY_AX3->Axis().Direction();
+  return std::shared_ptr<GeomAPI_Dir>(new GeomAPI_Dir(aDir.X(),aDir.Y(),aDir.Z()));
+}
+
+
+std::shared_ptr<GeomAPI_Pnt> GeomAPI_Ax3::to3D(double theX, double theY) const
+{
+  gp_Pnt aPnt = MY_AX3->Axis().Location();
+  gp_Dir aXDir = MY_AX3->XDirection();
+  gp_Dir aYDir = MY_AX3->YDirection();
+  gp_XYZ aSum = aPnt.XYZ().Added(aXDir.XYZ().Multiplied(theX)).Added(aYDir.XYZ().Multiplied(theY));
+
+  return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aSum.X(), aSum.Y(), aSum.Z()));
+}
+
+std::shared_ptr<GeomAPI_Pnt2d> GeomAPI_Ax3::to2D(double theX, double theY, double theZ) const
+{
+  gp_Pnt anOriginPnt = MY_AX3->Axis().Location();
+  gp_Vec aVec(anOriginPnt, gp_Pnt(0, 0, 0));
+
+  gp_Dir aXDir = MY_AX3->XDirection();
+  gp_Dir aYDir = MY_AX3->YDirection();
+
+  double aX = aVec.X() * aXDir.X() + aVec.Y() * aXDir.Y() + aVec.Z() * aXDir.Z();
+  double aY = aVec.X() * aYDir.X() + aVec.Y() * aYDir.Y() + aVec.Z() * aYDir.Y();
+  return std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aX, aY));
+}
\ No newline at end of file
diff --git a/src/GeomAPI/GeomAPI_Ax3.h b/src/GeomAPI/GeomAPI_Ax3.h
new file mode 100644 (file)
index 0000000..67bde43
--- /dev/null
@@ -0,0 +1,73 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        GeomAPI_Ax3.hxx
+// Created:     16 February 2015
+// Author:      Vitaly SMETANNIKOV
+
+#ifndef GEOMAPI_AX3_H_
+#define GEOMAPI_AX3_H_
+
+#include "GeomAPI.h"
+#include "GeomAPI_Pnt.h"
+#include "GeomAPI_Dir.h"
+
+/**
+ * \ingroup DataModel
+ * \brief The class represents a coordinate plane which is 2d plane with X and Y directions
+ * and origin
+ */ 
+class GEOMAPI_EXPORT GeomAPI_Ax3 : public GeomAPI_Interface
+{
+public:
+  /// Default constructor
+  GeomAPI_Ax3();
+
+  /// Ñonstructor
+  /// \param theOrigin point of origin
+  /// \param theDirX direction of X axis
+  /// \param theDirY direction of Y axis
+  /// \param theNorm direction of normal vector
+  GeomAPI_Ax3(std::shared_ptr<GeomAPI_Pnt> theOrigin,
+              std::shared_ptr<GeomAPI_Dir> theDirX,
+              std::shared_ptr<GeomAPI_Dir> theDirY,
+              std::shared_ptr<GeomAPI_Dir> theNorm);
+
+  /// Sets origin point
+  void setOrigin(const std::shared_ptr<GeomAPI_Pnt>& theOrigin);
+
+  /// Returns the plane origin point
+  std::shared_ptr<GeomAPI_Pnt> origin() const;
+
+  /// Sets X direction vector
+  void setDirX(const std::shared_ptr<GeomAPI_Dir>& theDirX);
+
+  /// Returns X direction vector
+  std::shared_ptr<GeomAPI_Dir> dirX() const;
+
+  /// Sets Y direction vector
+  void setDirY(const std::shared_ptr<GeomAPI_Dir>& theDirY);
+
+  /// Returns Y direction vector
+  std::shared_ptr<GeomAPI_Dir> dirY() const;
+
+  /// Sets Z direction vector
+  void setNorm(const std::shared_ptr<GeomAPI_Dir>& theNorm);
+
+  /// Returns Z direction vector
+  std::shared_ptr<GeomAPI_Dir> norm() const;
+
+  /// Converts 2d coordinates from the plane to 3d space point
+  /// \param theX X coordinate
+  /// \param theY Y coordinate
+  std::shared_ptr<GeomAPI_Pnt> to3D(double theX, double theY) const;
+
+  /// Converts 3d  to 2d coordinates of the plane
+  /// \param theX X coordinate
+  /// \param theY Y coordinate
+  /// \param theZ Z coordinate
+  std::shared_ptr<GeomAPI_Pnt2d> to2D(double theX, double theY, double theZ) const;
+
+};
+
+
+#endif
\ No newline at end of file
index 72c362d657e7e46787e30f3852cc878781de4e70..de9c6d299f5dbb359aee66febcb07473c2003c73 100644 (file)
@@ -9,18 +9,23 @@
 
 #include "GeomAPI.h"
 #include "GeomAPI_AISObject.h"
+#include "GeomAPI_AISObject.h"
 
+#include <vector>
 /**
 * Interface of a class which can provide specific customization of
 * object presentation
 */ 
+class ModelAPI_Result;
+
 class GeomAPI_ICustomPrs
 {
 public:
   GEOMAPI_EXPORT virtual ~GeomAPI_ICustomPrs();
 
   /// Modifies the given presentation in the custom way.
-  virtual void customisePresentation(AISObjectPtr thePrs) = 0;
+  virtual bool customisePresentation(std::shared_ptr<ModelAPI_Result> theResult, AISObjectPtr thePrs,
+                                     std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs) = 0;
 };
 
 typedef std::shared_ptr<GeomAPI_ICustomPrs> GeomCustomPrsPtr;
index 53470fb5e55d09aa3c21ee1fc2baa012a0f3b625..f7757cf7e94b7b32a3ad5f0a23067ece92cd4381 100644 (file)
@@ -52,7 +52,7 @@ std::list<std::shared_ptr<GeomAPI_Shape> > GeomAPI_PlanarEdges::getEdges()
 }
 
 bool GeomAPI_PlanarEdges::hasPlane() const {
-  return myOrigin && myNorm && myDirX && myDirY;
+  return myPlane.get() != NULL;
 }
 
 bool GeomAPI_PlanarEdges::isVertex() const {
@@ -63,28 +63,38 @@ bool GeomAPI_PlanarEdges::isEdge() const {
   return false;
 }
 
-void GeomAPI_PlanarEdges::setOrigin(const std::shared_ptr<GeomAPI_Pnt>& theOrigin)
+std::shared_ptr<GeomAPI_Pnt> GeomAPI_PlanarEdges::origin() const 
 {
-  myOrigin = theOrigin;
+  if (hasPlane())
+    return myPlane->origin();
+  return std::shared_ptr<GeomAPI_Pnt>();
 }
-std::shared_ptr<GeomAPI_Pnt> GeomAPI_PlanarEdges::origin() const {
-  return myOrigin;
-}
-void GeomAPI_PlanarEdges::setDirX(const std::shared_ptr<GeomAPI_Dir>& theDirX) {
-  myDirX = theDirX;
-}
-std::shared_ptr<GeomAPI_Dir> GeomAPI_PlanarEdges::dirX() const {
-  return myDirX;
-}
-void GeomAPI_PlanarEdges::setDirY(const std::shared_ptr<GeomAPI_Dir>& theDirY) {
-  myDirY = theDirY;
-}
-std::shared_ptr<GeomAPI_Dir> GeomAPI_PlanarEdges::dirY() const {
-  return myDirY;
+
+std::shared_ptr<GeomAPI_Dir> GeomAPI_PlanarEdges::dirX() const 
+{
+  if (hasPlane())
+    return myPlane->dirX();
+  return std::shared_ptr<GeomAPI_Dir>();
 }
-void GeomAPI_PlanarEdges::setNorm(const std::shared_ptr<GeomAPI_Dir>& theNorm) {
-  myNorm = theNorm;
+
+std::shared_ptr<GeomAPI_Dir> GeomAPI_PlanarEdges::dirY() const 
+{
+  if (hasPlane())
+    return myPlane->dirY();
+  return std::shared_ptr<GeomAPI_Dir>();
 }
-std::shared_ptr<GeomAPI_Dir> GeomAPI_PlanarEdges::norm() const {
-  return myNorm;
+
+std::shared_ptr<GeomAPI_Dir> GeomAPI_PlanarEdges::norm() const 
+{
+  if (hasPlane())
+    return myPlane->norm();
+  return std::shared_ptr<GeomAPI_Dir>();
 }
+
+void GeomAPI_PlanarEdges::setPlane(const std::shared_ptr<GeomAPI_Pnt>& theOrigin,
+                                   const std::shared_ptr<GeomAPI_Dir>& theDirX,
+                                   const std::shared_ptr<GeomAPI_Dir>& theDirY,
+                                   const std::shared_ptr<GeomAPI_Dir>& theNorm)
+{
+  myPlane = std::shared_ptr<GeomAPI_Ax3>(new GeomAPI_Ax3(theOrigin, theDirX, theDirY, theNorm));
+}
\ No newline at end of file
index 627bc5d719cfded780ee8c181ba13a29d18103c2..1eddd16c899ca9bb59c39d39eb34a33eafe47820 100644 (file)
@@ -11,6 +11,7 @@
 #include "GeomAPI_Edge.h"
 #include "GeomAPI_Pnt.h"
 #include "GeomAPI_Dir.h"
+#include "GeomAPI_Ax3.h"
 
 #include <memory>
 
@@ -41,36 +42,31 @@ class GeomAPI_PlanarEdges : public GeomAPI_Shape
   /// Returns True if the wire is defined in a plane
   GEOMAPI_EXPORT bool hasPlane() const;
 
-  /// Sets origin point
-  GEOMAPI_EXPORT void setOrigin(const std::shared_ptr<GeomAPI_Pnt>& theOrigin);
-
   /// Returns the plane origin point
   GEOMAPI_EXPORT std::shared_ptr<GeomAPI_Pnt> origin() const;
 
-  /// Sets X direction vector
-  GEOMAPI_EXPORT void setDirX(const std::shared_ptr<GeomAPI_Dir>& theDirX);
   /// Returns X direction vector
   GEOMAPI_EXPORT std::shared_ptr<GeomAPI_Dir> dirX() const;
 
-  /// Sets Y direction vector
-  GEOMAPI_EXPORT void setDirY(const std::shared_ptr<GeomAPI_Dir>& theDirY);
   /// Returns Y direction vector
   GEOMAPI_EXPORT std::shared_ptr<GeomAPI_Dir> dirY() const;
 
-  /// Sets Z direction vector
-  GEOMAPI_EXPORT void setNorm(const std::shared_ptr<GeomAPI_Dir>& theNorm);
   /// Returns Z direction vector
   GEOMAPI_EXPORT std::shared_ptr<GeomAPI_Dir> norm() const;
 
+  /// Set working plane
+  /// \param theOrigin origin of the plane axis
+  /// \param theDirX X direction of the plane axis
+  /// \param theDirY Y direction of the plane axis
+  /// \param theNorm normal direction of the plane axis
+  GEOMAPI_EXPORT void setPlane(const std::shared_ptr<GeomAPI_Pnt>& theOrigin,
+                               const std::shared_ptr<GeomAPI_Dir>& theDirX,
+                               const std::shared_ptr<GeomAPI_Dir>& theDirY,
+                               const std::shared_ptr<GeomAPI_Dir>& theNorm);
+
 private:
-  /// Origin point of the plane
-  std::shared_ptr<GeomAPI_Pnt> myOrigin;
-  /// The X direction inside of the plane
-  std::shared_ptr<GeomAPI_Dir> myDirX;
-  /// The Y direction inside of the plane
-  std::shared_ptr<GeomAPI_Dir> myDirY;
-  /// The normal direction to the plane
-  std::shared_ptr<GeomAPI_Dir> myNorm;
+
+  std::shared_ptr<GeomAPI_Ax3> myPlane;
 };
 
 #endif
index 86c7b0a228059201fde6a5a2530aa90933fd8aab..61e28412aab9d44a70420e17db223e8cee585566 100644 (file)
@@ -23,6 +23,9 @@ const TopoDS_Shape GeomAlgoAPI_DFLoader::refineResult(const  TopoDS_Shape& theRe
     if (nbSubResults == 1) {
       itr.Initialize(theResult);
       if (itr.More()) aResult = itr.Value();
+    } else {
+      /// MPV: store compound anyway: it may be Boolean operation that produces two solids from one
+      aResult = theResult;
     }
   }
   return aResult;
index 20c1c0b29733f0b0bddafad48ffc1ed7d61f2f86..ef4c82c12077d0ba4b2d4067fcf226634c746b2b 100644 (file)
@@ -14,7 +14,7 @@ SET(PROJECT_HEADERS
     Model_AttributeRefAttr.h
     Model_AttributeRefList.h
     Model_AttributeBoolean.h
-    Model_AttributeColor.h
+    Model_AttributeIntArray.h
     Model_AttributeString.h
     Model_AttributeInteger.h
     Model_AttributeSelection.h
@@ -40,7 +40,7 @@ SET(PROJECT_SOURCES
     Model_AttributeRefAttr.cpp
     Model_AttributeRefList.cpp
     Model_AttributeBoolean.cpp
-    Model_AttributeColor.cpp
+    Model_AttributeIntArray.cpp
     Model_AttributeString.cpp
     Model_AttributeInteger.cpp
     Model_AttributeSelection.cpp
diff --git a/src/Model/Model_AttributeColor.cpp b/src/Model/Model_AttributeColor.cpp
deleted file mode 100644 (file)
index 920e35a..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:        Model_AttributeColor.cpp
-// Created:     6 Mar 2015
-// Author:      Natalia ERMOLAEVA
-
-#include <Model_AttributeColor.h>
-#include <ModelAPI_AttributeString.h>
-#include <ModelAPI_Attribute.h>
-#include <ModelAPI_Data.h>
-#include <ModelAPI_Object.h>
-
-#include <Standard_TypeDef.hxx>
-#include <TCollection_AsciiString.hxx>
-#include <TCollection_ExtendedString.hxx>
-#include <TDataStd_Integer.hxx>
-#include <TDataStd_Name.hxx>
-
-#include <string>
-
-void Model_AttributeColor::setValues(const int theRed,
-                                     const int theGreen,
-                                     const int theBlue)
-{
-  if (!myIsInitialized || myRed->Get() != theRed ||
-      myGreen->Get() != theGreen || myBlue->Get() != theBlue) {
-    myRed->Set(theRed);
-    myGreen->Set(theGreen);
-    myBlue->Set(theBlue);
-
-    owner()->data()->sendAttributeUpdated(this);
-  }
-}
-
-void Model_AttributeColor::setValuesRandom()
-{
-  setValues(300, 150, 40);
-}
-
-void Model_AttributeColor::values(int& theRed, int& theGreen, int& theBlue)
-{
-  theRed = myRed->Get();
-  theGreen = myGreen->Get();
-  theBlue = myBlue->Get();
-}
-
-Model_AttributeColor::Model_AttributeColor(TDF_Label& theLabel)
-{
-  // check the attribute could be already presented in this doc (after load document)
-  myIsInitialized = theLabel.FindAttribute(TDataStd_Integer::GetID(), myRed) == Standard_True;
-  if (!myIsInitialized) {
-    // create attribute: not initialized by value yet, just zero
-    myRed = TDataStd_Integer::Set(theLabel, 0);
-    myGreen = TDataStd_Integer::Set(theLabel, 0);
-    myBlue = TDataStd_Integer::Set(theLabel, 0);
-  }
-}
diff --git a/src/Model/Model_AttributeColor.h b/src/Model/Model_AttributeColor.h
deleted file mode 100644 (file)
index 7c5922d..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:        Model_AttributeColor.h
-// Created:     6 Mar 2015
-// Author:      Natalia ERMOLAEVA
-
-#ifndef MODEL_ATTRIBUTECOLOR_H_
-#define MODEL_ATTRIBUTECOLOR_H_
-
-#include <Model.h>
-#include <ModelAPI_AttributeColor.h>
-
-#include <TDF_Label.hxx>
-#include <TDataStd_Integer.hxx>
-
-#include <string>
-
-/**\class Model_AttributeColor
- * \ingroup DataModel
- * \brief Attribute that contains three integer values which define the color.
- */
-
-class Model_AttributeColor : public ModelAPI_AttributeColor
-{
-  Handle_TDataStd_Integer myRed;
-  Handle_TDataStd_Integer myGreen;
-  Handle_TDataStd_Integer myBlue;
- public:
-  /// Defines the color value
-  /// \param theRed the red part of the color
-  /// \param theRed the green part of the color
-  /// \param theRed the blue part of the color
-  MODELAPI_EXPORT virtual void setValues(const int theRed,
-                                         const int theGreen,
-                                         const int theBlue);
-
-  /// Fills the attribute values by a random color
-  MODELAPI_EXPORT virtual void setValuesRandom();
-
-  /// Returns the color value
-  MODELAPI_EXPORT virtual void values(int& theRed, int& theGreen, int& theBlue);
-
- protected:
-  /// Initializes attibutes
-  Model_AttributeColor(TDF_Label& theLabel);
-
-  friend class Model_Data;
-};
-
-#endif
diff --git a/src/Model/Model_AttributeIntArray.cpp b/src/Model/Model_AttributeIntArray.cpp
new file mode 100644 (file)
index 0000000..8f21a42
--- /dev/null
@@ -0,0 +1,70 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        Model_AttributeIntArray.cpp
+// Created:     6 Mar 2015
+// Author:      Natalia ERMOLAEVA
+
+#include <Model_AttributeIntArray.h>
+#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_Attribute.h>
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Object.h>
+
+#include <Standard_TypeDef.hxx>
+#include <TCollection_AsciiString.hxx>
+#include <TCollection_ExtendedString.hxx>
+#include <TDataStd_Integer.hxx>
+#include <TDataStd_Name.hxx>
+
+#include <string>
+
+int Model_AttributeIntArray::size()
+{
+  return myArray.IsNull() ? 0 : myArray->Length();
+}
+
+void Model_AttributeIntArray::setSize(const int theSize)
+{
+  if (myArray.IsNull()) { // create array if it is not done yet
+    if (theSize != 0) { // if size is zero, nothing to do (null array means there is no array)
+      myArray = TDataStd_IntegerArray::Set(myLab, 0, theSize);
+      owner()->data()->sendAttributeUpdated(this);
+    }
+  } else { // reset the old array
+    if (theSize) {
+      if (theSize != myArray->Length()) { // old data is not keept, a new array is created
+        Handle(TColStd_HArray1OfInteger) aNewArray = new TColStd_HArray1OfInteger(0, theSize - 1);
+        myArray->ChangeArray(aNewArray);
+        owner()->data()->sendAttributeUpdated(this);
+      }
+    } else { // size is zero => array must be erased
+      if (!myArray.IsNull()) {
+        myArray.Nullify();
+        myLab.ForgetAttribute(TDataStd_IntegerArray::GetID());
+        owner()->data()->sendAttributeUpdated(this);
+      }
+    }
+  }
+}
+
+void Model_AttributeIntArray::setValue(const int theIndex,
+                                       const int theValue)
+{
+  if (myArray->Value(theIndex) != theValue) {
+    myArray->SetValue(theIndex, theValue);
+    owner()->data()->sendAttributeUpdated(this);
+  }
+}
+
+int Model_AttributeIntArray::value(const int theIndex)
+{
+  return myArray->Value(theIndex);
+}
+
+Model_AttributeIntArray::Model_AttributeIntArray(TDF_Label& theLabel)
+{
+  myLab = theLabel;
+  // check the attribute could be already presented in this doc (after load document)
+  myIsInitialized = 
+    myLab.FindAttribute(TDataStd_IntegerArray::GetID(), myArray) == Standard_True;
+}
diff --git a/src/Model/Model_AttributeIntArray.h b/src/Model/Model_AttributeIntArray.h
new file mode 100644 (file)
index 0000000..82808f5
--- /dev/null
@@ -0,0 +1,54 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        Model_AttributeIntArray.h
+// Created:     6 Mar 2015
+// Author:      Natalia ERMOLAEVA
+
+#ifndef MODEL_ATTRIBUTEINTARRAY_H_
+#define MODEL_ATTRIBUTEINTARRAY_H_
+
+#include <Model.h>
+#include <ModelAPI_AttributeIntArray.h>
+
+#include <TDF_Label.hxx>
+#include <TDataStd_IntegerArray.hxx>
+
+#include <string>
+
+/**\class Model_AttributeIntArray
+ * \ingroup DataModel
+ * \brief API for the attribute that contains several integers in the array inside.
+ * Used for RGB color storage for an example. By default size is one, zero-based.
+ * Represented as array in OCCT. Empty array means that this attribute does not exists.
+ */
+
+class Model_AttributeIntArray : public ModelAPI_AttributeIntArray
+{
+  /// The OCCT array that keeps all values. 
+  Handle_TDataStd_IntegerArray myArray;
+  /// Stores the label as a field to set array if size is not null (null array is buggy in OCAF)
+  TDF_Label myLab;
+ public:
+
+  /// Returns the size of the array (zero means that it is empty)
+  MODEL_EXPORT virtual int size();
+
+  /// Sets the new size of the array. The previous data is erased.
+  MODEL_EXPORT virtual void setSize(const int theSize);
+
+  /// Defines the value of the array by index [0; size-1]
+  MODEL_EXPORT virtual void setValue(const int theIndex,
+                                     const int theValue);
+
+  /// Returns the value by the index
+  MODEL_EXPORT virtual int value(const int theIndex);
+
+
+ protected:
+  /// Initializes attibutes
+  Model_AttributeIntArray(TDF_Label& theLabel);
+
+  friend class Model_Data;
+};
+
+#endif
index 4d0ed5d23bceac061d541d288830bf553acce213..b8aeabaffbba9e19dd2c04e33422da9bb9c59cea 100644 (file)
@@ -15,7 +15,7 @@
 #include <Model_AttributeString.h>
 #include <Model_AttributeSelection.h>
 #include <Model_AttributeSelectionList.h>
-#include <Model_AttributeColor.h>
+#include <Model_AttributeIntArray.h>
 #include <Model_Events.h>
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Result.h>
@@ -91,8 +91,8 @@ void Model_Data::addAttribute(const std::string& theID, const std::string theAtt
     anAttr = new Model_AttributeRefAttr(anAttrLab);
   } else if (theAttrType == ModelAPI_AttributeRefList::type()) {
     anAttr = new Model_AttributeRefList(anAttrLab);
-  } else if (theAttrType == ModelAPI_AttributeColor::type()) {
-    anAttr = new Model_AttributeColor(anAttrLab);
+  } else if (theAttrType == ModelAPI_AttributeIntArray::type()) {
+    anAttr = new Model_AttributeIntArray(anAttrLab);
   } 
   // create also GeomData attributes here because only here the OCAF strucure is known
   else if (theAttrType == GeomData_Point::type()) {
@@ -133,6 +133,7 @@ GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeSelection, selection);
 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeSelectionList, selectionList);
 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeRefAttr, refattr);
 GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeRefList, reflist);
+GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeIntArray, intArray);
 
 std::shared_ptr<ModelAPI_Attribute> Model_Data::attribute(const std::string& theID)
 {
index 6604e86e8a246dfce43bccf065e6944fb5637dfc..1787b2a9e0c2aa9fe9f5a3da79a1f9c7c7c690de 100644 (file)
@@ -17,6 +17,7 @@
 #include <ModelAPI_AttributeReference.h>
 #include <ModelAPI_AttributeRefList.h>
 #include <ModelAPI_AttributeString.h>
+#include <ModelAPI_AttributeIntArray.h>
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Object.h>
@@ -100,6 +101,10 @@ class Model_Data : public ModelAPI_Data
   /// Returns the attribute that contains real value with double precision
   MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeString>
     string(const std::string& theID);
+  /// Returns the attribute that contains integer values array
+  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeIntArray>
+    intArray(const std::string& theID);
+
   /// Returns the generic attribute by identifier
   /// \param theID identifier of the attribute
   MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Attribute> attribute(const std::string& theID);
index edee5b1495958450a9af23e078d881b36aafb4c3..2bdea7f5f30bdf54fbd2db814dccdc2b16615f1e 100644 (file)
@@ -7,7 +7,7 @@
 #include <Model_ResultBody.h>
 #include <Model_Data.h>
 #include <Model_Document.h>
-#include <ModelAPI_AttributeColor.h>
+#include <ModelAPI_AttributeIntArray.h>
 #include <TNaming_Builder.hxx>
 #include <TNaming_NamedShape.hxx>
 #include <TDataStd_Name.hxx>
@@ -37,8 +37,6 @@
 //#include <TDF_Tool.hxx>
 //#define DEB_IMPORT 1
 
-#define RESULT_BODY_COLOR "#ff0000"
-
 Model_ResultBody::Model_ResultBody()
 {
   setIsConcealed(false);
@@ -46,21 +44,17 @@ Model_ResultBody::Model_ResultBody()
 
 void Model_ResultBody::initAttributes()
 {
-  // append the color attribute
+  // append the color attribute. It is empty, the attribute will be filled by a request
   DataPtr aData = data();
-  aData->addAttribute(COLOR_ID(), ModelAPI_AttributeColor::type());
-  // set the default value
-  bool anIsRandomColor = Config_PropManager::boolean("Visualization", "random_result_color",
-                                                     "false");
-  AttributeColorPtr aColorAttr = std::dynamic_pointer_cast<ModelAPI_AttributeColor>
-                                                             (aData->attribute(COLOR_ID()));
-  if (anIsRandomColor)
-    aColorAttr->setValuesRandom();
-  else {
-    std::vector<int> aRGB;
-    aRGB = Config_PropManager::color("Visualization", "result_body_color", RESULT_BODY_COLOR);
-    aColorAttr->setValues(aRGB[0], aRGB[1], aRGB[2]);
-  }
+  aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::type());
+}
+
+void Model_ResultBody::colorConfigInfo(std::string& theSection, std::string& theName,
+                                       std::string& theDefault)
+{
+  theSection = "Visualization";
+  theName = "result_body_color";
+  theDefault = DEFAULT_COLOR();
 }
 
 void Model_ResultBody::store(const std::shared_ptr<GeomAPI_Shape>& theShape)
index 5b849c620b50b64b8fa1b3bad68c0eb68052d0a6..a5ffd83027b04bba1e2ca48a2fac7b6f6df0b951 100644 (file)
@@ -29,9 +29,20 @@ class Model_ResultBody : public ModelAPI_ResultBody
   /// label; index in vector corresponds to the label tag
   std::vector<TNaming_Builder*> myBuilders;
 public:
+  /// default color for a result body
+  inline static const std::string& DEFAULT_COLOR()
+  {
+    static const std::string RESULT_BODY_COLOR("#E0A01B");
+    return RESULT_BODY_COLOR;
+  }
+
   /// Request for initialization of data model of the result: adding all attributes
   virtual void initAttributes();
 
+  // Retuns the parameters of color definition in the resources config manager
+  MODEL_EXPORT virtual void colorConfigInfo(std::string& theSection, std::string& theName,
+                                            std::string& theDefault);
+
   /// Stores the shape (called by the execution method).
   MODEL_EXPORT virtual void store(const std::shared_ptr<GeomAPI_Shape>& theShape);
 
index aaade70ff23d3364b2fb930b5c1bc61081d5eac2..a0f3b9306ed2281a13ef5fe3c7c96d4596f6b44f 100644 (file)
@@ -6,6 +6,24 @@
 
 #include <Model_ResultConstruction.h>
 
+#include <ModelAPI_AttributeIntArray.h>
+#include <Config_PropManager.h>
+
+void Model_ResultConstruction::initAttributes()
+{
+  // append the color attribute. It is empty, the attribute will be filled by a request
+  DataPtr aData = data();
+  aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::type());
+}
+
+void Model_ResultConstruction::colorConfigInfo(std::string& theSection, std::string& theName,
+                                       std::string& theDefault)
+{
+  theSection = "Visualization";
+  theName = "result_construction_color";
+  theDefault = DEFAULT_COLOR();
+}
+
 void Model_ResultConstruction::setShape(std::shared_ptr<GeomAPI_Shape> theShape)
 {
   myShape = theShape;
index a66aeeb5a73eccebf1883dca7f04715774d5174b..8292e09bc12b12f9d8492199dac11d759b57e142 100644 (file)
@@ -23,6 +23,20 @@ class Model_ResultConstruction : public ModelAPI_ResultConstruction
   std::shared_ptr<GeomAPI_Shape> myShape;  ///< shape of this result created "on the fly"
   bool myIsInHistory;
  public:
+  /// default color for a result construction
+  inline static const std::string& DEFAULT_COLOR()
+  {
+    static const std::string RESULT_CONSTRUCTION_COLOR("#000000");
+    return RESULT_CONSTRUCTION_COLOR;
+  }
+
+  /// Request for initialization of data model of the result: adding all attributes
+  virtual void initAttributes();
+
+  // Retuns the parameters of color definition in the resources config manager
+  MODEL_EXPORT virtual void colorConfigInfo(std::string& theSection, std::string& theName,
+                                            std::string& theDefault);
+
   /// By default object is displayed in the object browser.
   MODEL_EXPORT virtual bool isInHistory()
   {
index ebcdb9b437ff4915e0bfe66b11856f4efb0b16f3..dd4ee732b7091f9823036048d326bef3f3d6f1af 100644 (file)
@@ -6,14 +6,33 @@
 
 #include <Model_ResultGroup.h>
 #include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_AttributeIntArray.h>
+
 #include <GeomAlgoAPI_CompoundBuilder.h>
 
+#include <Config_PropManager.h>
+
 Model_ResultGroup::Model_ResultGroup(std::shared_ptr<ModelAPI_Data> theOwnerData)
 {
   setIsConcealed(false);
   myOwnerData = theOwnerData;
 }
 
+void Model_ResultGroup::initAttributes()
+{
+  // append the color attribute. It is empty, the attribute will be filled by a request
+  DataPtr aData = data();
+  aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::type());
+}
+
+void Model_ResultGroup::colorConfigInfo(std::string& theSection, std::string& theName,
+                                       std::string& theDefault)
+{
+  theSection = "Visualization";
+  theName = "result_group_color";
+  theDefault = DEFAULT_COLOR();
+}
+
 std::shared_ptr<GeomAPI_Shape> Model_ResultGroup::shape()
 {
   std::shared_ptr<GeomAPI_Shape> aResult;
index 33b4351c9ac3e59bd7527528d6b8d5a0d6490272..7bfa796942d8053b4f72f03188bf3a114222444a 100644 (file)
@@ -20,6 +20,19 @@ class Model_ResultGroup : public ModelAPI_ResultGroup
 {
   std::shared_ptr<ModelAPI_Data> myOwnerData;  ///< data of owner of this result
 public:
+  /// default color for a result body
+  inline static const std::string& DEFAULT_COLOR()
+  {
+    static const std::string RESULT_GROUP_COLOR("#E0A01B");
+    return RESULT_GROUP_COLOR;
+  }
+  /// Request for initialization of data model of the result: adding all attributes
+  virtual void initAttributes();
+
+  // Retuns the parameters of color definition in the resources config manager
+  MODEL_EXPORT virtual void colorConfigInfo(std::string& theSection, std::string& theName,
+                                            std::string& theDefault);
+
   /// Returns the compound of selected entities
   MODEL_EXPORT virtual std::shared_ptr<GeomAPI_Shape> shape();
 
index 497fe5365b604573f73a95f6bc306ea7b45b2ac8..44602ce1c17ab5e8dbff136c9bab23e62280acb5 100644 (file)
@@ -9,7 +9,7 @@ SET(PROJECT_HEADERS
     ModelAPI.h
     ModelAPI_Attribute.h
     ModelAPI_AttributeBoolean.h
-    ModelAPI_AttributeColor.h
+    ModelAPI_AttributeIntArray.h
     ModelAPI_AttributeDocRef.h
     ModelAPI_AttributeDouble.h
     ModelAPI_AttributeInteger.h
@@ -45,7 +45,7 @@ SET(PROJECT_HEADERS
 SET(PROJECT_SOURCES
     ModelAPI_Attribute.cpp
     ModelAPI_AttributeBoolean.cpp
-    ModelAPI_AttributeColor.cpp
+    ModelAPI_AttributeIntArray.cpp
     ModelAPI_AttributeDocRef.cpp
     ModelAPI_AttributeDouble.cpp
     ModelAPI_AttributeInteger.cpp
diff --git a/src/ModelAPI/ModelAPI_AttributeColor.cpp b/src/ModelAPI/ModelAPI_AttributeColor.cpp
deleted file mode 100644 (file)
index 1909fc3..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:        ModelAPI_AttributeColor.cpp
-// Created:     6 Mar 2015
-// Author:      Natalia ERMOLAEVA
-
-#include <ModelAPI_AttributeColor.h>
-
-
-std::string ModelAPI_AttributeColor::attributeType()
-{
-  return type();
-}
-
-/// To virtually destroy the fields of successors
-ModelAPI_AttributeColor::~ModelAPI_AttributeColor()
-{
-}
-
-ModelAPI_AttributeColor::ModelAPI_AttributeColor()
-{
-}
diff --git a/src/ModelAPI/ModelAPI_AttributeColor.h b/src/ModelAPI/ModelAPI_AttributeColor.h
deleted file mode 100644 (file)
index 6d3986a..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:        ModelAPI_AttributeColor.h
-// Created:     6 Mar 2015
-// Author:      Natalia ERMOLAEVA
-
-#ifndef ModelAPI_AttributeColor_H_
-#define ModelAPI_AttributeColor_H_
-
-#include <ModelAPI.h>
-#include <ModelAPI_Attribute.h>
-
-#include <string>
-
-
-/**\class ModelAPI_AttributeColor
- * \ingroup DataModel
- * \brief API for the attribute that contains color (int, int, int). The color is in the range [0, 255]
- * There is an opportunity to fill the attribute by a random color
- */
-
-class ModelAPI_AttributeColor : public ModelAPI_Attribute
-{
- public:
-  /// Defines the color value
-  /// \param theRed the red part of the color
-  /// \param theRed the green part of the color
-  /// \param theRed the blue part of the color
-  MODELAPI_EXPORT virtual void setValues(const int theRed,
-                                         const int theGreen,
-                                         const int theBlue) = 0;
-
-  /// Fills the attribute values by a random color
-  MODELAPI_EXPORT virtual void setValuesRandom() = 0;
-
-  /// Returns the color value
-  MODELAPI_EXPORT virtual void values(int& theRed, int& theGreen, int& theBlue) = 0;
-
-  /// Returns the type of this class of attributes
-  MODELAPI_EXPORT static std::string type()
-  {
-    return "Color";
-  }
-
-  /// Returns the type of this class of attributes, not static method
-  MODELAPI_EXPORT virtual std::string attributeType();
-
-  /// To virtually destroy the fields of successors
-  MODELAPI_EXPORT virtual ~ModelAPI_AttributeColor();
-
- protected:
-  /// Objects are created for features automatically
-  MODELAPI_EXPORT ModelAPI_AttributeColor();
-};
-
-//! Pointer on double attribute
-typedef std::shared_ptr<ModelAPI_AttributeColor> AttributeColorPtr;
-
-#endif
diff --git a/src/ModelAPI/ModelAPI_AttributeIntArray.cpp b/src/ModelAPI/ModelAPI_AttributeIntArray.cpp
new file mode 100644 (file)
index 0000000..0e0304c
--- /dev/null
@@ -0,0 +1,22 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        ModelAPI_AttributeIntArray.cpp
+// Created:     6 Mar 2015
+// Author:      Natalia ERMOLAEVA
+
+#include <ModelAPI_AttributeIntArray.h>
+
+
+std::string ModelAPI_AttributeIntArray::attributeType()
+{
+  return type();
+}
+
+/// To virtually destroy the fields of successors
+ModelAPI_AttributeIntArray::~ModelAPI_AttributeIntArray()
+{
+}
+
+ModelAPI_AttributeIntArray::ModelAPI_AttributeIntArray()
+{
+}
diff --git a/src/ModelAPI/ModelAPI_AttributeIntArray.h b/src/ModelAPI/ModelAPI_AttributeIntArray.h
new file mode 100644 (file)
index 0000000..177db04
--- /dev/null
@@ -0,0 +1,59 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        ModelAPI_AttributeIntArray.h
+// Created:     6 Mar 2015
+// Author:      Natalia ERMOLAEVA
+
+#ifndef ModelAPI_AttributeIntArray_H_
+#define ModelAPI_AttributeIntArray_H_
+
+#include <ModelAPI.h>
+#include <ModelAPI_Attribute.h>
+
+#include <string>
+
+
+/**\class ModelAPI_AttributeIntArray
+ * \ingroup DataModel
+ * \brief API for the attribute that contains several integers in the array inside.
+ * Used for RGB color storage for an example. By default size is one, zero-based.
+ */
+
+class ModelAPI_AttributeIntArray : public ModelAPI_Attribute
+{
+ public:
+
+  /// Returns the size of the array (zero means that it is empty)
+  MODELAPI_EXPORT virtual int size() = 0;
+
+  /// Sets the new size of the array. The previous data is erased.
+  MODELAPI_EXPORT virtual void setSize(const int theSize) = 0;
+
+  /// Defines the value of the array by index [0; size-1]
+  MODELAPI_EXPORT virtual void setValue(const int theIndex,
+                                         const int theValue) = 0;
+
+  /// Returns the value by the index
+  MODELAPI_EXPORT virtual int value(const int theIndex) = 0;
+
+  /// Returns the type of this class of attributes
+  MODELAPI_EXPORT static std::string type()
+  {
+    return "IntArray";
+  }
+
+  /// Returns the type of this class of attributes, not static method
+  MODELAPI_EXPORT virtual std::string attributeType();
+
+  /// To virtually destroy the fields of successors
+  MODELAPI_EXPORT virtual ~ModelAPI_AttributeIntArray();
+
+ protected:
+  /// Objects are created for features automatically
+  MODELAPI_EXPORT ModelAPI_AttributeIntArray();
+};
+
+//! Pointer on double attribute
+typedef std::shared_ptr<ModelAPI_AttributeIntArray> AttributeIntArrayPtr;
+
+#endif
index bb532ce08bc51bb56e97357cceae56636489f3af..2d6baddb0d7c5b4f7bf59ed71a5647e22e6f5a40 100644 (file)
@@ -26,6 +26,7 @@ class ModelAPI_Attribute;
 class ModelAPI_Feature;
 class ModelAPI_AttributeSelection;
 class ModelAPI_AttributeSelectionList;
+class ModelAPI_AttributeIntArray;
 class ModelAPI_Object;
 class GeomAPI_Shape;
 
@@ -75,6 +76,8 @@ class MODELAPI_EXPORT ModelAPI_Data
   virtual std::shared_ptr<ModelAPI_AttributeBoolean> boolean(const std::string& theID) = 0;
   /// Returns the attribute that contains boolean value
   virtual std::shared_ptr<ModelAPI_AttributeString> string(const std::string& theID) = 0;
+  /// Returns the attribute that contains integer values array
+  virtual std::shared_ptr<ModelAPI_AttributeIntArray> intArray(const std::string& theID) = 0;
 
   /// Returns the generic attribute by identifier
   /// \param theID identifier of the attribute
index 776a2839153c4d64efb681044983402b4f8ba551..c02abf60828854ffb8dac14a4c808e9129173efd 100644 (file)
@@ -42,6 +42,9 @@ class ModelAPI_Result : public ModelAPI_Object
     myIsConcealed = theValue;
   }
 
+  // Retuns the parameters of color definition in the resources config manager
+  virtual void colorConfigInfo(std::string& theSection, std::string& theName, std::string& theDefault) {}
+
   /// Request for initialization of data model of the result: adding all attributes
   virtual void initAttributes() {};
 
index 616e659e06c6a9c69bc0fbdb8ff39ea3470c54b0..f97a9ed7f4cbabe15350fc9165530511dd40a6f8 100644 (file)
@@ -7,6 +7,10 @@
 #include "ModuleBase_Preferences.h"
 //#include "ModuleBase_Constants.h"
 
+#include <Model_ResultBody.h>
+#include <Model_ResultGroup.h>
+#include <Model_ResultConstruction.h>
+
 #include <Config_PropManager.h>
 
 #include <SUIT_ResourceMgr.h>
@@ -256,6 +260,16 @@ void ModuleBase_PreferencesDlg::createViewerPage(int thePageId)
   myPreferences->setItemProperty("texture_stretch_enabled", true, bgId);
   myPreferences->setItemProperty("custom_enabled", false, bgId);
   myPreferences->setItemProperty("image_formats", aImgFiles, bgId);
+
+  //Config_PropManager::registerProp("Visualization", "object_default_color", "Object color",
+  //                                 Config_Prop::Color, "#ffffff");
+
+  Config_PropManager::registerProp("Visualization", "result_body_color", "Body color",
+                                   Config_Prop::Color, Model_ResultBody::DEFAULT_COLOR());
+  Config_PropManager::registerProp("Visualization", "result_group_color", "Group color",
+                                   Config_Prop::Color, Model_ResultGroup::DEFAULT_COLOR());
+  Config_PropManager::registerProp("Visualization", "result_construction_color", "Construction color",
+                                   Config_Prop::Color, Model_ResultConstruction::DEFAULT_COLOR());
 }
 
 void ModuleBase_PreferencesDlg::createMenuPage(int thePageId)
index d4efeee6c8c472a835e077d5d809ca171bf5c333..01c640568d5617ede4b48ae4725b6f6af098850f 100644 (file)
@@ -54,6 +54,7 @@ SET(PROJECT_LIBRARIES
     GeomAPI
     GeomAlgoAPI
     ModelAPI
+    SketcherPrs
     ${CAS_KERNEL}
     ${CAS_SHAPE}
 )
@@ -73,6 +74,7 @@ INCLUDE_DIRECTORIES(
   ../GeomAPI
   ../GeomAlgoAPI
   ../GeomDataAPI
+  ../SketcherPrs
 )
 
 INSTALL(TARGETS SketchPlugin DESTINATION plugins)
index 15f6d1cccfc0844d7e55f573fa3994e588d47781..358158325fc9b4da8f49f9a60ca6efae1e14a66c 100644 (file)
@@ -6,9 +6,13 @@
 
 #include "SketchPlugin_ConstraintCoincidence.h"
 
+#include <SketcherPrs_Factory.h>
+
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_Data.h>
 #include <SketchPlugin_Point.h>
+#include <GeomDataAPI_Dir.h>
+#include <GeomDataAPI_Point.h>
 
 SketchPlugin_ConstraintCoincidence::SketchPlugin_ConstraintCoincidence()
 {
@@ -24,3 +28,15 @@ void SketchPlugin_ConstraintCoincidence::execute()
 {
 }
 
+AISObjectPtr SketchPlugin_ConstraintCoincidence::getAISObject(AISObjectPtr thePrevious)
+{
+  if (!sketch())
+    return thePrevious;
+
+  AISObjectPtr anAIS = thePrevious;
+  if (!anAIS) {
+    anAIS = SketcherPrs_Factory::coincidentConstraint(this, sketch()->coordinatePlane());
+    anAIS->setColor(0, 0, 255);
+  }
+  return anAIS;
+}
\ No newline at end of file
index ce1939f7689a024ccc08847117c7e22486c0a737..c3f359d73bcc52b51177bcdaf8637b77f7490fe3 100644 (file)
@@ -35,6 +35,9 @@ class SketchPlugin_ConstraintCoincidence : public SketchPlugin_ConstraintBase
     return MY_KIND;
   }
 
+  /// Returns the AIS preview
+  SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
+
   /// \brief Creates a new part document if needed
   SKETCHPLUGIN_EXPORT virtual void execute();
 
index ae26fc1c2d41218454c5c7432032e4be0a8b0947..29a7f0a25c1c6da37e19c10a514b0ad0ee9687ff 100644 (file)
@@ -5,7 +5,6 @@
 // Author:  Artem ZHIDKOV
 
 #include "SketchPlugin_ConstraintParallel.h"
-#include "SketchPlugin_ConstraintPerpendicular.h"
 
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_Data.h>
 #include <SketchPlugin_Line.h>
 #include <SketchPlugin_Sketch.h>
 
+#include <SketcherPrs_Factory.h>
+
 #include <GeomDataAPI_Point2D.h>
 #include <GeomAPI_Pnt2d.h>
 #include <GeomAPI_Pnt.h>
+#include <GeomDataAPI_Dir.h>
+#include <GeomDataAPI_Point.h>
 
 #include <Config_PropManager.h>
 
@@ -28,7 +31,7 @@ void SketchPlugin_ConstraintParallel::initAttributes()
 {
   data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::type());
   data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::type());
-  data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::type());
+  //data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::type());
 }
 
 void SketchPlugin_ConstraintParallel::execute()
@@ -40,67 +43,11 @@ AISObjectPtr SketchPlugin_ConstraintParallel::getAISObject(AISObjectPtr thePrevi
   if (!sketch())
     return thePrevious;
 
-  std::shared_ptr<ModelAPI_Data> aData = data();
-  std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr1 = std::dynamic_pointer_cast<
-      ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
-  std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr2 = std::dynamic_pointer_cast<
-      ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_B()));
-  if (!anAttr1 || !anAttr1->isObject() || !anAttr2 || !anAttr2->isObject())
-    return thePrevious;
-
-  FeaturePtr aFeature = ModelAPI_Feature::feature(anAttr1->object());
-  if (!aFeature)
-    return thePrevious;
-  std::shared_ptr<SketchPlugin_Line> aLine1Feature =
-      std::dynamic_pointer_cast<SketchPlugin_Line>(aFeature);
-
-  aFeature = ModelAPI_Feature::feature(anAttr2->object());
-  if (!aFeature)
-    return thePrevious;
-  std::shared_ptr<SketchPlugin_Line> aLine2Feature =
-      std::dynamic_pointer_cast<SketchPlugin_Line>(aFeature);
-
-  if (!aLine1Feature || !aLine2Feature)
-    return thePrevious;
-
-  std::shared_ptr<GeomAPI_Pln> aPlane = sketch()->plane();
-  std::shared_ptr<GeomAPI_Shape> aLine1, aLine2;
-  std::shared_ptr<ModelAPI_ResultConstruction> aConst1 = std::dynamic_pointer_cast<
-      ModelAPI_ResultConstruction>(anAttr1->object());
-  if (aConst1)
-    aLine1 = aConst1->shape();
-  std::shared_ptr<ModelAPI_ResultConstruction> aConst2 = std::dynamic_pointer_cast<
-      ModelAPI_ResultConstruction>(anAttr2->object());
-  if (aConst2)
-    aLine2 = aConst2->shape();
-
-  std::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr = std::dynamic_pointer_cast<
-      GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
-  std::shared_ptr<GeomAPI_Pnt> aFlyoutPnt = std::shared_ptr<GeomAPI_Pnt>();;
-  if(aFlyoutAttr->isInitialized()) {
-    aFlyoutPnt = sketch()->to3D(aFlyoutAttr->x(), aFlyoutAttr->y());
-  }
-
   AISObjectPtr anAIS = thePrevious;
-  if (!anAIS)
-    anAIS = AISObjectPtr(new GeomAPI_AISObject);
-  anAIS->createParallel(aLine1, aLine2, aFlyoutPnt, aPlane);
-
-  // Set color from preferences
-  std::vector<int> aRGB = Config_PropManager::color("Visualization", "sketch_parallel_color",
-                                                    SKETCH_CONSTRAINT_COLOR);
-  anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]);
+  if (!anAIS) {
+    anAIS = SketcherPrs_Factory::parallelConstraint(this, sketch()->coordinatePlane());
+  }
   return anAIS;
 }
 
-void SketchPlugin_ConstraintParallel::move(double theDeltaX, double theDeltaY)
-{
-  std::shared_ptr<ModelAPI_Data> aData = data();
-  if (!aData->isValid())
-    return;
-
-  std::shared_ptr<GeomDataAPI_Point2D> aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
-      aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
-  aPoint->move(theDeltaX, theDeltaY);
-}
 
index 87f69fe70ee76b2506e25abe546325ef607856b4..afaae6c005bca6baaaabe05adf1d4b787c7e19a5 100644 (file)
@@ -46,7 +46,7 @@ class SketchPlugin_ConstraintParallel : public SketchPlugin_ConstraintBase
   /// Moves the feature
   /// \param theDeltaX the delta for X coordinate is moved
   /// \param theDeltaY the delta for Y coordinate is moved
-  SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY);
+  //SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY);
 
   /// \brief Use plugin manager for features creation
   SketchPlugin_ConstraintParallel();
index c19e27114b2bb001425f78ae9f8b383f6031c5aa..58ab7cb98af9708399f88d172a257094dd8a7839 100644 (file)
@@ -117,10 +117,7 @@ void SketchPlugin_Sketch::execute()
   for (; aShapeIt != aFeaturesPreview.end(); ++aShapeIt) {
     aBigWire->addEdge(*aShapeIt);
   }
-  aBigWire->setOrigin(anOrigin->pnt());
-  aBigWire->setDirX(aDirX->dir());
-  aBigWire->setDirY(aDirY->dir());
-  aBigWire->setNorm(aNorm->dir());
+  aBigWire->setPlane(anOrigin->pnt(), aDirX->dir(), aDirY->dir(), aNorm->dir());
 
 //  GeomAlgoAPI_SketchBuilder::createFaces(anOrigin->pnt(), aDirX->dir(), aDirY->dir(), aNorm->dir(),
 //                                         aFeaturesPreview, aLoops, aWires);
@@ -246,6 +243,21 @@ std::shared_ptr<GeomAPI_Pln> SketchPlugin_Sketch::plane()
   return std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(anOrigin->pnt(), aNorm->dir()));
 }
 
+std::shared_ptr<GeomAPI_Ax3> SketchPlugin_Sketch::coordinatePlane() const
+{
+  DataPtr aData = data();
+  std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
+    aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
+  std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+    aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
+  std::shared_ptr<GeomDataAPI_Dir> aY = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+    aData->attribute(SketchPlugin_Sketch::DIRY_ID()));
+  std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+    aData->attribute(SketchPlugin_Sketch::NORM_ID()));
+
+  return std::shared_ptr<GeomAPI_Ax3>(new GeomAPI_Ax3(aC->pnt(), aX->dir(), aY->dir(), aNorm->dir()));
+}
+
 void SketchPlugin_Sketch::erase()
 {
   std::shared_ptr<ModelAPI_AttributeRefList> aRefList = std::dynamic_pointer_cast<
index c4721f547bfb114dbd7d50a0f6d9c948d3d4b966..43a6e370792dc38e1d020ee6808fe739d6b5e04f 100644 (file)
@@ -12,6 +12,7 @@
 #include <GeomAPI_Pnt.h>
 #include <GeomAPI_Pln.h>
 #include <GeomAPI_IPresentable.h>
+#include <GeomAPI_Ax3.h>
 #include <list>
 
 #define YZ_PLANE_COLOR "#ff0000"
@@ -81,7 +82,6 @@ class SketchPlugin_Sketch : public ModelAPI_CompositeFeature//, public GeomAPI_I
   SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY)
   {
   }
-  ;
 
   /// Return the distance between the feature and the point
   /// \param thePoint the point
@@ -89,7 +89,6 @@ class SketchPlugin_Sketch : public ModelAPI_CompositeFeature//, public GeomAPI_I
   {
     return 0;
   }
-  ;
 
   /// Converts a 2D sketch space point into point in 3D space
   SKETCHPLUGIN_EXPORT std::shared_ptr<GeomAPI_Pnt> to3D(const double theX, const double theY);
@@ -106,6 +105,8 @@ class SketchPlugin_Sketch : public ModelAPI_CompositeFeature//, public GeomAPI_I
   /// Returns the basis plane for the sketch
   std::shared_ptr<GeomAPI_Pln> plane();
 
+  SKETCHPLUGIN_EXPORT std::shared_ptr<GeomAPI_Ax3> coordinatePlane() const;
+
   //virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
 
   /// removes also all sub-sketch elements
index 1e7c4de3b5e2a999f2714426e2bc4feac8373118..0737eb899b8f4c756a443b3d154ee0a4fa002476 100644 (file)
@@ -4,6 +4,7 @@
 
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Validator.h>
+#include <ModelAPI_AttributeIntArray.h>
 
 SketchPlugin_SketchEntity::SketchPlugin_SketchEntity()
 : SketchPlugin_Feature()
index c0c0925638556abf9425de6208d45c1d184f8553..b1b74b519c9d9824dcc1b37009784a17070139a2 100644 (file)
@@ -60,48 +60,53 @@ class SketchPlugin_SketchEntity : public SketchPlugin_Feature, public GeomAPI_IC
   }
 
   /// Customize presentation of the feature
-  virtual void customisePresentation(AISObjectPtr thePrs)
+  virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
+                                     std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
   {
-    std::vector<int> aRGB;
-  
+    bool isCustomized = false;
     int aShapeType = thePrs->getShapeType();
-    if (aShapeType != 6/*an edge*/ && aShapeType != 7/*a vertex*/)
-      return;
+    // a compound is processed like the edge because the arc feature uses the compound for presentable AIS
+    if (aShapeType != 6/*an edge*/ && aShapeType != 7/*a vertex*/ && aShapeType != 0/*compound*/)
+      return false;
 
+    std::vector<int> aColor;
     std::shared_ptr<ModelAPI_AttributeBoolean> aConstructionAttr =
-                                   data()->boolean(SketchPlugin_SketchEntity::CONSTRUCTION_ID());
+                                    data()->boolean(SketchPlugin_SketchEntity::CONSTRUCTION_ID());
     bool isConstruction = aConstructionAttr.get() != NULL && aConstructionAttr->value();
-    if (aShapeType == 6) { // if this is an edge
+    if (aShapeType == 6 || aShapeType == 0) { // if this is an edge or a compound
       if (isConstruction) {
-        thePrs->setWidth(1);
-        thePrs->setLineStyle(3);
-        aRGB = Config_PropManager::color("Visualization", "sketch_construction_color",
-                                         SKETCH_CONSTRUCTION_COLOR);
+        isCustomized = thePrs->setWidth(1) || isCustomized;
+        isCustomized = thePrs->setLineStyle(3) || isCustomized;
+
+        aColor = Config_PropManager::color("Visualization", "sketch_construction_color",
+                                          SKETCH_CONSTRUCTION_COLOR);
       }
       else {
-        thePrs->setWidth(3);
-        thePrs->setLineStyle(0);
+        isCustomized = thePrs->setWidth(3) || isCustomized;
+        isCustomized = thePrs->setLineStyle(0) || isCustomized;
+
         if (isExternal()) {
           // Set color from preferences
-          aRGB = Config_PropManager::color("Visualization", "sketch_external_color",
-                                           SKETCH_EXTERNAL_EDGE_COLOR);
+          aColor = Config_PropManager::color("Visualization", "sketch_external_color",
+                                            SKETCH_EXTERNAL_EDGE_COLOR);
         }
         else {
           // Set color from preferences
-          aRGB = Config_PropManager::color("Visualization", "sketch_edge_color",
-                                           SKETCH_EDGE_COLOR);
+          aColor = Config_PropManager::color("Visualization", "sketch_edge_color",
+                                             SKETCH_EDGE_COLOR);
         }
       }
     }
     else if (aShapeType == 7) { // otherwise this is a vertex
       //  thePrs->setPointMarker(6, 2.);
-      // Set color from preferences
-      aRGB = Config_PropManager::color("Visualization", "sketch_point_color",
-                                       SKETCH_POINT_COLOR);
+      aColor = Config_PropManager::color("Visualization", "sketch_point_color",
+                                        SKETCH_POINT_COLOR);
     }
 
-    if (!aRGB.empty())
-      thePrs->setColor(aRGB[0], aRGB[1], aRGB[2]);
+    if (!aColor.empty()) {
+      isCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]) || isCustomized;
+    }
+    return isCustomized;
   }
 
 protected:
index 9eb94b38ff2f2fa300e0c0d0a16e4beedfc10f46..3875aa213b0b802f92030f0f09dc56edcacb113e 100644 (file)
@@ -15,6 +15,7 @@
       </feature>
       <feature id="SketchPoint" title="Point" tooltip="Create a new point" icon=":icons/point.png">
         <sketch-2dpoint_selector id="PointCoordindates" title="Point" tooltip="Point coordinates"/>
+        <boolvalue id="Construction" label="Construction" default="false" tooltip="Construction element" obligatory="0"/>
       </feature>
       <feature id="SketchLine" title="Line" tooltip="Create a new line" icon=":icons/line.png">
         <sketch-2dpoint_selector id="StartPoint" title="Start point" tooltip="Start point coordinates" previous_feature_param="EndPoint"/>
         <point2ddistance id="CircleRadius" first_point="CircleCenter" label="Radius:" min="0" step="1.0" default="0" icon=":icons/radius.png" tooltip="Set radius">
           <validator id="GeomValidators_Positive"/>
         </point2ddistance>
+        <boolvalue id="Construction" label="Construction" default="false" tooltip="Construction element" obligatory="0"/>
       </feature>
       <feature id="SketchArc" title="Arc" tooltip="Create a new arc" icon=":icons/arc.png">
         <sketch-2dpoint_selector id="ArcCenter" title="Center" tooltip="Center of a circle"/>
         <sketch-2dpoint_selector id="ArcStartPoint" title="Start point" tooltip="Start point"/>
         <sketch-2dpoint_selector id="ArcEndPoint" title="End point" tooltip="End point"/>
+        <boolvalue id="Construction" label="Construction" default="false" tooltip="Construction element" obligatory="0"/>
       </feature>
     </group>
       
             <validator id="SketchPlugin_ShapeValidator" parameters="ConstraintEntityA"/>
         </sketch_constraint_shape_selector>
         
-        <sketch-2dpoint_selector id="ConstraintFlyoutValuePnt" internal="1" obligatory="0"/>
         <validator id="PartSet_ParallelValidator"/>
       </feature>
     <!--  SketchConstraintPerpendicular  -->
diff --git a/src/SketcherPrs/CMakeLists.txt b/src/SketcherPrs/CMakeLists.txt
new file mode 100644 (file)
index 0000000..fcb8889
--- /dev/null
@@ -0,0 +1,48 @@
+## Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+SET(PROJECT_HEADERS
+    SketcherPrs.h
+    SketcherPrs_Coincident.h
+    SketcherPrs_Factory.h
+       SketcherPrs_Parallel.h
+       SketcherPrs_Tools.h
+)
+
+SET(PROJECT_SOURCES
+    SketcherPrs_Coincident.cpp
+    SketcherPrs_Factory.cpp
+       SketcherPrs_Parallel.cpp
+       SketcherPrs_Tools.cpp
+)
+
+SET(PROJECT_LIBRARIES
+    Config
+    ModelAPI
+    GeomAPI
+    ${CAS_KERNEL} 
+    ${CAS_MODELER} 
+    ${CAS_VIEWER}
+    ${CAS_SHAPE}
+    ${CAS_TKTopAlgo}
+)
+
+SET(PROJECT_PICTURES
+    icons/parallel.png
+)
+
+ADD_DEFINITIONS(-DCONSTRAINTS_EXPORTS ${CAS_DEFINITIONS})
+ADD_LIBRARY(SketcherPrs SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS})
+
+INCLUDE_DIRECTORIES(
+  ${PROJECT_SOURCE_DIR}/src/Config
+  ${PROJECT_SOURCE_DIR}/src/ModelAPI
+  ${PROJECT_SOURCE_DIR}/src/GeomAPI
+  ${PROJECT_SOURCE_DIR}/src/GeomDataAPI
+  ${PROJECT_SOURCE_DIR}/src/SketchPlugin
+  ${CAS_INCLUDE_DIRS}
+)
+
+TARGET_LINK_LIBRARIES(SketcherPrs ${PROJECT_LIBRARIES})
+
+INSTALL(TARGETS SketcherPrs DESTINATION bin)
+INSTALL(FILES ${PROJECT_PICTURES} DESTINATION resources)
diff --git a/src/SketcherPrs/SketcherPrs.h b/src/SketcherPrs/SketcherPrs.h
new file mode 100644 (file)
index 0000000..978f8c2
--- /dev/null
@@ -0,0 +1,20 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+#ifndef SKETCHERPRS_H
+#define SKETCHERPRS_H
+
+#if defined SKETCHERPRS_EXPORTS
+#if defined WIN32
+#define SKETCHERPRS_EXPORT   __declspec( dllexport )
+#else
+#define SKETCHERPRS_EXPORT
+#endif
+#else
+#if defined WIN32
+#define SKETCHERPRS_EXPORT   __declspec( dllimport )
+#else
+#define SKETCHERPRS_EXPORT
+#endif
+#endif
+
+#endif
diff --git a/src/SketcherPrs/SketcherPrs_Coincident.cpp b/src/SketcherPrs/SketcherPrs_Coincident.cpp
new file mode 100644 (file)
index 0000000..60c2e45
--- /dev/null
@@ -0,0 +1,78 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        SketcherPrs_Coincident.cpp
+// Created:     12 February 2015
+// Author:      Vitaly SMETANNIKOV
+
+#include "SketcherPrs_Coincident.h"
+#include "SketcherPrs_Tools.h"
+
+#include <ModelAPI_AttributeRefAttr.h>
+#include <GeomDataAPI_Point2D.h>
+#include <GeomDataAPI_Dir.h>
+#include <GeomDataAPI_Point.h>
+
+#include <GeomAPI_XYZ.h>
+#include <GeomAPI_Dir.h>
+#include <GeomAPI_Pnt2d.h>
+
+#include <SketchPlugin_Point.h>
+#include <SketchPlugin_Circle.h>
+#include <SketchPlugin_Constraint.h>
+
+#include <AIS_Drawer.hxx>
+#include <Graphic3d_AspectMarker3d.hxx>
+#include <Graphic3d_ArrayOfPoints.hxx>
+#include <Prs3d_PointAspect.hxx>
+#include <Prs3d_Root.hxx>
+
+
+IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Coincident, AIS_InteractiveObject);
+IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Coincident, AIS_InteractiveObject);
+
+SketcherPrs_Coincident::SketcherPrs_Coincident(SketchPlugin_Constraint* theConstraint, 
+                                               const std::shared_ptr<GeomAPI_Ax3>& thePlane) 
+ : AIS_InteractiveObject(), myConstraint(theConstraint), myPlane(thePlane)
+{
+}  
+
+
+
+void SketcherPrs_Coincident::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
+                                   const Handle(Prs3d_Presentation)& thePresentation, 
+                                   const Standard_Integer theMode)
+{
+  std::shared_ptr<GeomAPI_Pnt2d> aPnt = SketcherPrs_Tools::getPoint(myConstraint, 
+                                                                    SketchPlugin_Constraint::ENTITY_A());
+  if (aPnt.get() == NULL)
+    return;
+
+  std::shared_ptr<GeomAPI_Pnt> aPoint = myPlane->to3D(aPnt->x(), aPnt->y());
+
+  static Handle(Graphic3d_AspectMarker3d) aPtA = new Graphic3d_AspectMarker3d ();
+  aPtA->SetType(Aspect_TOM_RING1);
+  aPtA->SetScale(2.);
+  aPtA->SetColor(myOwnColor);
+  Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
+  aGroup->SetPrimitivesAspect(aPtA);
+  Handle(Graphic3d_ArrayOfPoints) aPntArray = new Graphic3d_ArrayOfPoints(1);
+  aPntArray->AddVertex (aPoint->x(), aPoint->y(), aPoint->z());
+  aGroup->AddPrimitiveArray (aPntArray);
+}
+
+
+void SketcherPrs_Coincident::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
+                                            const Standard_Integer aMode)
+{
+}
+
+void SketcherPrs_Coincident::SetColor(const Quantity_NameOfColor aCol)
+{
+  SetColor(Quantity_Color(aCol));
+}
+
+void SketcherPrs_Coincident::SetColor(const Quantity_Color &aCol)
+{
+  hasOwnColor=Standard_True;
+  myOwnColor=aCol;
+}
diff --git a/src/SketcherPrs/SketcherPrs_Coincident.h b/src/SketcherPrs/SketcherPrs_Coincident.h
new file mode 100644 (file)
index 0000000..9b9c4cd
--- /dev/null
@@ -0,0 +1,53 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        SketcherPrs_Coincident.h
+// Created:     12 February 2015
+// Author:      Vitaly SMETANNIKOV
+
+#ifndef SketcherPrs_Coincident_H
+#define SketcherPrs_Coincident_H
+
+#include <GeomAPI_Ax3.h>
+
+#include <AIS_InteractiveObject.hxx>
+#include <Standard_DefineHandle.hxx>
+
+class SketchPlugin_Constraint;
+
+
+DEFINE_STANDARD_HANDLE(SketcherPrs_Coincident, AIS_InteractiveObject)
+
+/**
+* \ingroup GUI
+* A redefinition of standard AIS Interactive Object in order to provide  
+* presentation of coincident constraint
+*/
+class SketcherPrs_Coincident: public AIS_InteractiveObject
+{
+public:
+  /// Constructor
+  /// \param theResult a result object
+  Standard_EXPORT SketcherPrs_Coincident(SketchPlugin_Constraint* theConstraint, 
+                                         const std::shared_ptr<GeomAPI_Ax3>& thePlane);
+
+  Standard_EXPORT virtual void SetColor(const Quantity_Color& aColor);
+  
+  Standard_EXPORT virtual void SetColor(const Quantity_NameOfColor aColor);
+   
+  DEFINE_STANDARD_RTTI(SketcherPrs_Coincident)
+protected:
+  /// Redefinition of virtual function
+  Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
+    const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode = 0);
+
+  /// Redefinition of virtual function
+  Standard_EXPORT virtual void ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
+    const Standard_Integer aMode) ;
+
+private:
+  SketchPlugin_Constraint* myConstraint;
+  std::shared_ptr<GeomAPI_Ax3> myPlane;
+};
+
+
+#endif
\ No newline at end of file
diff --git a/src/SketcherPrs/SketcherPrs_Factory.cpp b/src/SketcherPrs/SketcherPrs_Factory.cpp
new file mode 100644 (file)
index 0000000..829052f
--- /dev/null
@@ -0,0 +1,30 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        SketcherPrs_Factory.cpp
+// Created:     13 February 2015
+// Author:      Vitaly SMETANNIKOV
+
+#include "SketcherPrs_Factory.h"
+
+#include <SketcherPrs_Coincident.h>
+#include <SketcherPrs_Parallel.h>
+
+
+AISObjectPtr SketcherPrs_Factory::coincidentConstraint(SketchPlugin_Constraint* theConstraint, 
+                                                       const std::shared_ptr<GeomAPI_Ax3>& thePlane)
+{
+  std::shared_ptr<GeomAPI_AISObject> aAISObj = AISObjectPtr(new GeomAPI_AISObject());
+  Handle(SketcherPrs_Coincident) aPrs = new SketcherPrs_Coincident(theConstraint, thePlane);
+  aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs));
+  return aAISObj;
+}
+
+
+AISObjectPtr SketcherPrs_Factory::parallelConstraint(SketchPlugin_Constraint* theConstraint, 
+                                                     const std::shared_ptr<GeomAPI_Ax3>& thePlane)
+{
+  std::shared_ptr<GeomAPI_AISObject> aAISObj = AISObjectPtr(new GeomAPI_AISObject());
+  Handle(SketcherPrs_Parallel) aPrs = new SketcherPrs_Parallel(theConstraint, thePlane);
+  aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs));
+  return aAISObj;
+}
\ No newline at end of file
diff --git a/src/SketcherPrs/SketcherPrs_Factory.h b/src/SketcherPrs/SketcherPrs_Factory.h
new file mode 100644 (file)
index 0000000..75a496f
--- /dev/null
@@ -0,0 +1,36 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        SketcherPrs_Factory.h
+// Created:     13 February 2015
+// Author:      Vitaly SMETANNIKOV
+
+#ifndef SketcherPrs_Factory_H_
+#define SketcherPrs_Factory_H_
+
+#include "SketcherPrs.h"
+
+#include <GeomAPI_Ax3.h>
+#include <GeomAPI_AISObject.h>
+
+class SketchPlugin_Constraint;
+
+/**
+* Class which creates constraints presentations
+*/
+class SKETCHERPRS_EXPORT SketcherPrs_Factory
+{
+public:
+  /// Creates coincedent constraint presentation
+  /// \param theConstraint the constraint
+  /// \param thePlane the current sketch plane
+  static AISObjectPtr coincidentConstraint(SketchPlugin_Constraint* theConstraint, 
+                                           const std::shared_ptr<GeomAPI_Ax3>& thePlane);
+
+  /// Creates coincedent parallel presentation
+  /// \param theConstraint the constraint
+  /// \param thePlane the current sketch plane
+  static AISObjectPtr parallelConstraint(SketchPlugin_Constraint* theConstraint, 
+                                         const std::shared_ptr<GeomAPI_Ax3>& thePlane);
+};
+
+#endif
diff --git a/src/SketcherPrs/SketcherPrs_Parallel.cpp b/src/SketcherPrs/SketcherPrs_Parallel.cpp
new file mode 100644 (file)
index 0000000..74e9772
--- /dev/null
@@ -0,0 +1,124 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        SketcherPrs_Parallel.cpp
+// Created:     16 February 2015
+// Author:      Vitaly SMETANNIKOV
+
+#include "SketcherPrs_Parallel.h"
+#include "SketcherPrs_Tools.h"
+
+#include <GeomAPI_Pnt.h>
+
+#include <SketchPlugin_Constraint.h>
+
+#include <AIS_Drawer.hxx>
+#include <Graphic3d_AspectMarker3d.hxx>
+#include <Prs3d_PointAspect.hxx>
+#include <Prs3d_Root.hxx>
+#include <gp_Pnt2d.hxx>
+#include <Image_AlienPixMap.hxx>
+#include <Graphic3d_MarkerImage.hxx>
+#include <SelectMgr_EntityOwner.hxx>
+#include <Select3D_SensitivePoint.hxx>
+#include <SelectMgr_Selection.hxx>
+#include <Select3D_SensitiveSegment.hxx>
+
+extern std::shared_ptr<GeomAPI_Pnt2d> getFeaturePoint(DataPtr theData,
+                                                      const std::string& theAttribute);
+
+#ifdef WIN32
+# define FSEP "\\"
+#else
+# define FSEP "/"
+#endif
+
+
+IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Parallel, AIS_InteractiveObject);
+IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Parallel, AIS_InteractiveObject);
+
+static Handle(Image_AlienPixMap) MyPixMap;
+
+SketcherPrs_Parallel::SketcherPrs_Parallel(SketchPlugin_Constraint* theConstraint, 
+                                           const std::shared_ptr<GeomAPI_Ax3>& thePlane) 
+ : AIS_InteractiveObject(), myConstraint(theConstraint), myPlane(thePlane)
+{
+  if (MyPixMap.IsNull()) {
+    TCollection_AsciiString aFile(getenv("NewGeomResources"));
+    aFile += FSEP;
+    aFile += "parallel.png";
+    MyPixMap = new Image_AlienPixMap();
+    if (!MyPixMap->Load(aFile))
+      MyPixMap.Nullify();
+  }
+  if (!MyPixMap.IsNull()) {
+    myAspect = new Graphic3d_AspectMarker3d(MyPixMap);
+    myPntArray = new Graphic3d_ArrayOfPoints(2);
+    myPntArray->AddVertex(0., 0., 0.);
+    myPntArray->AddVertex(0. ,0., 0.);
+  }
+}  
+
+void SketcherPrs_Parallel::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
+                                   const Handle(Prs3d_Presentation)& thePresentation, 
+                                   const Standard_Integer theMode)
+{
+  if (myAspect.IsNull())
+    return;
+
+  std::shared_ptr<GeomAPI_Edge> aLine1 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_A());
+  if (aLine1.get() == NULL)
+    return;
+
+  std::shared_ptr<GeomAPI_Edge> aLine2 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_B());
+  if (aLine2.get() == NULL)
+    return;
+
+  std::shared_ptr<GeomAPI_Pnt> aPnt1 = aLine1->firstPoint();
+  std::shared_ptr<GeomAPI_Pnt> aPnt2 = aLine1->lastPoint();
+  gp_Pnt aP1((aPnt1->x() + aPnt2->x())/2.,
+             (aPnt1->y() + aPnt2->y())/2.,
+             (aPnt1->z() + aPnt2->z())/2.);
+
+  gp_Vec aVec1(aPnt1->impl<gp_Pnt>(), aPnt2->impl<gp_Pnt>());
+  gp_Vec aShift = aVec1.Crossed(myPlane->norm()->impl<gp_Dir>());
+  aShift.Normalize();
+  aShift.Multiply(20);
+  aP1.Translate(aShift);
+
+  aPnt1 = aLine2->firstPoint();
+  aPnt2 = aLine2->lastPoint();
+  gp_Pnt aP2((aPnt1->x() + aPnt2->x())/2.,
+             (aPnt1->y() + aPnt2->y())/2.,
+             (aPnt1->z() + aPnt2->z())/2.);
+
+  gp_Vec aVec2(aPnt1->impl<gp_Pnt>(), aPnt2->impl<gp_Pnt>());
+  aShift = aVec1.Crossed(myPlane->norm()->impl<gp_Dir>());
+  aShift.Normalize();
+  aShift.Multiply(20);
+  aP2.Translate(aShift);
+
+  Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
+  aGroup->SetPrimitivesAspect(myAspect);
+  myPntArray->SetVertice(1, aP1);
+  myPntArray->SetVertice(2, aP2);
+  aGroup->AddPrimitiveArray(myPntArray);
+}
+
+void SketcherPrs_Parallel::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
+                                            const Standard_Integer aMode)
+{
+  std::shared_ptr<GeomAPI_Edge> aLine1 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_A());
+  if (aLine1.get() == NULL)
+    return;
+
+  std::shared_ptr<GeomAPI_Edge> aLine2 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_B());
+  if (aLine2.get() == NULL)
+    return;
+
+  Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this);
+  Handle(Select3D_SensitivePoint) aSP1 = new Select3D_SensitivePoint(eown, myPntArray->Vertice(1));
+  Handle(Select3D_SensitivePoint) aSP2 = new Select3D_SensitivePoint(eown, myPntArray->Vertice(2));
+  aSelection->Add(aSP1);
+  aSelection->Add(aSP2);
+}
+
diff --git a/src/SketcherPrs/SketcherPrs_Parallel.h b/src/SketcherPrs/SketcherPrs_Parallel.h
new file mode 100644 (file)
index 0000000..5e39abb
--- /dev/null
@@ -0,0 +1,56 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        SketcherPrs_Parallel.h
+// Created:     16 February 2015
+// Author:      Vitaly SMETANNIKOV
+
+#ifndef SketcherPrs_Parallel_H
+#define SketcherPrs_Parallel_H
+
+#include <GeomAPI_Ax3.h>
+#include <GeomAPI_Edge.h>
+
+#include <AIS_InteractiveObject.hxx>
+#include <Graphic3d_ArrayOfPoints.hxx>
+#include <Graphic3d_AspectMarker3d.hxx>
+#include <Standard_DefineHandle.hxx>
+
+class SketchPlugin_Constraint;
+class SketchPlugin_Sketch;
+
+
+DEFINE_STANDARD_HANDLE(SketcherPrs_Parallel, AIS_InteractiveObject)
+
+/**
+* \ingroup GUI
+* A redefinition of standard AIS Interactive Object in order to provide  
+* presentation of coincident constraint
+*/
+class SketcherPrs_Parallel: public AIS_InteractiveObject
+{
+public:
+  /// Constructor
+  /// \param theResult a result object
+  Standard_EXPORT SketcherPrs_Parallel(SketchPlugin_Constraint* theConstraint, 
+                                       const std::shared_ptr<GeomAPI_Ax3>& thePlane);
+
+
+  DEFINE_STANDARD_RTTI(SketcherPrs_Parallel)
+protected:
+  /// Redefinition of virtual function
+  Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
+    const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode = 0);
+
+  /// Redefinition of virtual function
+  Standard_EXPORT virtual void ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
+    const Standard_Integer aMode) ;
+
+private:
+
+  SketchPlugin_Constraint* myConstraint;
+  std::shared_ptr<GeomAPI_Ax3> myPlane;
+  Handle(Graphic3d_AspectMarker3d) myAspect;
+  Handle(Graphic3d_ArrayOfPoints) myPntArray;
+};
+
+#endif
\ No newline at end of file
diff --git a/src/SketcherPrs/SketcherPrs_Tools.cpp b/src/SketcherPrs/SketcherPrs_Tools.cpp
new file mode 100644 (file)
index 0000000..2f356e1
--- /dev/null
@@ -0,0 +1,69 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        SketcherPrs_Tools.cpp
+// Created:     10 March 2015
+// Author:      Vitaly SMETANNIKOV
+
+#include "SketcherPrs_Tools.h"
+
+#include <SketchPlugin_Constraint.h>
+#include <SketchPlugin_Point.h>
+#include <SketchPlugin_Circle.h>
+#include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_AttributeRefAttr.h>
+
+#include <GeomDataAPI_Point2D.h>
+
+
+namespace SketcherPrs_Tools {
+
+
+std::shared_ptr<GeomAPI_Edge> getLine(SketchPlugin_Constraint* theFeature,
+                                      const std::string& theAttrName)
+{
+  std::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+  std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = 
+    std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(theAttrName));
+
+  ObjectPtr aObject = anAttr->object();
+  ResultConstructionPtr aRes = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aObject);
+  if (aRes.get() != NULL) {
+    std::shared_ptr<GeomAPI_Shape> aShape = aRes->shape();
+    if (aShape.get() != NULL) {   
+      return std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aShape));
+    }
+  }
+  return std::shared_ptr<GeomAPI_Edge>();
+}
+
+
+std::shared_ptr<GeomAPI_Pnt2d> getPoint(SketchPlugin_Constraint* theFeature,
+                                               const std::string& theAttribute)
+{
+  std::shared_ptr<GeomDataAPI_Point2D> aPointAttr;
+
+  if (!theFeature->data())
+    return std::shared_ptr<GeomAPI_Pnt2d>();
+
+  FeaturePtr aFeature;
+  std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = std::dynamic_pointer_cast<
+      ModelAPI_AttributeRefAttr>(theFeature->data()->attribute(theAttribute));
+  if (anAttr)
+    aFeature = ModelAPI_Feature::feature(anAttr->object());
+
+  if (aFeature && aFeature->getKind() == SketchPlugin_Point::ID())
+    aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+        aFeature->data()->attribute(SketchPlugin_Point::COORD_ID()));
+
+  else if (aFeature && aFeature->getKind() == SketchPlugin_Circle::ID())
+    aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+        aFeature->data()->attribute(SketchPlugin_Circle::CENTER_ID()));
+
+  else if (anAttr->attr()) {
+    aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr->attr());
+  }
+  return aPointAttr->pnt();
+}
+
+
+};
\ No newline at end of file
diff --git a/src/SketcherPrs/SketcherPrs_Tools.h b/src/SketcherPrs/SketcherPrs_Tools.h
new file mode 100644 (file)
index 0000000..5a93295
--- /dev/null
@@ -0,0 +1,27 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        SketcherPrs_Tools.h
+// Created:     10 March 2015
+// Author:      Vitaly SMETANNIKOV
+
+#ifndef SketcherPrs_Tools_H
+#define SketcherPrs_Tools_H
+
+#include "SketcherPrs.h"
+#include <GeomAPI_Edge.h>
+#include <GeomAPI_Pnt2d.h>
+#include <string>
+
+class SketchPlugin_Constraint;
+
+namespace SketcherPrs_Tools {
+
+  std::shared_ptr<GeomAPI_Edge> getLine(SketchPlugin_Constraint* theFeature,
+                                        const std::string& theAttrName);
+
+  std::shared_ptr<GeomAPI_Pnt2d> getPoint(SketchPlugin_Constraint* theFeature,
+                                          const std::string& theAttrName);
+
+};
+
+#endif
\ No newline at end of file
diff --git a/src/SketcherPrs/icons/parallel.png b/src/SketcherPrs/icons/parallel.png
new file mode 100644 (file)
index 0000000..4918612
Binary files /dev/null and b/src/SketcherPrs/icons/parallel.png differ
index c7a27c7161cfdc275dc1f0be70c5ca5f2282d253..bd843caa93b19576aab7c2eca61099108cc77a7c 100644 (file)
@@ -7,6 +7,7 @@ SET(PROJECT_HEADERS
        XGUI.h
        XGUI_ActionsMgr.h
        XGUI_ContextMenuMgr.h
+       XGUI_CustomPrs.h
        XGUI_DataTreeModel.h
        XGUI_Displayer.h
        XGUI_DocumentDataModel.h
@@ -33,6 +34,7 @@ SET(PROJECT_AUTOMOC
 SET(PROJECT_SOURCES
        XGUI_ActionsMgr.cpp
        XGUI_ContextMenuMgr.cpp
+       XGUI_CustomPrs.cpp
        XGUI_Displayer.cpp
        XGUI_DocumentDataModel.cpp
        XGUI_ErrorDialog.cpp
diff --git a/src/XGUI/XGUI_CustomPrs.cpp b/src/XGUI/XGUI_CustomPrs.cpp
new file mode 100644 (file)
index 0000000..8584bc5
--- /dev/null
@@ -0,0 +1,55 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        XGUI_CustomPrs.cpp
+// Created:     10 Mar 2015
+// Author:      Natalia ERMOLAEVA
+
+#include <XGUI_CustomPrs.h>
+
+#include <ModelAPI_AttributeIntArray.h>
+#include <Config_PropManager.h>
+
+#include <vector>
+
+
+void getColor(ResultPtr theResult, std::vector<int>& theColor)
+{
+  theColor.clear();
+  // get color from the attribute of the result
+  if (theResult.get() != NULL && theResult->data()->attribute(ModelAPI_Result::COLOR_ID()).get() != NULL) {
+    AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
+    if (aColorAttr.get() && aColorAttr->size()) {
+      theColor.push_back(aColorAttr->value(0));
+      theColor.push_back(aColorAttr->value(1));
+      theColor.push_back(aColorAttr->value(2));
+    }
+  }
+}
+
+void getDefaultColor(ResultPtr theResult, AISObjectPtr thePrs, std::vector<int>& theColor)
+{
+  theColor.clear();
+  // get default color from the preferences manager for the given result
+  if (theColor.empty()) {
+    std::string aSection, aName, aDefault;
+    theResult->colorConfigInfo(aSection, aName, aDefault);
+    if (!aSection.empty() && !aName.empty()) {
+      theColor = Config_PropManager::color(aSection, aName, aDefault);
+    }
+  }
+  if (theColor.empty()) // all AIS objects, where the color is not set, a white.
+    // The color should be defined in XML or set in the attribute
+    theColor = Config_PropManager::color("Visualization", "object_default_color", "#ffffff");
+}
+
+bool XGUI_CustomPrs::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
+                                           std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
+{
+  std::vector<int> aColor;
+
+  getColor(theResult, aColor);
+  if (aColor.empty())
+    getDefaultColor(theResult, thePrs, aColor);
+
+  return !aColor.empty() && thePrs->setColor(aColor[0], aColor[1], aColor[2]);
+}
diff --git a/src/XGUI/XGUI_CustomPrs.h b/src/XGUI/XGUI_CustomPrs.h
new file mode 100644 (file)
index 0000000..97bc891
--- /dev/null
@@ -0,0 +1,29 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        XGUI_CustomPrs.hxx
+// Created:     10 Mar 2015
+// Author:      Natalia ERMOLAEVA
+
+#ifndef XGUI_CustomPrs_H
+#define XGUI_CustomPrs_H
+
+#include "XGUI.h"
+#include <GeomAPI_ICustomPrs.h>
+#include <GeomAPI_AISObject.h>
+#include <ModelAPI_Result.h>
+
+/**
+* Interface of a class which can provide specific customization of
+* object presentation
+*/ 
+class XGUI_CustomPrs : public GeomAPI_ICustomPrs
+{
+public:
+  XGUI_EXPORT virtual ~XGUI_CustomPrs() {};
+
+  /// Modifies the given presentation in the custom way.
+  virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
+                                     std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs);
+};
+
+#endif
index 88e8d599c3856ec43e16a4f2500976eecc6fd70e..7d4ae0012ba5db8b645726cedd4d3cc806ac92e1 100644 (file)
@@ -9,6 +9,7 @@
 #include "XGUI_ViewerProxy.h"
 #include "XGUI_SelectionMgr.h"
 #include "XGUI_Selection.h"
+#include "XGUI_CustomPrs.h"
 
 #include <AppElements_Viewer.h>
 
@@ -16,7 +17,7 @@
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Object.h>
 #include <ModelAPI_Tools.h>
-#include <ModelAPI_AttributeColor.h>
+#include <ModelAPI_AttributeIntArray.h>
 
 #include <ModuleBase_ResultPrs.h>
 
@@ -72,6 +73,7 @@ XGUI_Displayer::XGUI_Displayer(XGUI_Workshop* theWorkshop)
   : myWorkshop(theWorkshop)
 {
   enableUpdateViewer(true);
+  myCustomPrs = std::shared_ptr<GeomAPI_ICustomPrs>(new XGUI_CustomPrs());
 }
 
 XGUI_Displayer::~XGUI_Displayer()
@@ -159,7 +161,10 @@ void XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS,
 
     aContext->SetDisplayMode(anAISIO, isShading? Shading : Wireframe, false);
 
-    customizeObject(theObject);
+    bool isCustomized = customizeObject(theObject);
+    if (isCustomized)
+      aContext->Redisplay(anAISIO, false);
+
     if (aCanBeShaded) {
       openLocalContext();
       activateObjects(myActiveSelectionModes);
@@ -223,6 +228,7 @@ void XGUI_Displayer::redisplay(ObjectPtr theObject, bool isUpdateViewer)
     // before and after the values modification.
     // Moreother, this check avoids customize and redisplay presentation if the presentable
     // parameter is changed.
+    bool isEqualShapes = false;
     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
     if (aResult.get() != NULL) {
       Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aAISIO);
@@ -233,17 +239,17 @@ void XGUI_Displayer::redisplay(ObjectPtr theObject, bool isUpdateViewer)
           std::shared_ptr<GeomAPI_Shape> anAISShapePtr(new GeomAPI_Shape());
           anAISShapePtr->setImpl(new TopoDS_Shape(aShape));
 
-          if (aShapePtr->isEqual(anAISShapePtr))
-            return;
+          isEqualShapes = aShapePtr->isEqual(anAISShapePtr);
         }
       }
     }
     // Customization of presentation
-    customizeObject(theObject);
-
-    aContext->Redisplay(aAISIO, false);
-    if (isUpdateViewer)
-      updateViewer();
+    bool isCustomized = customizeObject(theObject);
+    if (!isEqualShapes || isCustomized) {
+      aContext->Redisplay(aAISIO, false);
+      if (isUpdateViewer)
+        updateViewer();
+    }
   }
 }
 
@@ -758,26 +764,26 @@ void XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO,
   }
 }
 
-void XGUI_Displayer::customizeObject(ObjectPtr theObject)
+bool XGUI_Displayer::customizeObject(ObjectPtr theObject)
 {
   AISObjectPtr anAISObj = getAISObject(theObject);
   // correct the result's color it it has the attribute
   ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
-  if (aResult.get() != NULL && aResult->data()->attribute(ModelAPI_Result::COLOR_ID()).get() != NULL) {
-    int aRed, aGreen, aBlue;
 
-    AttributeColorPtr aColorAttr = std::dynamic_pointer_cast<ModelAPI_AttributeColor>(
-                                              aResult->data()->attribute(ModelAPI_Result::COLOR_ID()));
-    aColorAttr->values(aRed, aGreen, aBlue);
-    anAISObj->setColor(aRed, aGreen, aBlue);
+  // Customization of presentation
+  GeomCustomPrsPtr aCustomPrs;
+  FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
+  if (aFeature.get() != NULL) {
+    GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
+    if (aCustPrs.get() != NULL)
+      aCustomPrs = aCustPrs;
   }
-  else {
-    // Customization of presentation
-    FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
-    if (aFeature.get() != NULL) {
-      GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
-      if (aCustPrs.get() != NULL)
-        aCustPrs->customisePresentation(anAISObj);
-    }
+  if (aCustomPrs.get() == NULL) {
+    // we ignore presentable not customized objects
+    GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
+    if (aPrs.get() != NULL)
+      return false;
+    aCustomPrs = myCustomPrs;
   }
+  return aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs);
 }
index e5ea6fd05d7995b7bf8d080aad56af2cc1512add..da11c4d8ef6f65ba1ca039fe7f9c208d41c92a43 100644 (file)
@@ -20,6 +20,8 @@
 #include <ModuleBase_Definitions.h>
 #include <ModuleBase_ViewerPrs.h>
 
+#include <GeomAPI_ICustomPrs.h>
+
 #include <SelectMgr_AndFilter.hxx>
 
 #include <QString>
@@ -218,8 +220,9 @@ class XGUI_EXPORT XGUI_Displayer
    * If the object is result with the color attribute value set, it is used,
    * otherwise the customize is applyed to the object's feature if it is a custom prs
    * \param theObject an object instance
+   * \return the true state if there is changes and the presentation is customized
    */
-  void customizeObject(ObjectPtr theObject);
+  bool customizeObject(ObjectPtr theObject);
 
  protected:
    /// Reference to workshop
@@ -228,6 +231,9 @@ class XGUI_EXPORT XGUI_Displayer
   /// A container for selection filters
   Handle(SelectMgr_AndFilter) myAndFilter;
 
+  /// A default custom presentation, which is used if the displayed feature is not a custom presentation
+  GeomCustomPrsPtr myCustomPrs;
+
   /// Definition of a type of map which defines correspondance between objects and presentations
   typedef QMap<ObjectPtr, AISObjectPtr> ResultToAISMap;
 
index 70b6c615654dee1e67bea0d7c5dc1f746c546d46..dc54367498b68b55918a8c871eed80dad398fe47 100644 (file)
@@ -39,6 +39,7 @@
 #include <ModelAPI_ResultGroup.h>
 #include <ModelAPI_ResultConstruction.h>
 #include <ModelAPI_ResultBody.h>
+#include <ModelAPI_AttributeIntArray.h>
 
 //#include <PartSetPlugin_Part.h>
 
 #include <QMenu>
 #include <QToolButton>
 #include <QAction>
+#include <QDialog>
+#include <QDialogButtonBox>
+#include <QHBoxLayout>
+#include <QtxColorButton.h>
 
 #ifdef _DEBUG
 #include <QDebug>
@@ -1335,7 +1340,6 @@ These features will be deleted also. Would you like to continue?")).arg(aNames),
       return;
   }
 
-  SessionPtr aMgr = ModelAPI_Session::get();
   QString aDescription = tr("Delete %1");
   QStringList aObjectNames;
   foreach (ObjectPtr aObj, theList) {
@@ -1344,6 +1348,7 @@ These features will be deleted also. Would you like to continue?")).arg(aNames),
     aObjectNames << QString::fromStdString(aObj->data()->name());
   }
   aDescription = aDescription.arg(aObjectNames.join(", "));
+  SessionPtr aMgr = ModelAPI_Session::get();
   aMgr->startOperation(aDescription.toStdString());
   std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
                                        aLast = aRefFeatures.end();
@@ -1404,40 +1409,38 @@ bool XGUI_Workshop::canChangeColor() const
 }
 
 //**************************************************************
-#include <QDialog>
-#include <QHBoxLayout>
-#include <QtxColorButton.h>
-#include <ModelAPI_AttributeColor.h>
 void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
 {
-  // 1. find the initial value of the color
-  AttributeColorPtr aColorAttr;
-  foreach(ObjectPtr anObj, theObjects) {
-    ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
-    if (aResult.get() != NULL) {
-      AttributePtr anAttr = aResult->data()->attribute(ModelAPI_Result::COLOR_ID());
-      if (anAttr.get() != NULL)
-        aColorAttr = std::dynamic_pointer_cast<ModelAPI_AttributeColor>(anAttr);
-    }
+  std::vector<int> aColor;
+  foreach(ObjectPtr anObject, theObjects) {
+
+    AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
+    aColor.resize(3);
+    anAISObj->getColor(aColor[0], aColor[1], aColor[2]);
+    if (!aColor.empty())
+      break;
   }
-  // there is no object with the color attribute
-  if (aColorAttr.get() == NULL)
+  if (aColor.size() != 3)
     return;
-  int aRed, aGreen, aBlue;
-  aColorAttr->values(aRed, aGreen, aBlue);
 
   // 2. show the dialog to change the value
-  QDialog aDlg;
-  QHBoxLayout* aLay = new QHBoxLayout(&aDlg);
+  QDialog* aDlg = new QDialog();
+  QVBoxLayout* aLay = new QVBoxLayout(aDlg);
+
+  QtxColorButton* aColorBtn = new QtxColorButton(aDlg);
+  aColorBtn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
 
-  QtxColorButton* aColorBtn = new QtxColorButton(&aDlg);
   aLay->addWidget(aColorBtn);
-  aColorBtn->setColor(QColor(aRed, aGreen, aBlue));
+  aColorBtn->setColor(QColor(aColor[0], aColor[1], aColor[2]));
 
-  QPoint aPoint = QCursor::pos();
-  aDlg.move(aPoint);
+  QDialogButtonBox* aButtons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
+                                                    Qt::Horizontal, aDlg);
+  connect(aButtons, SIGNAL(accepted()), aDlg, SLOT(accept()));
+  connect(aButtons, SIGNAL(rejected()), aDlg, SLOT(reject()));
+  aLay->addWidget(aButtons);
 
-  bool isDone = aDlg.exec() == QDialog::Accepted;
+  aDlg->move(QCursor::pos());
+  bool isDone = aDlg->exec() == QDialog::Accepted;
   if (!isDone)
     return;
 
@@ -1446,25 +1449,38 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
       aGreenResult = aColorResult.green(),
       aBlueResult = aColorResult.blue();
 
-  if (aRedResult == aRed && aGreenResult == aGreen && aBlueResult == aBlue)
+  if (aRedResult == aColor[0] && aGreenResult == aColor[1] && aBlueResult == aColor[2])
     return;
 
   // 3. abort the previous operation and start a new one
-  if(!isActiveOperationAborted())
-    return;
+  SessionPtr aMgr = ModelAPI_Session::get();
+  bool aWasOperation = aMgr->isOperation(); // keep this value
+  if (!aWasOperation) {
+    QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text();
+    aMgr->startOperation(aDescription.toStdString());
+  }
 
   // 4. set the value to all results
+  static Events_ID EVENT_DISP = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
+  AttributeIntArrayPtr aColorAttr;
   foreach(ObjectPtr anObj, theObjects) {
     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
     if (aResult.get() != NULL) {
-      AttributePtr anAttr = aResult->data()->attribute(ModelAPI_Result::COLOR_ID());
-      if (anAttr.get() != NULL) {
-        aColorAttr = std::dynamic_pointer_cast<ModelAPI_AttributeColor>(anAttr);
-        if (aColorAttr.get() != NULL)
-          aColorAttr->setValues(aRedResult, aGreenResult, aBlueResult);
+      aColorAttr = aResult->data()->intArray(ModelAPI_Result::COLOR_ID());
+      if (aColorAttr.get() != NULL) {
+        if (!aColorAttr->size()) {
+          aColorAttr->setSize(3);
+        }
+        aColorAttr->setValue(0, aRedResult);
+        aColorAttr->setValue(1, aGreenResult);
+        aColorAttr->setValue(2, aBlueResult);
+        ModelAPI_EventCreator::get()->sendUpdated(anObj, EVENT_DISP);
       }
     }
   }
+  if (!aWasOperation)
+    aMgr->finishOperation();
+  updateCommandStatus();
 }
 
 //**************************************************************