0024448: Possible copy-paste bug in IGESGeom_SplineCurve.cxx
[occt.git] / src / AIS / AIS_DiameterDimension.cxx
CommitLineData
b311480e 1// Created on: 1996-12-05
2// Created by: Jacques MINOT/Odile Olivier/Sergey ZARITCHNY
3// Copyright (c) 1996-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
a6eb515f 21#include <AIS_DiameterDimension.hxx>
a6eb515f 22#include <AIS.hxx>
23#include <AIS_Drawer.hxx>
7fd59977 24#include <ElCLib.hxx>
a6eb515f 25#include <gce_MakeDir.hxx>
a6eb515f 26#include <Graphic3d_ArrayOfSegments.hxx>
27#include <Graphic3d_Group.hxx>
28#include <PrsMgr_PresentationManager3d.hxx>
a6eb515f 29#include <Prs3d_Root.hxx>
7fd59977 30
a6eb515f 31IMPLEMENT_STANDARD_HANDLE(AIS_DiameterDimension, AIS_Dimension)
32IMPLEMENT_STANDARD_RTTIEXT(AIS_DiameterDimension, AIS_Dimension)
7fd59977 33
d7bffd44 34namespace
35{
36 static const Standard_ExtCharacter THE_DIAMETER_SYMBOL (0x00D8);
37};
38
7fd59977 39//=======================================================================
40//function : Constructor
41//purpose :
42//=======================================================================
43
a6eb515f 44AIS_DiameterDimension::AIS_DiameterDimension(const gp_Circ& theCircle)
45: AIS_Dimension(),
a6eb515f 46 myCircle (theCircle)
7fd59977 47{
a6eb515f 48 SetKindOfDimension(AIS_KOD_DIAMETER);
49 myIsInitialized = Standard_True;
d7bffd44 50 SetSpecialSymbol (THE_DIAMETER_SYMBOL);
a6eb515f 51 SetDisplaySpecialSymbol (AIS_DSS_Before);
d7bffd44 52 SetFlyout (0.0);
a6eb515f 53 // Count attach points
54 myFirstPoint = ElCLib::Value (0, myCircle);
55 mySecondPoint = myFirstPoint.Translated (gp_Vec(myFirstPoint, theCircle.Location())*2);
7fd59977 56}
57
58//=======================================================================
59//function : Constructor
60//purpose :
61//=======================================================================
62
a6eb515f 63AIS_DiameterDimension::AIS_DiameterDimension(const gp_Circ& theCircle, const gp_Pnt& theAttachPoint)
64: AIS_Dimension(),
a6eb515f 65 myCircle (theCircle)
7fd59977 66{
d7bffd44 67 SetKindOfDimension (AIS_KOD_DIAMETER);
68 SetSpecialSymbol (THE_DIAMETER_SYMBOL);
a6eb515f 69 SetDisplaySpecialSymbol (AIS_DSS_Before);
d7bffd44 70 SetFlyout (0.0);
a6eb515f 71 myFirstPoint = theAttachPoint;
72 // Count the second point
73 if (Abs(myFirstPoint.Distance (theCircle.Location()) - theCircle.Radius()) < Precision::Confusion())
74 {
75 mySecondPoint = myFirstPoint.Translated(gp_Vec(myFirstPoint, theCircle.Location())*2);
76 }
77 else
78 {
79 myFirstPoint = ElCLib::Value(0, myCircle);
80 mySecondPoint = myFirstPoint.Translated(gp_Vec(myFirstPoint, theCircle.Location())*2);
81 }
82 myIsInitialized = Standard_True;
7fd59977 83}
84
7fd59977 85//=======================================================================
a6eb515f 86//function : Constructor
87//purpose : Universal constructor for diameter dimension of shape
7fd59977 88//=======================================================================
89
a6eb515f 90AIS_DiameterDimension::AIS_DiameterDimension (const TopoDS_Shape& theShape)
62b6361a 91: AIS_Dimension ()
7fd59977 92{
d7bffd44 93 SetKindOfDimension (AIS_KOD_DIAMETER);
94 SetSpecialSymbol (THE_DIAMETER_SYMBOL);
95 SetDisplaySpecialSymbol (AIS_DSS_Before);
96 SetFlyout (0.0);
a6eb515f 97 myFirstShape = theShape;
98 myIsInitialized = Standard_False;
7fd59977 99}
100
101//=======================================================================
a6eb515f 102//function : Compute
7fd59977 103//purpose :
104//=======================================================================
105
a6eb515f 106void AIS_DiameterDimension::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePM*/,
107 const Handle(Prs3d_Presentation)& thePresentation,
108 const Standard_Integer theMode)
7fd59977 109{
a6eb515f 110 thePresentation->Clear();
fe83e1ea 111 mySelectionGeom.Clear (theMode);
a6eb515f 112
113 Handle(Prs3d_DimensionAspect) aDimensionAspect = myDrawer->DimensionAspect();
114 Prs3d_Root::CurrentGroup (thePresentation)->SetPrimitivesAspect (aDimensionAspect->LineAspect()->Aspect());
115
116 if (!myIsInitialized)
117 {
118 if (!initCircularDimension (myFirstShape, myCircle,
119 myFirstPoint, mySecondPoint))
120 return;
121 else
122 myIsInitialized = Standard_True;
7fd59977 123 }
7fd59977 124
d7bffd44 125 if (!myIsWorkingPlaneCustom)
a6eb515f 126 {
d7bffd44 127 countDefaultPlane();
7fd59977 128 }
129
fe83e1ea 130 drawLinearDimension (thePresentation, theMode);
7fd59977 131}
132
133//=======================================================================
a6eb515f 134//function : computeValue
7fd59977 135//purpose :
136//=======================================================================
137
a6eb515f 138void AIS_DiameterDimension::computeValue ()
7fd59977 139{
a6eb515f 140 myValue = myFirstPoint.Distance (mySecondPoint);
141 AIS_Dimension::computeValue();
7fd59977 142}
143
7fd59977 144//=======================================================================
a6eb515f 145//function : countDefaultPlane
7fd59977 146//purpose :
147//=======================================================================
148
a6eb515f 149void AIS_DiameterDimension::countDefaultPlane ()
7fd59977 150{
a6eb515f 151 // Compute normal of the default plane.
152 //gp_Vec aVec1(mySecondPoint, myFirstPoint),
153 // aVec2(mySecondPoint, ElCLib::Value(M_PI_2, myCircle));
154 myDefaultPlane = gp_Pln(gp_Ax3(myCircle.Position()));
155 // Set computed value to <myWorkingPlane>
156 ResetWorkingPlane ();
7fd59977 157}