1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
15 #include <AIS_InteractiveContext.hxx>
16 #include <AIS_InteractiveObject.hxx>
17 #include <PrsDim_Relation.hxx>
18 #include <Standard_GUID.hxx>
19 #include <Standard_ProgramError.hxx>
20 #include <Standard_Type.hxx>
21 #include <TDataStd_Real.hxx>
22 #include <TDataXtd_Constraint.hxx>
23 #include <TDataXtd_Position.hxx>
24 #include <TDF_Label.hxx>
25 #include <TPrsStd_ConstraintDriver.hxx>
26 #include <TPrsStd_ConstraintTools.hxx>
28 IMPLEMENT_STANDARD_RTTIEXT(TPrsStd_ConstraintDriver,TPrsStd_Driver)
30 //=======================================================================
33 //=======================================================================
34 TPrsStd_ConstraintDriver::TPrsStd_ConstraintDriver()
38 //=======================================================================
41 //=======================================================================
42 Standard_Boolean TPrsStd_ConstraintDriver::Update (const TDF_Label& aLabel,
43 Handle(AIS_InteractiveObject)& anAISObject)
45 Handle(TDataXtd_Constraint) apConstraint;
46 if( !aLabel.FindAttribute(TDataXtd_Constraint::GetID(), apConstraint) ) {
47 return Standard_False;
50 if (!anAISObject.IsNull() && anAISObject->HasInteractiveContext()) {
51 if (!apConstraint->Verified()) {
52 TPrsStd_ConstraintTools::UpdateOnlyValue(apConstraint,anAISObject);
53 Quantity_Color aColor;
54 anAISObject->Color (aColor);
55 if (aColor.Name() != Quantity_NOC_RED)
57 anAISObject->SetColor(Quantity_NOC_RED);
63 Handle(AIS_InteractiveObject) anAIS = anAISObject;
66 TDataXtd_ConstraintEnum thetype = apConstraint->GetType();
69 case TDataXtd_DISTANCE:
71 TPrsStd_ConstraintTools::ComputeDistance(apConstraint,anAIS);
74 case TDataXtd_PARALLEL:
76 TPrsStd_ConstraintTools::ComputeParallel(apConstraint,anAIS);
79 case TDataXtd_PERPENDICULAR:
81 TPrsStd_ConstraintTools::ComputePerpendicular(apConstraint,anAIS);
84 case TDataXtd_CONCENTRIC:
86 TPrsStd_ConstraintTools::ComputeConcentric(apConstraint,anAIS);
89 case TDataXtd_SYMMETRY:
91 TPrsStd_ConstraintTools::ComputeSymmetry(apConstraint,anAIS);
94 case TDataXtd_MIDPOINT:
96 TPrsStd_ConstraintTools::ComputeMidPoint(apConstraint,anAIS);
99 case TDataXtd_TANGENT:
101 TPrsStd_ConstraintTools::ComputeTangent(apConstraint,anAIS);
106 TPrsStd_ConstraintTools::ComputeAngle(apConstraint,anAIS);
109 case TDataXtd_RADIUS:
111 TPrsStd_ConstraintTools::ComputeRadius(apConstraint,anAIS);
114 case TDataXtd_MINOR_RADIUS:
116 TPrsStd_ConstraintTools::ComputeMinRadius(apConstraint,anAIS);
119 case TDataXtd_MAJOR_RADIUS:
121 TPrsStd_ConstraintTools::ComputeMaxRadius(apConstraint,anAIS);
124 case TDataXtd_DIAMETER:
126 TPrsStd_ConstraintTools::ComputeDiameter(apConstraint,anAIS);
131 TPrsStd_ConstraintTools::ComputeFix(apConstraint,anAIS);
134 case TDataXtd_OFFSET:
136 TPrsStd_ConstraintTools::ComputeOffset(apConstraint,anAIS);
139 case TDataXtd_COINCIDENT:
141 TPrsStd_ConstraintTools::ComputeCoincident(apConstraint,anAIS);
146 TPrsStd_ConstraintTools::ComputeRound(apConstraint,anAIS);
151 case TDataXtd_ALIGN_FACES:
152 case TDataXtd_ALIGN_AXES:
153 case TDataXtd_AXES_ANGLE:
155 TPrsStd_ConstraintTools::ComputePlacement(apConstraint,anAIS);
158 case TDataXtd_EQUAL_DISTANCE :
160 TPrsStd_ConstraintTools::ComputeEqualDistance(apConstraint,anAIS);
163 case TDataXtd_EQUAL_RADIUS:
165 TPrsStd_ConstraintTools::ComputeEqualRadius(apConstraint,anAIS);
170 TPrsStd_ConstraintTools::ComputeOthers(apConstraint,anAIS);
174 if (anAIS.IsNull()) return Standard_False;
176 anAIS->ResetTransformation();
177 anAIS->SetToUpdate();
178 anAIS->UpdateSelection();
182 Handle(TDataXtd_Position) Position;
183 if (aLabel.FindAttribute(TDataXtd_Position::GetID(),Position)) {
184 Handle(PrsDim_Relation)::DownCast(anAISObject)->SetPosition(Position->GetPosition());
187 if (anAISObject->HasInteractiveContext()) {
188 Quantity_Color originColor;
189 anAISObject->Color (originColor);
190 if (!apConstraint->Verified()) {
191 if (originColor.Name() != Quantity_NOC_RED)
192 anAISObject->SetColor(Quantity_NOC_RED);
194 else if (apConstraint->IsDimension() && apConstraint->GetValue()->IsCaptured()) {
195 if (originColor.Name() != Quantity_NOC_PURPLE)
196 anAISObject->SetColor(Quantity_NOC_PURPLE);
198 else if (!apConstraint->IsPlanar() && (originColor.Name() != Quantity_NOC_YELLOW))
199 anAISObject->SetColor(Quantity_NOC_YELLOW);
202 if (!apConstraint->Verified()) {
203 anAISObject->SetColor(Quantity_NOC_RED);
205 else if (apConstraint->IsDimension() && apConstraint->GetValue()->IsCaptured()) {
206 anAISObject->SetColor(Quantity_NOC_PURPLE);
208 else if (!apConstraint->IsPlanar()) anAISObject->SetColor(Quantity_NOC_YELLOW);
210 return Standard_True;