1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
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.
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.
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.
18 #include <TPrsStd_ConstraintDriver.ixx>
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>
31 //=======================================================================
34 //=======================================================================
35 TPrsStd_ConstraintDriver::TPrsStd_ConstraintDriver()
39 //=======================================================================
42 //=======================================================================
43 Standard_Boolean TPrsStd_ConstraintDriver::Update (const TDF_Label& aLabel,
44 Handle(AIS_InteractiveObject)& anAISObject)
46 Handle(TDataXtd_Constraint) apConstraint;
47 if( !aLabel.FindAttribute(TDataXtd_Constraint::GetID(), apConstraint) ) {
48 return Standard_False;
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);
59 Handle(AIS_InteractiveObject) anAIS = anAISObject;
62 TDataXtd_ConstraintEnum thetype = apConstraint->GetType();
65 case TDataXtd_DISTANCE:
67 TPrsStd_ConstraintTools::ComputeDistance(apConstraint,anAIS);
70 case TDataXtd_PARALLEL:
72 TPrsStd_ConstraintTools::ComputeParallel(apConstraint,anAIS);
75 case TDataXtd_PERPENDICULAR:
77 TPrsStd_ConstraintTools::ComputePerpendicular(apConstraint,anAIS);
80 case TDataXtd_CONCENTRIC:
82 TPrsStd_ConstraintTools::ComputeConcentric(apConstraint,anAIS);
85 case TDataXtd_SYMMETRY:
87 TPrsStd_ConstraintTools::ComputeSymmetry(apConstraint,anAIS);
90 case TDataXtd_MIDPOINT:
92 TPrsStd_ConstraintTools::ComputeMidPoint(apConstraint,anAIS);
95 case TDataXtd_TANGENT:
97 TPrsStd_ConstraintTools::ComputeTangent(apConstraint,anAIS);
102 TPrsStd_ConstraintTools::ComputeAngle(apConstraint,anAIS);
105 case TDataXtd_RADIUS:
107 TPrsStd_ConstraintTools::ComputeRadius(apConstraint,anAIS);
110 case TDataXtd_MINOR_RADIUS:
112 TPrsStd_ConstraintTools::ComputeMinRadius(apConstraint,anAIS);
115 case TDataXtd_MAJOR_RADIUS:
117 TPrsStd_ConstraintTools::ComputeMaxRadius(apConstraint,anAIS);
120 case TDataXtd_DIAMETER:
122 TPrsStd_ConstraintTools::ComputeDiameter(apConstraint,anAIS);
127 TPrsStd_ConstraintTools::ComputeFix(apConstraint,anAIS);
130 case TDataXtd_OFFSET:
132 TPrsStd_ConstraintTools::ComputeOffset(apConstraint,anAIS);
135 case TDataXtd_COINCIDENT:
137 TPrsStd_ConstraintTools::ComputeCoincident(apConstraint,anAIS);
142 TPrsStd_ConstraintTools::ComputeRound(apConstraint,anAIS);
147 case TDataXtd_ALIGN_FACES:
148 case TDataXtd_ALIGN_AXES:
149 case TDataXtd_AXES_ANGLE:
151 TPrsStd_ConstraintTools::ComputePlacement(apConstraint,anAIS);
154 case TDataXtd_EQUAL_DISTANCE :
156 TPrsStd_ConstraintTools::ComputeEqualDistance(apConstraint,anAIS);
159 case TDataXtd_EQUAL_RADIUS:
161 TPrsStd_ConstraintTools::ComputeEqualRadius(apConstraint,anAIS);
166 TPrsStd_ConstraintTools::ComputeOthers(apConstraint,anAIS);
170 if (anAIS.IsNull()) return Standard_False;
172 anAIS->ResetLocation();
173 anAIS->SetToUpdate();
174 anAIS->UpdateSelection();
178 Handle(TDataXtd_Position) Position;
179 if (aLabel.FindAttribute(TDataXtd_Position::GetID(),Position)) {
180 Handle(AIS_Relation)::DownCast(anAISObject)->SetPosition(Position->GetPosition());
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);
189 else if (apConstraint->IsDimension() && apConstraint->GetValue()->IsCaptured()) {
190 if (originColor != Quantity_NOC_PURPLE)
191 anAISObject->SetColor(Quantity_NOC_PURPLE);
193 else if (!apConstraint->IsPlanar() && (originColor != Quantity_NOC_YELLOW))
194 anAISObject->SetColor(Quantity_NOC_YELLOW);
197 if (!apConstraint->Verified()) {
198 anAISObject->SetColor(Quantity_NOC_RED);
200 else if (apConstraint->IsDimension() && apConstraint->GetValue()->IsCaptured()) {
201 anAISObject->SetColor(Quantity_NOC_PURPLE);
203 else if (!apConstraint->IsPlanar()) anAISObject->SetColor(Quantity_NOC_YELLOW);
205 return Standard_True;