0024837: Visualization - revise design and implementation of connected Interactive...
[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#include <TPrsStd_ConstraintDriver.ixx>
15
16#include <TDF_Label.hxx>
17#include <TDataXtd_Constraint.hxx>
18#include <TPrsStd_ConstraintTools.hxx>
19#include <Standard_ProgramError.hxx>
20#include <Standard_GUID.hxx>
21#include <TDataStd_Real.hxx>
22#include <TDataXtd_Position.hxx>
23#include <AIS_Drawer.hxx>
24#include <AIS_InteractiveContext.hxx>
25#include <AIS_Relation.hxx>
26
27//=======================================================================
28//function :
29//purpose :
30//=======================================================================
31TPrsStd_ConstraintDriver::TPrsStd_ConstraintDriver()
32{
33}
34
35//=======================================================================
36//function :
37//purpose :
38//=======================================================================
39Standard_Boolean TPrsStd_ConstraintDriver::Update (const TDF_Label& aLabel,
40 Handle(AIS_InteractiveObject)& anAISObject)
41{
42 Handle(TDataXtd_Constraint) apConstraint;
43 if( !aLabel.FindAttribute(TDataXtd_Constraint::GetID(), apConstraint) ) {
44 return Standard_False;
45 }
46
47 if (!anAISObject.IsNull() && anAISObject->HasInteractiveContext()) {
48 if (!apConstraint->Verified()) {
49 TPrsStd_ConstraintTools::UpdateOnlyValue(apConstraint,anAISObject);
50 if (anAISObject->Color() != Quantity_NOC_RED) anAISObject->SetColor(Quantity_NOC_RED);
51 return Standard_True;
52 }
53 }
54
55 Handle(AIS_InteractiveObject) anAIS = anAISObject;
56
57 // recuperation
58 TDataXtd_ConstraintEnum thetype = apConstraint->GetType();
59
60 switch (thetype) {
61 case TDataXtd_DISTANCE:
62 {
63 TPrsStd_ConstraintTools::ComputeDistance(apConstraint,anAIS);
64 break;
65 }
66 case TDataXtd_PARALLEL:
67 {
68 TPrsStd_ConstraintTools::ComputeParallel(apConstraint,anAIS);
69 break;
70 }
71 case TDataXtd_PERPENDICULAR:
72 {
73 TPrsStd_ConstraintTools::ComputePerpendicular(apConstraint,anAIS);
74 break;
75 }
76 case TDataXtd_CONCENTRIC:
77 {
78 TPrsStd_ConstraintTools::ComputeConcentric(apConstraint,anAIS);
79 break;
80 }
81 case TDataXtd_SYMMETRY:
82 {
83 TPrsStd_ConstraintTools::ComputeSymmetry(apConstraint,anAIS);
84 break;
85 }
86 case TDataXtd_MIDPOINT:
87 {
88 TPrsStd_ConstraintTools::ComputeMidPoint(apConstraint,anAIS);
89 break;
90 }
91 case TDataXtd_TANGENT:
92 {
93 TPrsStd_ConstraintTools::ComputeTangent(apConstraint,anAIS);
94 break;
95 }
96 case TDataXtd_ANGLE:
97 {
98 TPrsStd_ConstraintTools::ComputeAngle(apConstraint,anAIS);
99 break;
100 }
101 case TDataXtd_RADIUS:
102 {
103 TPrsStd_ConstraintTools::ComputeRadius(apConstraint,anAIS);
104 break;
105 }
106 case TDataXtd_MINOR_RADIUS:
107 {
108 TPrsStd_ConstraintTools::ComputeMinRadius(apConstraint,anAIS);
109 break;
110 }
111 case TDataXtd_MAJOR_RADIUS:
112 {
113 TPrsStd_ConstraintTools::ComputeMaxRadius(apConstraint,anAIS);
114 break;
115 }
116 case TDataXtd_DIAMETER:
117 {
118 TPrsStd_ConstraintTools::ComputeDiameter(apConstraint,anAIS);
119 break;
120 }
121 case TDataXtd_FIX:
122 {
123 TPrsStd_ConstraintTools::ComputeFix(apConstraint,anAIS);
124 break;
125 }
126 case TDataXtd_OFFSET:
127 {
128 TPrsStd_ConstraintTools::ComputeOffset(apConstraint,anAIS);
129 break;
130 }
131 case TDataXtd_COINCIDENT:
132 {
133 TPrsStd_ConstraintTools::ComputeCoincident(apConstraint,anAIS);
134 break;
135 }
136 case TDataXtd_ROUND:
137 {
138 TPrsStd_ConstraintTools::ComputeRound(apConstraint,anAIS);
139 break;
140 }
141
142 case TDataXtd_MATE:
143 case TDataXtd_ALIGN_FACES:
144 case TDataXtd_ALIGN_AXES:
145 case TDataXtd_AXES_ANGLE:
146 {
147 TPrsStd_ConstraintTools::ComputePlacement(apConstraint,anAIS);
148 break;
149 }
150 case TDataXtd_EQUAL_DISTANCE :
151 {
152 TPrsStd_ConstraintTools::ComputeEqualDistance(apConstraint,anAIS);
153 break;
154 }
155 case TDataXtd_EQUAL_RADIUS:
156 {
157 TPrsStd_ConstraintTools::ComputeEqualRadius(apConstraint,anAIS);
158 break;
159 }
160 default:
161 {
162 TPrsStd_ConstraintTools::ComputeOthers(apConstraint,anAIS);
163 break;
164 }
165 }
166 if (anAIS.IsNull()) return Standard_False;
167
0717ddc1 168 anAIS->ResetTransformation();
7fd59977 169 anAIS->SetToUpdate();
170 anAIS->UpdateSelection();
171
172 anAISObject = anAIS;
173
174 Handle(TDataXtd_Position) Position;
175 if (aLabel.FindAttribute(TDataXtd_Position::GetID(),Position)) {
176 Handle(AIS_Relation)::DownCast(anAISObject)->SetPosition(Position->GetPosition());
177 }
178
179 if (anAISObject->HasInteractiveContext()) {
180 Quantity_NameOfColor originColor = anAISObject->Color();
181 if (!apConstraint->Verified()) {
182 if (originColor != Quantity_NOC_RED)
183 anAISObject->SetColor(Quantity_NOC_RED);
184 }
185 else if (apConstraint->IsDimension() && apConstraint->GetValue()->IsCaptured()) {
186 if (originColor != Quantity_NOC_PURPLE)
187 anAISObject->SetColor(Quantity_NOC_PURPLE);
188 }
189 else if (!apConstraint->IsPlanar() && (originColor != Quantity_NOC_YELLOW))
190 anAISObject->SetColor(Quantity_NOC_YELLOW);
191 }
192 else {
193 if (!apConstraint->Verified()) {
194 anAISObject->SetColor(Quantity_NOC_RED);
195 }
196 else if (apConstraint->IsDimension() && apConstraint->GetValue()->IsCaptured()) {
197 anAISObject->SetColor(Quantity_NOC_PURPLE);
198 }
199 else if (!apConstraint->IsPlanar()) anAISObject->SetColor(Quantity_NOC_YELLOW);
200 }
201 return Standard_True;
202}
203