]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #805 In the sketch presentation, show both the parameter and its value: dimensi...
authornds <nds@opencascade.com>
Thu, 31 Mar 2016 12:32:05 +0000 (15:32 +0300)
committernds <nds@opencascade.com>
Thu, 31 Mar 2016 12:32:05 +0000 (15:32 +0300)
src/SketcherPrs/CMakeLists.txt
src/SketcherPrs/SketcherPrs_DimensionStyleListener.cpp [new file with mode: 0755]
src/SketcherPrs/SketcherPrs_DimensionStyleListener.h [new file with mode: 0755]
src/SketcherPrs/SketcherPrs_LengthDimension.cpp
src/SketcherPrs/SketcherPrs_LengthDimension.h

index acdb1d7eef9cb9039b32812a10239499c6a204ad..e060ad3254c7bada4d6751ec8fe7555939f0c2a8 100644 (file)
@@ -9,6 +9,7 @@ SET(PROJECT_HEADERS
     SketcherPrs.h
     SketcherPrs_Coincident.h
     SketcherPrs_Collinear.h
+    SketcherPrs_DimensionStyleListener.h
     SketcherPrs_Factory.h
     SketcherPrs_Parallel.h
     SketcherPrs_Tools.h
@@ -32,6 +33,7 @@ SET(PROJECT_HEADERS
 SET(PROJECT_SOURCES
     SketcherPrs_Coincident.cpp
     SketcherPrs_Collinear.cpp
+    SketcherPrs_DimensionStyleListener.cpp
     SketcherPrs_Factory.cpp
     SketcherPrs_Parallel.cpp
     SketcherPrs_Tools.cpp
diff --git a/src/SketcherPrs/SketcherPrs_DimensionStyleListener.cpp b/src/SketcherPrs/SketcherPrs_DimensionStyleListener.cpp
new file mode 100755 (executable)
index 0000000..ffb2a8d
--- /dev/null
@@ -0,0 +1,53 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        SketcherPrs_DimensionStyleListener.cpp
+// Created:     31 March 2016
+// Author:      Natalia ERMOLAEVA
+
+#include "SketcherPrs_DimensionStyleListener.h"
+#include "SketcherPrs_Tools.h"
+
+#include <Events_Error.h>
+#include <Events_Loop.h>
+
+SketcherPrs_DimensionStyleListener::SketcherPrs_DimensionStyleListener()
+{
+  Events_Loop* aLoop = Events_Loop::loop();
+  const Events_ID kDocCreatedEvent =
+                SketcherPrs_ParameterStyleMessage::eventId();
+  aLoop->registerListener(this, kDocCreatedEvent, NULL, false);
+}
+
+SketcherPrs_DimensionStyleListener::~SketcherPrs_DimensionStyleListener()
+{
+  Events_Loop* aLoop = Events_Loop::loop();
+  aLoop->removeListener(this);
+}
+
+void SketcherPrs_DimensionStyleListener::processEvent(const std::shared_ptr<Events_Message>& theMessage)
+{
+  const Events_ID kParameterStyleEvent = SketcherPrs_ParameterStyleMessage::eventId();
+  if (theMessage->eventID() == kParameterStyleEvent) {
+    std::shared_ptr<SketcherPrs_ParameterStyleMessage> aMessage = std::dynamic_pointer_cast<
+                                            SketcherPrs_ParameterStyleMessage>(theMessage);
+    myStyle = aMessage->style();
+  }
+}
+
+void SketcherPrs_DimensionStyleListener::updateDimensions(AIS_Dimension* theDimension,
+                                        const AttributeDoublePtr& theAttributeValue)
+{
+  if (!theDimension || !theAttributeValue.get())
+    return;
+
+  bool aHasParameters = theAttributeValue->usedParameters().size() > 0;
+  if (aHasParameters) {
+    bool isParameterValueStyle = myStyle == SketcherPrs_ParameterStyleMessage::ParameterValue;
+    SketcherPrs_Tools::setDisplaySpecialSymbol(theDimension, isParameterValueStyle);
+    SketcherPrs_Tools::setDisplayParameter(theDimension, theAttributeValue->text(), !isParameterValueStyle);
+  }
+  else {
+    SketcherPrs_Tools::setDisplaySpecialSymbol(theDimension, false);
+    SketcherPrs_Tools::setDisplayParameter(theDimension, theAttributeValue->text(), false);
+  }
+}
diff --git a/src/SketcherPrs/SketcherPrs_DimensionStyleListener.h b/src/SketcherPrs/SketcherPrs_DimensionStyleListener.h
new file mode 100755 (executable)
index 0000000..03e9295
--- /dev/null
@@ -0,0 +1,47 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        SketcherPrs_DimensionStyleListener.h
+// Created:     31 March 2016
+// Author:      Natalia ERMOLAEVA
+
+#ifndef SketcherPrs_DimensionStyleListener_H
+#define SketcherPrs_DimensionStyleListener_H
+
+#include <Events_Listener.h>
+
+#include <ModelAPI_AttributeDouble.h>
+
+#include "SketcherPrs_Tools.h"
+
+#include <Standard.hxx>
+
+/**
+* \ingroup GUI
+* A class for representation of linear dimension constraint.
+* It supports SketchPlugin_ConstraintLength and SketchPlugin_ConstraintDistance features.
+*/
+class SketcherPrs_DimensionStyleListener : public Events_Listener
+{
+public:
+  /// Constructor
+  /// \param theConstraint a constraint feature
+  /// \param thePlane a coordinate plane of current sketch
+  Standard_EXPORT SketcherPrs_DimensionStyleListener();
+
+  /// Destructor
+  Standard_EXPORT ~SketcherPrs_DimensionStyleListener();
+
+  /// Process the ModelAPI_DocumentCreatedMessage to fulfill a document
+  /// from the message with origin and planes
+  virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
+
+  /// Redefinition of virtual function
+  Standard_EXPORT void updateDimensions(AIS_Dimension* theDimension,
+                                        const AttributeDoublePtr& theAttributeValue);
+
+private:
+  /// Style how the parameter of dimension should be visualized
+  SketcherPrs_ParameterStyleMessage::ParameterStyle myStyle;
+};
+
+#endif
\ No newline at end of file
index 0ec0382e49a01bbdb995b6f679bd6aeef76dd035..a61a6cb4005e63675f80f76cf74b451777de55ab 100644 (file)
@@ -15,6 +15,7 @@
 #include <SketchPlugin_Circle.h>
 
 #include <SketcherPrs_Tools.h>
+#include <SketcherPrs_DimensionStyleListener.h>
 
 #include <Events_Error.h>
 #include <Events_Loop.h>
@@ -55,26 +56,12 @@ SketcherPrs_LengthDimension::SketcherPrs_LengthDimension(ModelAPI_Feature* theCo
   SetSelToleranceForText2d(SketcherPrs_Tools::getTextHeight());
   SetDimensionAspect(myAspect);
 
-  Events_Loop* aLoop = Events_Loop::loop();
-  const Events_ID kDocCreatedEvent =
-                SketcherPrs_ParameterStyleMessage::eventId();
-  aLoop->registerListener(this, kDocCreatedEvent, NULL, false);
+  myStyleListener = new SketcherPrs_DimensionStyleListener();
 }
 
 SketcherPrs_LengthDimension::~SketcherPrs_LengthDimension()
 {
-  Events_Loop* aLoop = Events_Loop::loop();
-  aLoop->removeListener(this);
-}
-
-void SketcherPrs_LengthDimension::processEvent(const std::shared_ptr<Events_Message>& theMessage)
-{
-  const Events_ID kParameterStyleEvent = SketcherPrs_ParameterStyleMessage::eventId();
-  if (theMessage->eventID() == kParameterStyleEvent) {
-    std::shared_ptr<SketcherPrs_ParameterStyleMessage> aMessage = std::dynamic_pointer_cast<
-                                            SketcherPrs_ParameterStyleMessage>(theMessage);
-    myStyle = aMessage->style();
-  }
+  delete myStyleListener;
 }
 
 bool SketcherPrs_LengthDimension::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
@@ -126,16 +113,9 @@ void SketcherPrs_LengthDimension::Compute(const Handle(PrsMgr_PresentationManage
   myAspect->TextAspect()->SetVerticalJustification(Graphic3d_VTA_CENTER);
 
   AttributeDoublePtr aValue = myConstraint->data()->real(SketchPlugin_Constraint::VALUE());
-  bool aHasParameters = aValue->usedParameters().size() > 0;
-  if (aHasParameters) {
-    bool isParameterValueStyle = myStyle == SketcherPrs_ParameterStyleMessage::ParameterValue;
-    SketcherPrs_Tools::setDisplaySpecialSymbol(this, isParameterValueStyle);
-    SketcherPrs_Tools::setDisplayParameter(this, aValue->text(), !isParameterValueStyle);
-  }
-  else {
-    SketcherPrs_Tools::setDisplaySpecialSymbol(this, false);
-    SketcherPrs_Tools::setDisplayParameter(this, aValue->text(), false);
-  }
+
+  myStyleListener->updateDimensions(this, aValue);
+
   AIS_LengthDimension::Compute(thePresentationManager, thePresentation, theMode);
 }
 
index c0716bc5825c8802fb4a4c339e827b8b1158c165..59d302ae52d1660d526bbd3032823f3da481c19d 100644 (file)
@@ -15,8 +15,7 @@
 
 #include <SketcherPrs_Tools.h>
 
-#include <Events_Listener.h>
-
+class SketcherPrs_DimensionStyleListener;
 
 DEFINE_STANDARD_HANDLE(SketcherPrs_LengthDimension, AIS_LengthDimension)
 
@@ -25,7 +24,7 @@ DEFINE_STANDARD_HANDLE(SketcherPrs_LengthDimension, AIS_LengthDimension)
 * A class for representation of linear dimension constraint.
 * It supports SketchPlugin_ConstraintLength and SketchPlugin_ConstraintDistance features.
 */
-class SketcherPrs_LengthDimension : public AIS_LengthDimension, public Events_Listener
+class SketcherPrs_LengthDimension : public AIS_LengthDimension
 {
 public:
   /// Constructor
@@ -39,10 +38,6 @@ public:
 
   DEFINE_STANDARD_RTTI(SketcherPrs_LengthDimension)
 
-  /// Process the ModelAPI_DocumentCreatedMessage to fulfill a document
-  /// from the message with origin and planes
-  virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
-
   /// Returns true if the constraint feature arguments are correcly filled to build AIS presentation
   /// \param theConstraint a constraint feature
   /// \param thePlane a coordinate plane of current sketch
@@ -71,8 +66,8 @@ private:
 
   Handle(Prs3d_DimensionAspect) myAspect;
 
-  /// Style how the parameter of dimension should be visualized
-  SketcherPrs_ParameterStyleMessage::ParameterStyle myStyle;
+  /// Listener to update dimension visualization style
+  SketcherPrs_DimensionStyleListener* myStyleListener;
 };
 
 #endif
\ No newline at end of file