0023024: Update headers of OCCT files
[occt.git] / src / TPrsStd / TPrsStd_ConstraintDriver.cxx
1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
2 //
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
7 //
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
10 //
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
17
18 #include <TPrsStd_ConstraintDriver.ixx>
19
20 #include <TDF_Label.hxx>
21 #include <TDataXtd_Constraint.hxx>
22 #include <TPrsStd_ConstraintTools.hxx>
23 #include <Standard_ProgramError.hxx>
24 #include <Standard_GUID.hxx>
25 #include <TDataStd_Real.hxx>
26 #include <TDataXtd_Position.hxx>
27 #include <AIS_Drawer.hxx>
28 #include <AIS_InteractiveContext.hxx>
29 #include <AIS_Relation.hxx>
30
31 //=======================================================================
32 //function :
33 //purpose  : 
34 //=======================================================================
35 TPrsStd_ConstraintDriver::TPrsStd_ConstraintDriver()
36 {
37 }
38
39 //=======================================================================
40 //function :
41 //purpose  : 
42 //=======================================================================
43 Standard_Boolean TPrsStd_ConstraintDriver::Update (const TDF_Label& aLabel,
44                                                   Handle(AIS_InteractiveObject)& anAISObject) 
45 {
46   Handle(TDataXtd_Constraint) apConstraint;
47   if( !aLabel.FindAttribute(TDataXtd_Constraint::GetID(), apConstraint) ) {
48    return Standard_False;
49   }
50    
51   if (!anAISObject.IsNull() && anAISObject->HasInteractiveContext()) {
52     if (!apConstraint->Verified()) {
53       TPrsStd_ConstraintTools::UpdateOnlyValue(apConstraint,anAISObject);
54       if (anAISObject->Color() != Quantity_NOC_RED) anAISObject->SetColor(Quantity_NOC_RED);
55       return Standard_True;
56     }
57   }
58
59   Handle(AIS_InteractiveObject) anAIS = anAISObject;
60
61   // recuperation 
62   TDataXtd_ConstraintEnum thetype = apConstraint->GetType();
63   
64   switch (thetype)  {
65   case TDataXtd_DISTANCE:
66     {
67       TPrsStd_ConstraintTools::ComputeDistance(apConstraint,anAIS);
68       break;
69     }
70   case TDataXtd_PARALLEL:
71     {
72       TPrsStd_ConstraintTools::ComputeParallel(apConstraint,anAIS);
73       break;
74     }
75   case TDataXtd_PERPENDICULAR:
76     {
77       TPrsStd_ConstraintTools::ComputePerpendicular(apConstraint,anAIS);
78       break;
79     }
80   case TDataXtd_CONCENTRIC:
81     {
82       TPrsStd_ConstraintTools::ComputeConcentric(apConstraint,anAIS);
83       break;
84     }
85   case TDataXtd_SYMMETRY:
86     {
87       TPrsStd_ConstraintTools::ComputeSymmetry(apConstraint,anAIS);
88       break;
89     }
90   case TDataXtd_MIDPOINT:
91     {
92       TPrsStd_ConstraintTools::ComputeMidPoint(apConstraint,anAIS);
93       break;
94     }
95   case TDataXtd_TANGENT:
96     {
97       TPrsStd_ConstraintTools::ComputeTangent(apConstraint,anAIS);
98       break;
99     }
100   case TDataXtd_ANGLE:
101     {
102       TPrsStd_ConstraintTools::ComputeAngle(apConstraint,anAIS);
103       break;
104     }
105   case TDataXtd_RADIUS:
106     {
107       TPrsStd_ConstraintTools::ComputeRadius(apConstraint,anAIS);
108       break;
109     }
110   case TDataXtd_MINOR_RADIUS:
111     {
112       TPrsStd_ConstraintTools::ComputeMinRadius(apConstraint,anAIS);
113       break;
114     }
115   case TDataXtd_MAJOR_RADIUS:
116     {
117       TPrsStd_ConstraintTools::ComputeMaxRadius(apConstraint,anAIS);
118       break; 
119     }
120   case TDataXtd_DIAMETER:
121     {
122       TPrsStd_ConstraintTools::ComputeDiameter(apConstraint,anAIS);
123       break;
124     }
125   case TDataXtd_FIX:
126     {
127       TPrsStd_ConstraintTools::ComputeFix(apConstraint,anAIS);
128       break;
129     } 
130   case TDataXtd_OFFSET:
131     {
132       TPrsStd_ConstraintTools::ComputeOffset(apConstraint,anAIS);
133       break;
134     }
135   case TDataXtd_COINCIDENT:
136     {
137       TPrsStd_ConstraintTools::ComputeCoincident(apConstraint,anAIS); 
138       break;
139     }
140   case TDataXtd_ROUND:
141     {
142       TPrsStd_ConstraintTools::ComputeRound(apConstraint,anAIS); 
143       break;
144     }
145
146   case TDataXtd_MATE:
147   case TDataXtd_ALIGN_FACES:
148   case TDataXtd_ALIGN_AXES:
149   case TDataXtd_AXES_ANGLE:
150     {
151       TPrsStd_ConstraintTools::ComputePlacement(apConstraint,anAIS);
152       break;
153     }
154   case TDataXtd_EQUAL_DISTANCE :
155     {
156       TPrsStd_ConstraintTools::ComputeEqualDistance(apConstraint,anAIS);
157       break;
158     }
159   case  TDataXtd_EQUAL_RADIUS:
160     {
161       TPrsStd_ConstraintTools::ComputeEqualRadius(apConstraint,anAIS);
162       break;
163     }
164   default:
165     {
166       TPrsStd_ConstraintTools::ComputeOthers(apConstraint,anAIS);
167       break;
168     }
169   }
170   if (anAIS.IsNull()) return Standard_False;
171  
172   anAIS->ResetLocation();
173   anAIS->SetToUpdate();
174   anAIS->UpdateSelection();
175   
176   anAISObject = anAIS;
177   
178   Handle(TDataXtd_Position) Position;
179   if (aLabel.FindAttribute(TDataXtd_Position::GetID(),Position)) {
180     Handle(AIS_Relation)::DownCast(anAISObject)->SetPosition(Position->GetPosition());
181   }
182
183   if (anAISObject->HasInteractiveContext()) {
184     Quantity_NameOfColor originColor = anAISObject->Color();
185     if (!apConstraint->Verified()) {
186       if (originColor != Quantity_NOC_RED)
187         anAISObject->SetColor(Quantity_NOC_RED);
188     }
189     else if (apConstraint->IsDimension() && apConstraint->GetValue()->IsCaptured()) {
190       if (originColor != Quantity_NOC_PURPLE)
191         anAISObject->SetColor(Quantity_NOC_PURPLE);
192     }
193     else if (!apConstraint->IsPlanar() && (originColor != Quantity_NOC_YELLOW)) 
194       anAISObject->SetColor(Quantity_NOC_YELLOW);
195   }
196   else {
197     if (!apConstraint->Verified()) {
198       anAISObject->SetColor(Quantity_NOC_RED);
199     }
200     else if (apConstraint->IsDimension() && apConstraint->GetValue()->IsCaptured()) {
201       anAISObject->SetColor(Quantity_NOC_PURPLE);
202     }
203     else if (!apConstraint->IsPlanar()) anAISObject->SetColor(Quantity_NOC_YELLOW);
204   }
205   return Standard_True;
206 }
207