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_Type.hxx>
19 #include <TDataStd_Real.hxx>
20 #include <TDataXtd_Constraint.hxx>
21 #include <TDataXtd_Position.hxx>
22 #include <TDF_Label.hxx>
23 #include <TPrsStd_ConstraintDriver.hxx>
24 #include <TPrsStd_ConstraintTools.hxx>
26 IMPLEMENT_STANDARD_RTTIEXT(TPrsStd_ConstraintDriver,TPrsStd_Driver)
28 //=======================================================================
31 //=======================================================================
32 TPrsStd_ConstraintDriver::TPrsStd_ConstraintDriver()
36 //=======================================================================
39 //=======================================================================
40 Standard_Boolean TPrsStd_ConstraintDriver::Update (const TDF_Label& aLabel,
41 Handle(AIS_InteractiveObject)& anAISObject)
43 Handle(TDataXtd_Constraint) apConstraint;
44 if( !aLabel.FindAttribute(TDataXtd_Constraint::GetID(), apConstraint) ) {
45 return Standard_False;
48 if (!anAISObject.IsNull() && anAISObject->HasInteractiveContext()) {
49 if (!apConstraint->Verified()) {
50 TPrsStd_ConstraintTools::UpdateOnlyValue(apConstraint,anAISObject);
51 Quantity_Color aColor;
52 anAISObject->Color (aColor);
53 if (aColor.Name() != Quantity_NOC_RED)
55 anAISObject->SetColor(Quantity_NOC_RED);
61 Handle(AIS_InteractiveObject) anAIS = anAISObject;
64 TDataXtd_ConstraintEnum thetype = apConstraint->GetType();
67 case TDataXtd_DISTANCE:
69 TPrsStd_ConstraintTools::ComputeDistance(apConstraint,anAIS);
72 case TDataXtd_PARALLEL:
74 TPrsStd_ConstraintTools::ComputeParallel(apConstraint,anAIS);
77 case TDataXtd_PERPENDICULAR:
79 TPrsStd_ConstraintTools::ComputePerpendicular(apConstraint,anAIS);
82 case TDataXtd_CONCENTRIC:
84 TPrsStd_ConstraintTools::ComputeConcentric(apConstraint,anAIS);
87 case TDataXtd_SYMMETRY:
89 TPrsStd_ConstraintTools::ComputeSymmetry(apConstraint,anAIS);
92 case TDataXtd_MIDPOINT:
94 TPrsStd_ConstraintTools::ComputeMidPoint(apConstraint,anAIS);
97 case TDataXtd_TANGENT:
99 TPrsStd_ConstraintTools::ComputeTangent(apConstraint,anAIS);
104 TPrsStd_ConstraintTools::ComputeAngle(apConstraint,anAIS);
107 case TDataXtd_RADIUS:
109 TPrsStd_ConstraintTools::ComputeRadius(apConstraint,anAIS);
112 case TDataXtd_MINOR_RADIUS:
114 TPrsStd_ConstraintTools::ComputeMinRadius(apConstraint,anAIS);
117 case TDataXtd_MAJOR_RADIUS:
119 TPrsStd_ConstraintTools::ComputeMaxRadius(apConstraint,anAIS);
122 case TDataXtd_DIAMETER:
124 TPrsStd_ConstraintTools::ComputeDiameter(apConstraint,anAIS);
129 TPrsStd_ConstraintTools::ComputeFix(apConstraint,anAIS);
132 case TDataXtd_OFFSET:
134 TPrsStd_ConstraintTools::ComputeOffset(apConstraint,anAIS);
137 case TDataXtd_COINCIDENT:
139 TPrsStd_ConstraintTools::ComputeCoincident(apConstraint,anAIS);
144 TPrsStd_ConstraintTools::ComputeRound(apConstraint,anAIS);
149 case TDataXtd_ALIGN_FACES:
150 case TDataXtd_ALIGN_AXES:
151 case TDataXtd_AXES_ANGLE:
153 TPrsStd_ConstraintTools::ComputePlacement(apConstraint,anAIS);
156 case TDataXtd_EQUAL_DISTANCE :
158 TPrsStd_ConstraintTools::ComputeEqualDistance(apConstraint,anAIS);
161 case TDataXtd_EQUAL_RADIUS:
163 TPrsStd_ConstraintTools::ComputeEqualRadius(apConstraint,anAIS);
168 TPrsStd_ConstraintTools::ComputeOthers(apConstraint,anAIS);
172 if (anAIS.IsNull()) return Standard_False;
174 anAIS->ResetTransformation();
175 anAIS->SetToUpdate();
176 anAIS->UpdateSelection();
180 Handle(TDataXtd_Position) Position;
181 if (aLabel.FindAttribute(TDataXtd_Position::GetID(),Position)) {
182 Handle(PrsDim_Relation)::DownCast(anAISObject)->SetPosition(Position->GetPosition());
185 if (anAISObject->HasInteractiveContext()) {
186 Quantity_Color originColor;
187 anAISObject->Color (originColor);
188 if (!apConstraint->Verified()) {
189 if (originColor.Name() != Quantity_NOC_RED)
190 anAISObject->SetColor(Quantity_NOC_RED);
192 else if (apConstraint->IsDimension() && apConstraint->GetValue()->IsCaptured()) {
193 if (originColor.Name() != Quantity_NOC_PURPLE)
194 anAISObject->SetColor(Quantity_NOC_PURPLE);
196 else if (!apConstraint->IsPlanar() && (originColor.Name() != Quantity_NOC_YELLOW))
197 anAISObject->SetColor(Quantity_NOC_YELLOW);
200 if (!apConstraint->Verified()) {
201 anAISObject->SetColor(Quantity_NOC_RED);
203 else if (apConstraint->IsDimension() && apConstraint->GetValue()->IsCaptured()) {
204 anAISObject->SetColor(Quantity_NOC_PURPLE);
206 else if (!apConstraint->IsPlanar()) anAISObject->SetColor(Quantity_NOC_YELLOW);
208 return Standard_True;