0031456: Visualization - move out Dimensions and Relations from package AIS to PrsDims
[occt.git] / src / TPrsStd / TPrsStd_ConstraintDriver.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
d5f74e42 5// This library is free software; you can redistribute it and/or modify it under
6// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 7// by the Free Software Foundation, with special exception defined in the file
8// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9// distribution for complete text of the license and disclaimer of any warranty.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
7fd59977 14
42cf5bc1 15#include <AIS_InteractiveContext.hxx>
16#include <AIS_InteractiveObject.hxx>
787ff240 17#include <PrsDim_Relation.hxx>
7fd59977 18#include <Standard_GUID.hxx>
42cf5bc1 19#include <Standard_ProgramError.hxx>
20#include <Standard_Type.hxx>
7fd59977 21#include <TDataStd_Real.hxx>
42cf5bc1 22#include <TDataXtd_Constraint.hxx>
7fd59977 23#include <TDataXtd_Position.hxx>
42cf5bc1 24#include <TDF_Label.hxx>
25#include <TPrsStd_ConstraintDriver.hxx>
26#include <TPrsStd_ConstraintTools.hxx>
7fd59977 27
92efcf78 28IMPLEMENT_STANDARD_RTTIEXT(TPrsStd_ConstraintDriver,TPrsStd_Driver)
29
7fd59977 30//=======================================================================
31//function :
32//purpose :
33//=======================================================================
34TPrsStd_ConstraintDriver::TPrsStd_ConstraintDriver()
35{
36}
37
38//=======================================================================
39//function :
40//purpose :
41//=======================================================================
42Standard_Boolean TPrsStd_ConstraintDriver::Update (const TDF_Label& aLabel,
43 Handle(AIS_InteractiveObject)& anAISObject)
44{
45 Handle(TDataXtd_Constraint) apConstraint;
46 if( !aLabel.FindAttribute(TDataXtd_Constraint::GetID(), apConstraint) ) {
47 return Standard_False;
48 }
49
50 if (!anAISObject.IsNull() && anAISObject->HasInteractiveContext()) {
51 if (!apConstraint->Verified()) {
52 TPrsStd_ConstraintTools::UpdateOnlyValue(apConstraint,anAISObject);
87432b82 53 Quantity_Color aColor;
54 anAISObject->Color (aColor);
55 if (aColor.Name() != Quantity_NOC_RED)
56 {
57 anAISObject->SetColor(Quantity_NOC_RED);
58 }
7fd59977 59 return Standard_True;
60 }
61 }
62
63 Handle(AIS_InteractiveObject) anAIS = anAISObject;
64
65 // recuperation
66 TDataXtd_ConstraintEnum thetype = apConstraint->GetType();
67
68 switch (thetype) {
69 case TDataXtd_DISTANCE:
70 {
71 TPrsStd_ConstraintTools::ComputeDistance(apConstraint,anAIS);
72 break;
73 }
74 case TDataXtd_PARALLEL:
75 {
76 TPrsStd_ConstraintTools::ComputeParallel(apConstraint,anAIS);
77 break;
78 }
79 case TDataXtd_PERPENDICULAR:
80 {
81 TPrsStd_ConstraintTools::ComputePerpendicular(apConstraint,anAIS);
82 break;
83 }
84 case TDataXtd_CONCENTRIC:
85 {
86 TPrsStd_ConstraintTools::ComputeConcentric(apConstraint,anAIS);
87 break;
88 }
89 case TDataXtd_SYMMETRY:
90 {
91 TPrsStd_ConstraintTools::ComputeSymmetry(apConstraint,anAIS);
92 break;
93 }
94 case TDataXtd_MIDPOINT:
95 {
96 TPrsStd_ConstraintTools::ComputeMidPoint(apConstraint,anAIS);
97 break;
98 }
99 case TDataXtd_TANGENT:
100 {
101 TPrsStd_ConstraintTools::ComputeTangent(apConstraint,anAIS);
102 break;
103 }
104 case TDataXtd_ANGLE:
105 {
106 TPrsStd_ConstraintTools::ComputeAngle(apConstraint,anAIS);
107 break;
108 }
109 case TDataXtd_RADIUS:
110 {
111 TPrsStd_ConstraintTools::ComputeRadius(apConstraint,anAIS);
112 break;
113 }
114 case TDataXtd_MINOR_RADIUS:
115 {
116 TPrsStd_ConstraintTools::ComputeMinRadius(apConstraint,anAIS);
117 break;
118 }
119 case TDataXtd_MAJOR_RADIUS:
120 {
121 TPrsStd_ConstraintTools::ComputeMaxRadius(apConstraint,anAIS);
122 break;
123 }
124 case TDataXtd_DIAMETER:
125 {
126 TPrsStd_ConstraintTools::ComputeDiameter(apConstraint,anAIS);
127 break;
128 }
129 case TDataXtd_FIX:
130 {
131 TPrsStd_ConstraintTools::ComputeFix(apConstraint,anAIS);
132 break;
133 }
134 case TDataXtd_OFFSET:
135 {
136 TPrsStd_ConstraintTools::ComputeOffset(apConstraint,anAIS);
137 break;
138 }
139 case TDataXtd_COINCIDENT:
140 {
141 TPrsStd_ConstraintTools::ComputeCoincident(apConstraint,anAIS);
142 break;
143 }
144 case TDataXtd_ROUND:
145 {
146 TPrsStd_ConstraintTools::ComputeRound(apConstraint,anAIS);
147 break;
148 }
149
150 case TDataXtd_MATE:
151 case TDataXtd_ALIGN_FACES:
152 case TDataXtd_ALIGN_AXES:
153 case TDataXtd_AXES_ANGLE:
154 {
155 TPrsStd_ConstraintTools::ComputePlacement(apConstraint,anAIS);
156 break;
157 }
158 case TDataXtd_EQUAL_DISTANCE :
159 {
160 TPrsStd_ConstraintTools::ComputeEqualDistance(apConstraint,anAIS);
161 break;
162 }
163 case TDataXtd_EQUAL_RADIUS:
164 {
165 TPrsStd_ConstraintTools::ComputeEqualRadius(apConstraint,anAIS);
166 break;
167 }
168 default:
169 {
170 TPrsStd_ConstraintTools::ComputeOthers(apConstraint,anAIS);
171 break;
172 }
173 }
174 if (anAIS.IsNull()) return Standard_False;
175
0717ddc1 176 anAIS->ResetTransformation();
7fd59977 177 anAIS->SetToUpdate();
178 anAIS->UpdateSelection();
179
180 anAISObject = anAIS;
181
182 Handle(TDataXtd_Position) Position;
183 if (aLabel.FindAttribute(TDataXtd_Position::GetID(),Position)) {
787ff240 184 Handle(PrsDim_Relation)::DownCast(anAISObject)->SetPosition(Position->GetPosition());
7fd59977 185 }
186
187 if (anAISObject->HasInteractiveContext()) {
87432b82 188 Quantity_Color originColor;
189 anAISObject->Color (originColor);
7fd59977 190 if (!apConstraint->Verified()) {
87432b82 191 if (originColor.Name() != Quantity_NOC_RED)
7fd59977 192 anAISObject->SetColor(Quantity_NOC_RED);
193 }
194 else if (apConstraint->IsDimension() && apConstraint->GetValue()->IsCaptured()) {
87432b82 195 if (originColor.Name() != Quantity_NOC_PURPLE)
7fd59977 196 anAISObject->SetColor(Quantity_NOC_PURPLE);
197 }
87432b82 198 else if (!apConstraint->IsPlanar() && (originColor.Name() != Quantity_NOC_YELLOW))
7fd59977 199 anAISObject->SetColor(Quantity_NOC_YELLOW);
200 }
201 else {
202 if (!apConstraint->Verified()) {
203 anAISObject->SetColor(Quantity_NOC_RED);
204 }
205 else if (apConstraint->IsDimension() && apConstraint->GetValue()->IsCaptured()) {
206 anAISObject->SetColor(Quantity_NOC_PURPLE);
207 }
208 else if (!apConstraint->IsPlanar()) anAISObject->SetColor(Quantity_NOC_YELLOW);
209 }
210 return Standard_True;
211}
212