]> OCCT Git - occt-copy.git/commitdiff
patch of 0028850: Visualization - Length dimension along Horizontal/Vertical axes NewGEOM_2.8.0
authornds <nds@opencascade.com>
Wed, 20 Sep 2017 11:45:10 +0000 (14:45 +0300)
committernds <nds@opencascade.com>
Wed, 20 Sep 2017 11:45:10 +0000 (14:45 +0300)
src/AIS/AIS_Dimension.cxx
src/AIS/AIS_Dimension.hxx
src/AIS/AIS_LengthDimension.cxx
src/AIS/AIS_LengthDimension.hxx

index 204c3296cddbaf61a97bac78352774b4a82c157b..dbfc898d30c5bc2a38bcfa881e913c3bc55dcf3a 100755 (executable)
@@ -691,21 +691,9 @@ void AIS_Dimension::DrawLinearDimension (const Handle(Prs3d_Presentation)& thePr
   FitTextAlignmentForLinear (theFirstPoint, theSecondPoint, theIsOneSide, aHorisontalTextPos,
                              aLabelPosition, isArrowsExternal);
 
-    // compute dimension line points
-  gp_Ax1 aPlaneNormal = GetPlane().Axis();
-  gp_Dir aTargetPointsVector = gce_MakeDir (theFirstPoint, theSecondPoint);
-
-  // compute flyout direction vector
-  gp_Dir aFlyoutVector = aPlaneNormal.Direction() ^ aTargetPointsVector;
-
-  // create lines for layouts
-  gp_Lin aLine1 (theFirstPoint, aFlyoutVector);
-  gp_Lin aLine2 (theSecondPoint, aFlyoutVector);
-
-  // Get flyout end points
-  gp_Pnt aLineBegPoint = ElCLib::Value (ElCLib::Parameter (aLine1, theFirstPoint)  + GetFlyout(), aLine1);
-  gp_Pnt aLineEndPoint = ElCLib::Value (ElCLib::Parameter (aLine2, theSecondPoint) + GetFlyout(), aLine2);
-
+  // compute dimension line points
+  gp_Pnt aLineBegPoint, aLineEndPoint;
+  ComputeFlyoutLinePoints (theFirstPoint, theSecondPoint, aLineBegPoint, aLineEndPoint);
   gp_Lin aDimensionLine = gce_MakeLin (aLineBegPoint, aLineEndPoint);
 
   // compute arrows positions and directions
@@ -996,6 +984,27 @@ void AIS_Dimension::DrawLinearDimension (const Handle(Prs3d_Presentation)& thePr
   mySelectionGeom.IsComputed = Standard_True;
 }
 
+//=======================================================================
+//function : ComputeFlyoutLinePoints
+//purpose  :
+//=======================================================================
+void AIS_Dimension::ComputeFlyoutLinePoints (const gp_Pnt& theFirstPoint, const gp_Pnt& theSecondPoint,
+                                             gp_Pnt& theLineBegPoint, gp_Pnt& theLineEndPoint)
+{
+  // compute dimension line points
+  gp_Ax1 aPlaneNormal = GetPlane().Axis();
+  // compute flyout direction vector
+  gp_Dir aTargetPointsVector = gce_MakeDir (theFirstPoint, theSecondPoint);
+  gp_Dir aFlyoutVector = aPlaneNormal.Direction() ^ aTargetPointsVector;
+  // create lines for layouts
+  gp_Lin aLine1 (theFirstPoint, aFlyoutVector);
+  gp_Lin aLine2 (theSecondPoint, aFlyoutVector);
+
+  // Get flyout end points
+  theLineBegPoint = ElCLib::Value (ElCLib::Parameter (aLine1, theFirstPoint)  + GetFlyout(), aLine1);
+  theLineEndPoint = ElCLib::Value (ElCLib::Parameter (aLine2, theSecondPoint) + GetFlyout(), aLine2);
+}
+
 //=======================================================================
 //function : ComputeLinearFlyouts
 //purpose  :
index 498eaa04dbc4e3f4031505485800ef07fb058683..13cea1363214a62fcbbd42bca71023abd4445f2a 100755 (executable)
@@ -463,6 +463,14 @@ protected:
                                             const gp_Pnt& theSecondPoint,
                                             const Standard_Boolean theIsOneSide = Standard_False);
 
+  //! Computes points bounded the flyout line for linear dimension.
+  //! @param theFirstPoint [in] the first attach point of linear dimension.
+  //! @param theSecondPoint [in] the second attach point of linear dimension.
+  //! @param theLineBegPoint [out] the first attach point of linear dimension.
+  //! @param theLineEndPoint [out] the second attach point of linear dimension.
+  Standard_EXPORT virtual void ComputeFlyoutLinePoints (const gp_Pnt& theFirstPoint, const gp_Pnt& theSecondPoint,
+                                                        gp_Pnt& theLineBegPoint, gp_Pnt& theLineEndPoint);
+
   //! Compute selection sensitives for linear dimension flyout lines (length, diameter, radius).
   //! Please note that this method uses base dimension properties: working plane and flyout length.
   //! @param theSelection [in] the selection structure to fill with selection primitives.
index cd35bf31759421c072f063f8ccdf27c2e5ca67a8..af2f23589de8b7126d0fff01e82c886fba4a5175 100755 (executable)
@@ -44,7 +44,8 @@ IMPLEMENT_STANDARD_RTTIEXT(AIS_LengthDimension,AIS_Dimension)
 //=======================================================================
 AIS_LengthDimension::AIS_LengthDimension (const TopoDS_Face& theFirstFace,
                                           const TopoDS_Face& theSecondFace)
-: AIS_Dimension (AIS_KOD_LENGTH)
+: AIS_Dimension (AIS_KOD_LENGTH),
+  myHasCustomDirection (Standard_False)
 {
   SetMeasuredGeometry (theFirstFace, theSecondFace);
   SetFlyout (15.0);
@@ -56,7 +57,8 @@ AIS_LengthDimension::AIS_LengthDimension (const TopoDS_Face& theFirstFace,
 //=======================================================================
 AIS_LengthDimension::AIS_LengthDimension (const TopoDS_Face& theFace,
                                           const TopoDS_Edge& theEdge)
-: AIS_Dimension (AIS_KOD_LENGTH)
+: AIS_Dimension (AIS_KOD_LENGTH),
+  myHasCustomDirection (Standard_False)
 {
   SetMeasuredGeometry (theFace, theEdge);
   SetFlyout (15.0);
@@ -69,7 +71,8 @@ AIS_LengthDimension::AIS_LengthDimension (const TopoDS_Face& theFace,
 AIS_LengthDimension::AIS_LengthDimension (const gp_Pnt& theFirstPoint,
                                           const gp_Pnt& theSecondPoint,
                                           const gp_Pln& thePlane)
-: AIS_Dimension (AIS_KOD_LENGTH)
+: AIS_Dimension (AIS_KOD_LENGTH),
+  myHasCustomDirection (Standard_False)
 {
   SetMeasuredGeometry (theFirstPoint, theSecondPoint, thePlane);
   SetFlyout (15.0);
@@ -82,7 +85,8 @@ AIS_LengthDimension::AIS_LengthDimension (const gp_Pnt& theFirstPoint,
 AIS_LengthDimension::AIS_LengthDimension (const TopoDS_Shape& theFirstShape,
                                           const TopoDS_Shape& theSecondShape,
                                           const gp_Pln& thePlane)
-: AIS_Dimension (AIS_KOD_LENGTH)
+: AIS_Dimension (AIS_KOD_LENGTH),
+  myHasCustomDirection (Standard_False)
 {
   SetCustomPlane (thePlane);
   SetMeasuredShapes (theFirstShape, theSecondShape);
@@ -95,7 +99,8 @@ AIS_LengthDimension::AIS_LengthDimension (const TopoDS_Shape& theFirstShape,
 //=======================================================================
 AIS_LengthDimension::AIS_LengthDimension (const TopoDS_Edge& theEdge,
                                           const gp_Pln& thePlane)
-: AIS_Dimension (AIS_KOD_LENGTH)
+: AIS_Dimension (AIS_KOD_LENGTH),
+  myHasCustomDirection (Standard_False)
 {
   SetMeasuredGeometry (theEdge, thePlane);
   SetFlyout (15.0);
@@ -261,7 +266,13 @@ void AIS_LengthDimension::SetDisplayUnits (const TCollection_AsciiString& theUni
 //=======================================================================
 Standard_Real AIS_LengthDimension::ComputeValue() const
 {
-  return IsValid() ? myFirstPoint.Distance (mySecondPoint) : 0.0;
+  if (!IsValid())
+    return 0.0;
+
+  if (!myHasCustomDirection)
+    return myFirstPoint.Distance (mySecondPoint);
+
+  return fabs (gp_Vec(myFirstPoint, mySecondPoint).Dot (myDirection));
 }
 
 //=======================================================================
@@ -282,6 +293,35 @@ void AIS_LengthDimension::Compute (const Handle(PrsMgr_PresentationManager3d)& /
   DrawLinearDimension (thePresentation, theMode, myFirstPoint, mySecondPoint);
 }
 
+ //=======================================================================
+//function : ComputeFlyoutLinePoints
+//purpose  : 
+//=======================================================================
+void AIS_LengthDimension::ComputeFlyoutLinePoints (const gp_Pnt& theFirstPoint, const gp_Pnt& theSecondPoint,
+                                                   gp_Pnt& theLineBegPoint, gp_Pnt& theLineEndPoint)
+{
+  if (!myHasCustomDirection)
+  {
+    AIS_Dimension::ComputeFlyoutLinePoints (theFirstPoint, theSecondPoint, theLineBegPoint, theLineEndPoint);
+    return;
+  }
+
+  // find scalar of projection target vector (from start to second point) to flyout vector
+  gp_Ax1 aPlaneNormal = GetPlane().Axis();
+  gp_Vec aFlyoutNormalizedDir(aPlaneNormal.Direction() ^ myDirection);
+  aFlyoutNormalizedDir.Normalize();
+  Standard_Real aTargetProjectedToFlyout = gp_Vec(theFirstPoint, theSecondPoint).Dot (aFlyoutNormalizedDir);
+
+  gp_Dir aFlyoutVector = aFlyoutNormalizedDir;
+  // create lines for layouts
+  gp_Lin aLine1 (theFirstPoint, aFlyoutVector);
+  gp_Lin aLine2 (theSecondPoint, aFlyoutVector);
+
+  // Get flyout end points
+  theLineBegPoint = ElCLib::Value (ElCLib::Parameter (aLine1, theFirstPoint)  + GetFlyout() + aTargetProjectedToFlyout, aLine1);
+  theLineEndPoint = ElCLib::Value (ElCLib::Parameter (aLine2, theSecondPoint) + GetFlyout(), aLine2);
+}
+
 //=======================================================================
 //function : ComputeFlyoutSelection
 //purpose  : 
@@ -773,3 +813,14 @@ void AIS_LengthDimension::SetTextPosition (const gp_Pnt& theTextPos)
 
   SetToUpdate();
 }
+
+//=======================================================================
+//function : SetDirection
+//purpose  : 
+//=======================================================================
+void AIS_LengthDimension::SetDirection (const gp_Dir& theDirection, const Standard_Boolean theUseDirection)
+{
+  myHasCustomDirection = theUseDirection;
+  if (myHasCustomDirection)
+    myDirection = theDirection;
+}
index c5cbfce2ae6a870f9648ca6e399448c04da6c13f..867fe7257e3074f3a33278ee4187d4aaec42220a 100755 (executable)
@@ -194,6 +194,13 @@ public:
 
   Standard_EXPORT virtual const gp_Pnt GetTextPosition() const Standard_OVERRIDE;
 
+  //! Set custom direction for dimension. If it is not set, the direction is obtained
+  //! from the measured geometry (e.g. line between points of dimension)
+  //! The direction does not change flyout direction of dimension.
+  //! @param theDirection [in] the dimension direction.
+  //! @param theUseDirection [in] boolean value if custom direction should be used.
+  Standard_EXPORT void SetDirection (const gp_Dir& theDirection, const Standard_Boolean theUseDirection = Standard_True);
+
 public:
 
   DEFINE_STANDARD_RTTIEXT(AIS_LengthDimension,AIS_Dimension)
@@ -205,12 +212,25 @@ protected:
 
   Standard_EXPORT virtual gp_Pln ComputePlane(const gp_Dir& theAttachDir) const;
 
+  //! Computes distance between dimension points. If custom direction is defined, the distance
+  //! is a projection value of the distance between points to this direction
+  //! @return dimension value
   Standard_EXPORT Standard_Real ComputeValue() const Standard_OVERRIDE;
 
   Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
                                         const Handle(Prs3d_Presentation)& thePresentation,
                                         const Standard_Integer theMode = 0) Standard_OVERRIDE;
 
+  //! Computes points bounded the flyout line for linear dimension.
+  //! Direction of flyout line equal to the custom direction of dimension if defined or
+  //! parallel to the main direction line
+  //! @param theFirstPoint [in] the first attach point of linear dimension.
+  //! @param theSecondPoint [in] the second attach point of linear dimension.
+  //! @param theLineBegPoint [out] the first attach point of linear dimension.
+  //! @param theLineEndPoint [out] the second attach point of linear dimension.
+  Standard_EXPORT virtual void ComputeFlyoutLinePoints (const gp_Pnt& theFirstPoint, const gp_Pnt& theSecondPoint,
+                                                        gp_Pnt& theLineBegPoint, gp_Pnt& theLineEndPoint) Standard_OVERRIDE;
+
   Standard_EXPORT virtual void ComputeFlyoutSelection (const Handle(SelectMgr_Selection)& theSelection,
                                                        const Handle(SelectMgr_EntityOwner)& theEntityOwner) Standard_OVERRIDE;
 
@@ -263,6 +283,8 @@ private:
   gp_Pnt mySecondPoint;
   TopoDS_Shape myFirstShape;
   TopoDS_Shape mySecondShape;
+  gp_Dir myDirection;
+  Standard_Boolean myHasCustomDirection;
 };
 
 #endif // _AIS_LengthDimension_HeaderFile