// Created on: 1996-12-05
// Created by: Jean-Pierre COMBE/Odile Olivier/Serguei Zaritchny
// Copyright (c) 1996-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
+// Copyright (c) 1999-2014 OPEN CASCADE SAS
//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
+// This file is part of Open CASCADE Technology software library.
//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-#include <Standard_NotImplemented.hxx>
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
#include <AIS_RadiusDimension.hxx>
#include <AIS.hxx>
-#include <AIS_Drawer.hxx>
-#include <AIS_KindOfDimension.hxx>
-#include <Adaptor3d_HCurve.hxx>
-#include <BRep_Tool.hxx>
-#include <BRepAdaptor_Surface.hxx>
-#include <BRepAdaptor_Curve.hxx>
-#include <DsgPrs.hxx>
+#include <BRepLib_MakeEdge.hxx>
#include <ElCLib.hxx>
-#include <GC_MakeCircle.hxx>
-#include <gce_MakeCirc.hxx>
#include <gce_MakeDir.hxx>
-#include <gce_MakeLin.hxx>
-#include <Geom_Surface.hxx>
-#include <Geom_Plane.hxx>
-#include <Geom_Circle.hxx>
-#include <Geom_Curve.hxx>
-#include <Geom_TrimmedCurve.hxx>
-#include <Geom_ToroidalSurface.hxx>
-#include <Geom_CylindricalSurface.hxx>
-#include <Geom_SurfaceOfLinearExtrusion.hxx>
-#include <gp_Circ.hxx>
-#include <gp_Pnt.hxx>
-#include <gp_Trsf.hxx>
-#include <Graphic3d_ArrayOfSegments.hxx>
-#include <Graphic3d_Group.hxx>
-#include <Precision.hxx>
-#include <PrsMgr_PresentationManager3d.hxx>
-#include <Prs3d_DimensionAspect.hxx>
-#include <Prs3d_ArrowAspect.hxx>
-#include <Prs3d_Drawer.hxx>
-#include <Prs3d_Root.hxx>
-#include <TCollection_AsciiString.hxx>
-#include <TCollection_ExtendedString.hxx>
-#include <TopExp_Explorer.hxx>
-#include <TopAbs_ShapeEnum.hxx>
-#include <TopoDS.hxx>
-#include <TopoDS_Face.hxx>
-#include <TopoDS_Wire.hxx>
-#include <TopoDS_Edge.hxx>
-#include <TopoDS_Vertex.hxx>
-#include <TopLoc_Location.hxx>
-
-IMPLEMENT_STANDARD_HANDLE(AIS_RadiusDimension, AIS_Dimension)
-IMPLEMENT_STANDARD_RTTIEXT(AIS_RadiusDimension, AIS_Dimension)
+
+
+IMPLEMENT_STANDARD_RTTIEXT(AIS_RadiusDimension,AIS_Dimension)
+
+namespace
+{
+ static const Standard_ExtCharacter THE_RADIUS_SYMBOL ('R');
+}
//=======================================================================
//function : Constructor
//purpose :
//=======================================================================
-
AIS_RadiusDimension::AIS_RadiusDimension (const gp_Circ& theCircle)
-: AIS_Dimension(),
- myFlyout (0.0),
- myCircle (theCircle)
+: AIS_Dimension (AIS_KOD_RADIUS)
{
- myFirstPoint = ElCLib::Value(0, myCircle);
- mySecondPoint = theCircle.Location();
- myIsInitialized = Standard_True;
- SetSpecialSymbol ('R');
+ SetMeasuredGeometry (theCircle);
+ SetSpecialSymbol (THE_RADIUS_SYMBOL);
SetDisplaySpecialSymbol (AIS_DSS_Before);
- SetKindOfDimension(AIS_KOD_RADIUS);
+ SetFlyout (0.0);
}
+//=======================================================================
+//function : Constructor
+//purpose :
+//=======================================================================
AIS_RadiusDimension::AIS_RadiusDimension (const gp_Circ& theCircle,
const gp_Pnt& theAttachPoint)
-: AIS_Dimension(),
- myFlyout (0.0),
- myCircle (theCircle)
+: AIS_Dimension (AIS_KOD_RADIUS)
{
- myFirstPoint = theAttachPoint;
- mySecondPoint = theCircle.Location();
- myIsInitialized = Standard_True;
- SetSpecialSymbol ('R');
+ SetMeasuredGeometry (theCircle, theAttachPoint);
+ SetSpecialSymbol (THE_RADIUS_SYMBOL);
SetDisplaySpecialSymbol (AIS_DSS_Before);
- SetKindOfDimension (AIS_KOD_RADIUS);
+ SetFlyout (0.0);
}
//=======================================================================
//function : Constructor
//purpose :
//=======================================================================
-
AIS_RadiusDimension::AIS_RadiusDimension (const TopoDS_Shape& theShape)
-: AIS_Dimension (),
- myFlyout (0.0)
+: AIS_Dimension (AIS_KOD_RADIUS)
{
- myFirstShape = theShape;
- myIsInitialized = Standard_False;
- SetSpecialSymbol ('R');
+ SetMeasuredGeometry (theShape);
+ SetSpecialSymbol (THE_RADIUS_SYMBOL);
SetDisplaySpecialSymbol (AIS_DSS_Before);
- SetKindOfDimension (AIS_KOD_RADIUS);
+ SetFlyout (0.0);
}
//=======================================================================
-//function : Constructor
+//function : SetMeasuredGeometry
//purpose :
//=======================================================================
+void AIS_RadiusDimension::SetMeasuredGeometry (const gp_Circ& theCircle)
+{
+ myCircle = theCircle;
+ myGeometryType = GeometryType_Edge;
+ myShape = BRepLib_MakeEdge (theCircle);
+ myAnchorPoint = ElCLib::Value (0, myCircle);
+ myIsGeometryValid = IsValidCircle (myCircle);
-AIS_RadiusDimension::AIS_RadiusDimension (const gp_Circ& theCircle,
- const Handle(Prs3d_DimensionAspect)& theDimensionAspect,
- const Standard_Real theExtensionSize/* = 1.0*/)
+ if (myIsGeometryValid)
+ {
+ ComputePlane();
+ }
-: AIS_Dimension (theDimensionAspect,theExtensionSize),
- myFlyout (0.0),
- myCircle (theCircle)
-{
- myFirstPoint = ElCLib::Value(0, myCircle);
- mySecondPoint = theCircle.Location();
- SetSpecialSymbol ('R');
- SetDisplaySpecialSymbol (AIS_DSS_Before);
- SetKindOfDimension (AIS_KOD_RADIUS);
+ SetToUpdate();
}
//=======================================================================
-//function : Constructor
+//function : SetMeasuredGeometry
//purpose :
//=======================================================================
-
-AIS_RadiusDimension::AIS_RadiusDimension (const gp_Circ& theCircle,
- const gp_Pnt& theAttachPoint,
- const Handle(Prs3d_DimensionAspect)& theDimensionAspect,
- const Standard_Real theExtensionSize/* = 1.0*/)
-: AIS_Dimension (theDimensionAspect,theExtensionSize),
- myFlyout (0.0),
- myCircle (theCircle)
+void AIS_RadiusDimension::SetMeasuredGeometry (const gp_Circ& theCircle,
+ const gp_Pnt& theAnchorPoint)
{
- myFirstPoint = theAttachPoint;
- mySecondPoint = theCircle.Location();
- SetSpecialSymbol ('R');
- SetDisplaySpecialSymbol (AIS_DSS_Before);
- SetKindOfDimension (AIS_KOD_RADIUS);
+ myCircle = theCircle;
+ myGeometryType = GeometryType_Edge;
+ myShape = BRepLib_MakeEdge (theCircle);
+ myAnchorPoint = theAnchorPoint;
+ myIsGeometryValid = IsValidCircle (myCircle) && IsValidAnchor (myCircle, theAnchorPoint);
+
+ if (myIsGeometryValid)
+ {
+ ComputePlane();
+ }
+
+ SetToUpdate();
}
//=======================================================================
-//function : Compute
+//function : SetMeasuredGeometry
//purpose :
//=======================================================================
-
-void AIS_RadiusDimension::Compute(const Handle(PrsMgr_PresentationManager3d)& /*thePM*/,
- const Handle(Prs3d_Presentation)& thePresentation,
- const Standard_Integer theMode)
+void AIS_RadiusDimension::SetMeasuredGeometry (const TopoDS_Shape& theShape)
{
- thePresentation->Clear();
-
- Handle(Prs3d_DimensionAspect) aDimensionAspect = myDrawer->DimensionAspect();
- Prs3d_Root::CurrentGroup (thePresentation)->SetPrimitivesAspect (aDimensionAspect->LineAspect()->Aspect());
+ Standard_Boolean isClosed = Standard_False;
+ myShape = theShape;
+ myGeometryType = GeometryType_UndefShapes;
+ myIsGeometryValid = InitCircularDimension (theShape, myCircle, myAnchorPoint, isClosed)
+ && IsValidCircle (myCircle);
- if (!myIsInitialized)
+ if (myIsGeometryValid)
{
- gp_Pnt aLastPoint;
- if (!initCircularDimension (myFirstShape, myCircle,
- myFirstPoint, aLastPoint))
- return;
- else
- {
- mySecondPoint = myCircle.Location();
- myIsInitialized = Standard_True;
- }
+ ComputePlane();
}
- if (!myIsWorkingPlaneCustom)
- countDefaultPlane();
-
- //Count flyout direction
- gp_Ax1 aWorkingPlaneNormal = GetWorkingPlane().Axis();
- gp_Dir aTargetPointsVector = gce_MakeDir (myFirstPoint, mySecondPoint);
- // Count a flyout direction vector.
- gp_Dir aFlyoutVector = aWorkingPlaneNormal.Direction()^aTargetPointsVector;
- gp_Ax3 aLocalSystem (myFirstPoint, aTargetPointsVector, aFlyoutVector);
-
- // Create lines for layouts
- gp_Lin aLine1 (myFirstPoint, aFlyoutVector);
- gp_Lin aLine2 (mySecondPoint, aFlyoutVector);
-
- // Get flyout end points
- gp_Pnt aFlyoutEnd1 = ElCLib::Value (ElCLib::Parameter (aLine1, myFirstPoint) + GetFlyout(), aLine1);
- gp_Pnt aFlyoutEnd2 = ElCLib::Value (ElCLib::Parameter (aLine2, mySecondPoint) + GetFlyout(), aLine2);
-
- // Add layout lines to graphic group
- // Common to all type of dimension placement.
- if (theMode == 0)
- {
- Handle(Graphic3d_ArrayOfSegments) aPrimSegments = new Graphic3d_ArrayOfSegments(4);
- aPrimSegments->AddVertex (myFirstPoint);
- aPrimSegments->AddVertex (aFlyoutEnd1);
- aPrimSegments->AddVertex (mySecondPoint);
- aPrimSegments->AddVertex (aFlyoutEnd2);
+ SetToUpdate();
+}
- Prs3d_Root::CurrentGroup (thePresentation)->AddPrimitiveArray (aPrimSegments);
+//=======================================================================
+//function : CheckPlane
+//purpose :
+//=======================================================================
+Standard_Boolean AIS_RadiusDimension::CheckPlane (const gp_Pln& thePlane) const
+{
+ // Check if anchor point and circle center point belong to plane.
+ if (!thePlane.Contains (myAnchorPoint, Precision::Confusion()) &&
+ !thePlane.Contains (myCircle.Location(), Precision::Confusion()))
+ {
+ return Standard_False;
}
- drawLinearDimension (thePresentation, aFlyoutEnd1, aFlyoutEnd2, (AIS_DimensionDisplayMode)theMode, Standard_True);
+ return Standard_True;
}
//=======================================================================
-//function : computeValue
+//function : ComputePlane
//purpose :
//=======================================================================
+void AIS_RadiusDimension::ComputePlane()
+{
+ if (!myIsGeometryValid)
+ {
+ return;
+ }
+
+ gp_Dir aDimensionX = gce_MakeDir (myAnchorPoint, myCircle.Location());
+
+ myPlane = gp_Pln (gp_Ax3 (myCircle.Location(),
+ myCircle.Axis().Direction(),
+ aDimensionX));
+}
-void AIS_RadiusDimension::computeValue ()
+//=======================================================================
+//function : GetModelUnits
+//purpose :
+//=======================================================================
+const TCollection_AsciiString& AIS_RadiusDimension::GetModelUnits() const
{
- myValue = myFirstPoint.Distance (mySecondPoint);
- AIS_Dimension::computeValue ();
+ return myDrawer->DimLengthModelUnits();
}
//=======================================================================
-//function : countDefaultPlane
+//function : GetDisplayUnits
+//purpose :
+//=======================================================================
+const TCollection_AsciiString& AIS_RadiusDimension::GetDisplayUnits() const
+{
+ return myDrawer->DimLengthDisplayUnits();
+}
+
+//=======================================================================
+//function : SetModelUnits
+//purpose :
+//=======================================================================
+void AIS_RadiusDimension::SetModelUnits (const TCollection_AsciiString& theUnits)
+{
+ myDrawer->SetDimLengthModelUnits (theUnits);
+}
+
+//=======================================================================
+//function : SetDisplayUnits
+//purpose :
+//=======================================================================
+void AIS_RadiusDimension::SetDisplayUnits (const TCollection_AsciiString& theUnits)
+{
+ myDrawer->SetDimLengthDisplayUnits(theUnits);
+}
+
+//=======================================================================
+//function : ComputeValue
//purpose :
//=======================================================================
+Standard_Real AIS_RadiusDimension::ComputeValue() const
+{
+ if (!IsValid())
+ {
+ return 0.0;
+ }
+
+ return myCircle.Radius();
+}
-void AIS_RadiusDimension::countDefaultPlane ()
+//=======================================================================
+//function : Compute
+//purpose :
+//=======================================================================
+void AIS_RadiusDimension::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePM*/,
+ const Handle(Prs3d_Presentation)& thePresentation,
+ const Standard_Integer theMode)
{
- // Compute normal of the default plane.
- gp_Vec aVec1(mySecondPoint, myFirstPoint),
- aVec2(mySecondPoint, ElCLib::Value(M_PI_2, myCircle));
- myDefaultPlane = gp_Pln(myCircle.Location(), aVec1^aVec2);
- // Set computed value to <myWorkingPlane>
- ResetWorkingPlane ();
+ thePresentation->Clear();
+ mySelectionGeom.Clear (theMode);
+
+ if (!IsValid())
+ {
+ return;
+ }
+
+ DrawLinearDimension (thePresentation, theMode, myAnchorPoint, myCircle.Location(), Standard_True);
}
//=======================================================================
-//function : SetFlyout
+//function : IsValidCircle
//purpose :
//=======================================================================
+Standard_Boolean AIS_RadiusDimension::IsValidCircle (const gp_Circ& theCircle) const
+{
+ return theCircle.Radius() > Precision::Confusion();
+}
-void AIS_RadiusDimension::SetFlyout (const Standard_Real theFlyout)
+//=======================================================================
+//function : IsValidAnchor
+//purpose :
+//=======================================================================
+Standard_Boolean AIS_RadiusDimension::IsValidAnchor (const gp_Circ& theCircle,
+ const gp_Pnt& theAnchor) const
{
- myFlyout = theFlyout;
+ gp_Pln aCirclePlane (theCircle.Location(), theCircle.Axis().Direction());
+ Standard_Real anAnchorDist = theAnchor.Distance (theCircle.Location());
+ Standard_Real aRadius = myCircle.Radius();
+
+ return Abs (anAnchorDist - aRadius) > Precision::Confusion()
+ && aCirclePlane.Contains (theAnchor, Precision::Confusion());
}
//=======================================================================
-//function : GetFlyout
+//function : GetTextPosition
//purpose :
//=======================================================================
+const gp_Pnt AIS_RadiusDimension::GetTextPosition() const
+{
+ if (IsTextPositionCustom())
+ {
+ return myFixedTextPosition;
+ }
-Standard_Real AIS_RadiusDimension::GetFlyout () const
+ // Counts text position according to the dimension parameters
+ return GetTextPositionForLinear (myAnchorPoint, myCircle.Location(), Standard_True);
+}
+
+//=======================================================================
+//function : GetTextPosition
+//purpose :
+//=======================================================================
+void AIS_RadiusDimension::SetTextPosition (const gp_Pnt& theTextPos)
{
- return myFlyout;
+ if (!myIsGeometryValid)
+ {
+ return;
+ }
+
+ myIsTextPositionFixed = Standard_True;
+ myFixedTextPosition = theTextPos;
+
+ SetToUpdate();
}