625e1958 |
1 | // Created on: 2015-12-23 |
2 | // Created by: Anastasia BORISOVA |
3 | // Copyright (c) 2015 OPEN CASCADE SAS |
4 | // |
5 | // This file is part of Open CASCADE Technology software library. |
6 | // |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
12 | // |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
15 | |
16 | #include <AIS_Manipulator.hxx> |
17 | |
18 | #include <AIS_InteractiveContext.hxx> |
19 | #include <AIS_ManipulatorOwner.hxx> |
12280e4b |
20 | #include <Extrema_ExtElC.hxx> |
625e1958 |
21 | #include <gce_MakeDir.hxx> |
12280e4b |
22 | #include <IntAna_IntConicQuad.hxx> |
62ef08df |
23 | #include <Prs3d_Arrow.hxx> |
625e1958 |
24 | #include <Prs3d_ShadingAspect.hxx> |
62ef08df |
25 | #include <Prs3d_ToolDisk.hxx> |
f522ce50 |
26 | #include <Prs3d_ToolSector.hxx> |
62ef08df |
27 | #include <Prs3d_ToolSphere.hxx> |
625e1958 |
28 | #include <Select3D_SensitiveCircle.hxx> |
29 | #include <Select3D_SensitivePoint.hxx> |
30 | #include <Select3D_SensitiveSegment.hxx> |
31 | #include <Select3D_SensitiveTriangulation.hxx> |
62ef08df |
32 | #include <Select3D_SensitivePrimitiveArray.hxx> |
625e1958 |
33 | #include <SelectMgr_SequenceOfOwner.hxx> |
625e1958 |
34 | #include <TColgp_Array1OfPnt.hxx> |
35 | #include <V3d_View.hxx> |
36 | |
37 | IMPLEMENT_STANDARD_HANDLE (AIS_Manipulator, AIS_InteractiveObject) |
38 | IMPLEMENT_STANDARD_RTTIEXT(AIS_Manipulator, AIS_InteractiveObject) |
39 | |
40 | IMPLEMENT_HSEQUENCE(AIS_ManipulatorObjectSequence) |
41 | |
3ed88fac |
42 | namespace |
43 | { |
44 | //! Return Ax1 for specified direction of Ax2. |
45 | static gp_Ax1 getAx1FromAx2Dir (const gp_Ax2& theAx2, |
46 | int theIndex) |
47 | { |
48 | switch (theIndex) |
49 | { |
50 | case 0: return gp_Ax1 (theAx2.Location(), theAx2.XDirection()); |
51 | case 1: return gp_Ax1 (theAx2.Location(), theAx2.YDirection()); |
52 | case 2: return theAx2.Axis(); |
53 | } |
54 | throw Standard_ProgramError ("AIS_Manipulator - Invalid axis index"); |
55 | } |
b11aef43 |
56 | |
57 | //! Auxiliary tool for filtering picking ray. |
58 | class ManipSensRotation |
59 | { |
60 | public: |
61 | //! Main constructor. |
62 | ManipSensRotation (const gp_Dir& thePlaneNormal) : myPlaneNormal (thePlaneNormal), myAngleTol (10.0 * M_PI / 180.0) {} |
63 | |
64 | //! Checks if picking ray can be used for detection. |
65 | Standard_Boolean isValidRay (const SelectBasics_SelectingVolumeManager& theMgr) const |
66 | { |
67 | if (theMgr.GetActiveSelectionType() != SelectBasics_SelectingVolumeManager::Point) |
68 | { |
69 | return Standard_False; |
70 | } |
71 | |
72 | const gp_Vec aRay (theMgr.GetNearPickedPnt(), theMgr.GetFarPickedPnt()); |
73 | return !aRay.IsNormal (myPlaneNormal, myAngleTol); |
74 | } |
75 | private: |
76 | gp_Dir myPlaneNormal; |
77 | Standard_Real myAngleTol; |
78 | }; |
79 | |
80 | //! Sensitive circle with filtering picking ray. |
81 | class ManipSensCircle : public Select3D_SensitiveCircle, public ManipSensRotation |
82 | { |
83 | public: |
84 | //! Main constructor. |
0ef04197 |
85 | ManipSensCircle (const Handle(SelectMgr_EntityOwner)& theOwnerId, |
7f24b768 |
86 | const gp_Circ& theCircle, |
b11aef43 |
87 | const Standard_Integer theNbPnts) |
88 | : Select3D_SensitiveCircle (theOwnerId, theCircle, Standard_False, theNbPnts), |
7f24b768 |
89 | ManipSensRotation (theCircle.Position().Direction()) {} |
b11aef43 |
90 | |
91 | //! Checks whether the circle overlaps current selecting volume |
92 | virtual Standard_Boolean Matches (SelectBasics_SelectingVolumeManager& theMgr, |
93 | SelectBasics_PickResult& thePickResult) Standard_OVERRIDE |
94 | { |
95 | return isValidRay (theMgr) |
96 | && Select3D_SensitiveCircle::Matches (theMgr, thePickResult); |
97 | } |
98 | }; |
99 | |
100 | //! Sensitive triangulation with filtering picking ray. |
101 | class ManipSensTriangulation : public Select3D_SensitiveTriangulation, public ManipSensRotation |
102 | { |
103 | public: |
0ef04197 |
104 | ManipSensTriangulation (const Handle(SelectMgr_EntityOwner)& theOwnerId, |
b11aef43 |
105 | const Handle(Poly_Triangulation)& theTrg, |
106 | const gp_Dir& thePlaneNormal) |
107 | : Select3D_SensitiveTriangulation (theOwnerId, theTrg, TopLoc_Location(), Standard_True), |
108 | ManipSensRotation (thePlaneNormal) {} |
109 | |
110 | //! Checks whether the circle overlaps current selecting volume |
111 | virtual Standard_Boolean Matches (SelectBasics_SelectingVolumeManager& theMgr, |
112 | SelectBasics_PickResult& thePickResult) Standard_OVERRIDE |
113 | { |
114 | return isValidRay (theMgr) |
115 | && Select3D_SensitiveTriangulation::Matches (theMgr, thePickResult); |
116 | } |
117 | }; |
3ed88fac |
118 | } |
119 | |
625e1958 |
120 | //======================================================================= |
121 | //function : init |
122 | //purpose : |
123 | //======================================================================= |
124 | void AIS_Manipulator::init() |
125 | { |
126 | // Create axis in the default coordinate system. The custom position is applied in local transformation. |
127 | myAxes[0] = Axis (gp::OX(), Quantity_NOC_RED); |
128 | myAxes[1] = Axis (gp::OY(), Quantity_NOC_GREEN); |
129 | myAxes[2] = Axis (gp::OZ(), Quantity_NOC_BLUE1); |
130 | |
131 | Graphic3d_MaterialAspect aShadingMaterial; |
61168418 |
132 | aShadingMaterial.SetSpecularColor(Quantity_NOC_BLACK); |
625e1958 |
133 | aShadingMaterial.SetMaterialType (Graphic3d_MATERIAL_ASPECT); |
134 | |
135 | myDrawer->SetShadingAspect (new Prs3d_ShadingAspect()); |
136 | myDrawer->ShadingAspect()->Aspect()->SetInteriorStyle (Aspect_IS_SOLID); |
137 | myDrawer->ShadingAspect()->SetColor (Quantity_NOC_WHITE); |
138 | myDrawer->ShadingAspect()->SetMaterial (aShadingMaterial); |
139 | |
140 | Graphic3d_MaterialAspect aHilightMaterial; |
141 | aHilightMaterial.SetColor (Quantity_NOC_AZURE); |
61168418 |
142 | aHilightMaterial.SetAmbientColor (Quantity_NOC_BLACK); |
143 | aHilightMaterial.SetDiffuseColor (Quantity_NOC_BLACK); |
144 | aHilightMaterial.SetSpecularColor(Quantity_NOC_BLACK); |
145 | aHilightMaterial.SetEmissiveColor(Quantity_NOC_BLACK); |
625e1958 |
146 | aHilightMaterial.SetMaterialType (Graphic3d_MATERIAL_ASPECT); |
147 | |
148 | myHighlightAspect = new Prs3d_ShadingAspect(); |
149 | myHighlightAspect->Aspect()->SetInteriorStyle (Aspect_IS_SOLID); |
150 | myHighlightAspect->SetMaterial (aHilightMaterial); |
151 | |
f522ce50 |
152 | Graphic3d_MaterialAspect aDraggerMaterial; |
61168418 |
153 | aDraggerMaterial.SetAmbientColor (Quantity_NOC_BLACK); |
154 | aDraggerMaterial.SetDiffuseColor (Quantity_NOC_BLACK); |
155 | aDraggerMaterial.SetSpecularColor(Quantity_NOC_BLACK); |
f522ce50 |
156 | aDraggerMaterial.SetMaterialType(Graphic3d_MATERIAL_ASPECT); |
f522ce50 |
157 | |
158 | myDraggerHighlight = new Prs3d_ShadingAspect(); |
159 | myDraggerHighlight->Aspect()->SetInteriorStyle(Aspect_IS_SOLID); |
160 | myDraggerHighlight->SetMaterial(aDraggerMaterial); |
161 | |
162 | myDraggerHighlight->SetTransparency(0.5); |
163 | |
625e1958 |
164 | SetSize (100); |
165 | SetZLayer (Graphic3d_ZLayerId_Topmost); |
166 | } |
167 | |
168 | //======================================================================= |
169 | //function : getHighlightPresentation |
170 | //purpose : |
171 | //======================================================================= |
172 | Handle(Prs3d_Presentation) AIS_Manipulator::getHighlightPresentation (const Handle(SelectMgr_EntityOwner)& theOwner) const |
173 | { |
174 | Handle(Prs3d_Presentation) aDummyPrs; |
175 | Handle(AIS_ManipulatorOwner) anOwner = Handle(AIS_ManipulatorOwner)::DownCast (theOwner); |
176 | if (anOwner.IsNull()) |
177 | { |
178 | return aDummyPrs; |
179 | } |
180 | |
181 | switch (anOwner->Mode()) |
182 | { |
f522ce50 |
183 | case AIS_MM_Translation : return myAxes[anOwner->Index()].TranslatorHighlightPrs(); |
184 | case AIS_MM_Rotation : return myAxes[anOwner->Index()].RotatorHighlightPrs(); |
185 | case AIS_MM_Scaling : return myAxes[anOwner->Index()].ScalerHighlightPrs(); |
186 | case AIS_MM_TranslationPlane: return myAxes[anOwner->Index()].DraggerHighlightPrs(); |
187 | case AIS_MM_None : break; |
625e1958 |
188 | } |
189 | |
190 | return aDummyPrs; |
191 | } |
192 | |
193 | //======================================================================= |
194 | //function : getGroup |
195 | //purpose : |
196 | //======================================================================= |
197 | Handle(Graphic3d_Group) AIS_Manipulator::getGroup (const Standard_Integer theIndex, const AIS_ManipulatorMode theMode) const |
198 | { |
199 | Handle(Graphic3d_Group) aDummyGroup; |
200 | |
201 | if (theIndex < 0 || theIndex > 2) |
202 | { |
203 | return aDummyGroup; |
204 | } |
205 | |
206 | switch (theMode) |
207 | { |
f522ce50 |
208 | case AIS_MM_Translation : return myAxes[theIndex].TranslatorGroup(); |
209 | case AIS_MM_Rotation : return myAxes[theIndex].RotatorGroup(); |
210 | case AIS_MM_Scaling : return myAxes[theIndex].ScalerGroup(); |
211 | case AIS_MM_TranslationPlane: return myAxes[theIndex].DraggerGroup(); |
212 | case AIS_MM_None : break; |
625e1958 |
213 | } |
214 | |
215 | return aDummyGroup; |
216 | } |
217 | |
218 | //======================================================================= |
219 | //function : Constructor |
220 | //purpose : |
221 | //======================================================================= |
222 | AIS_Manipulator::AIS_Manipulator() |
223 | : myPosition (gp::XOY()), |
224 | myCurrentIndex (-1), |
225 | myCurrentMode (AIS_MM_None), |
226 | myIsActivationOnDetection (Standard_False), |
227 | myIsZoomPersistentMode (Standard_True), |
228 | myHasStartedTransformation (Standard_False), |
229 | myStartPosition (gp::XOY()), |
230 | myStartPick (0.0, 0.0, 0.0), |
231 | myPrevState (0.0) |
232 | { |
233 | SetInfiniteState(); |
234 | SetMutable (Standard_True); |
235 | SetDisplayMode (AIS_Shaded); |
236 | init(); |
237 | } |
238 | |
239 | //======================================================================= |
240 | //function : Constructor |
241 | //purpose : |
242 | //======================================================================= |
243 | AIS_Manipulator::AIS_Manipulator (const gp_Ax2& thePosition) |
244 | : myPosition (thePosition), |
245 | myCurrentIndex (-1), |
246 | myCurrentMode (AIS_MM_None), |
247 | myIsActivationOnDetection (Standard_False), |
248 | myIsZoomPersistentMode (Standard_True), |
249 | myHasStartedTransformation (Standard_False), |
250 | myStartPosition (gp::XOY()), |
251 | myStartPick (0.0, 0.0, 0.0), |
252 | myPrevState (0.0) |
253 | { |
254 | SetInfiniteState(); |
255 | SetMutable (Standard_True); |
256 | SetDisplayMode (AIS_Shaded); |
257 | init(); |
258 | } |
259 | |
260 | //======================================================================= |
261 | //function : SetPart |
262 | //purpose : |
263 | //======================================================================= |
264 | void AIS_Manipulator::SetPart (const Standard_Integer theAxisIndex, const AIS_ManipulatorMode theMode, const Standard_Boolean theIsEnabled) |
265 | { |
266 | Standard_ProgramError_Raise_if (theAxisIndex < 0 || theAxisIndex > 2, "AIS_Manipulator::SetMode(): axis index should be between 0 and 2"); |
267 | switch (theMode) |
268 | { |
269 | case AIS_MM_Translation: |
270 | myAxes[theAxisIndex].SetTranslation (theIsEnabled); |
271 | break; |
272 | |
273 | case AIS_MM_Rotation: |
274 | myAxes[theAxisIndex].SetRotation (theIsEnabled); |
275 | break; |
276 | |
277 | case AIS_MM_Scaling: |
278 | myAxes[theAxisIndex].SetScaling (theIsEnabled); |
279 | break; |
280 | |
f522ce50 |
281 | case AIS_MM_TranslationPlane: |
282 | myAxes[theAxisIndex].SetDragging(theIsEnabled); |
283 | break; |
284 | |
625e1958 |
285 | case AIS_MM_None: |
286 | break; |
287 | } |
288 | } |
289 | |
f15c5f90 |
290 | //======================================================================= |
291 | //function : SetPart |
292 | //purpose : |
293 | //======================================================================= |
294 | void AIS_Manipulator::SetPart (const AIS_ManipulatorMode theMode, const Standard_Boolean theIsEnabled) |
295 | { |
84b904bc |
296 | for (Standard_Integer anIt = 0; anIt < 3; ++anIt) |
f15c5f90 |
297 | { |
298 | SetPart (anIt, theMode, theIsEnabled); |
299 | } |
300 | } |
301 | |
625e1958 |
302 | //======================================================================= |
303 | //function : EnableMode |
304 | //purpose : |
305 | //======================================================================= |
306 | void AIS_Manipulator::EnableMode (const AIS_ManipulatorMode theMode) |
307 | { |
308 | if (!IsAttached()) |
309 | { |
310 | return; |
311 | } |
312 | |
313 | const Handle(AIS_InteractiveContext)& aContext = GetContext(); |
314 | if (aContext.IsNull()) |
315 | { |
316 | return; |
317 | } |
318 | |
319 | aContext->Activate (this, theMode); |
320 | } |
321 | |
322 | //======================================================================= |
323 | //function : attachToBox |
324 | //purpose : |
325 | //======================================================================= |
326 | void AIS_Manipulator::attachToBox (const Bnd_Box& theBox) |
327 | { |
328 | if (theBox.IsVoid()) |
329 | { |
330 | return; |
331 | } |
332 | |
333 | Standard_Real anXmin = 0.0, anYmin = 0.0, aZmin = 0.0, anXmax = 0.0, anYmax = 0.0, aZmax = 0.0; |
334 | theBox.Get (anXmin, anYmin, aZmin, anXmax, anYmax, aZmax); |
335 | |
336 | gp_Ax2 aPosition = gp::XOY(); |
337 | aPosition.SetLocation (gp_Pnt ((anXmin + anXmax) * 0.5, (anYmin + anYmax) * 0.5, (aZmin + aZmax) * 0.5)); |
338 | SetPosition (aPosition); |
339 | } |
340 | |
341 | //======================================================================= |
342 | //function : adjustSize |
343 | //purpose : |
344 | //======================================================================= |
345 | void AIS_Manipulator::adjustSize (const Bnd_Box& theBox) |
346 | { |
347 | Standard_Real aXmin = 0., aYmin = 0., aZmin = 0., aXmax = 0., aYmax = 0., aZmax = 0.0; |
348 | theBox.Get (aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); |
349 | Standard_Real aXSize = aXmax - aXmin; |
350 | Standard_Real aYSize = aYmax - aYmin; |
351 | Standard_Real aZSize = aZmax - aZmin; |
352 | |
353 | SetSize ((Standard_ShortReal) (Max (aXSize, Max (aYSize, aZSize)) * 0.5)); |
354 | } |
355 | |
356 | //======================================================================= |
357 | //function : Attach |
358 | //purpose : |
359 | //======================================================================= |
360 | void AIS_Manipulator::Attach (const Handle(AIS_InteractiveObject)& theObject, const OptionsForAttach& theOptions) |
361 | { |
362 | if (theObject->IsKind (STANDARD_TYPE(AIS_Manipulator))) |
363 | { |
364 | return; |
365 | } |
366 | |
367 | Handle(AIS_ManipulatorObjectSequence) aSeq = new AIS_ManipulatorObjectSequence(); |
368 | aSeq->Append (theObject); |
369 | Attach (aSeq, theOptions); |
370 | } |
371 | |
372 | //======================================================================= |
373 | //function : Attach |
374 | //purpose : |
375 | //======================================================================= |
376 | void AIS_Manipulator::Attach (const Handle(AIS_ManipulatorObjectSequence)& theObjects, const OptionsForAttach& theOptions) |
377 | { |
378 | if (theObjects->Size() < 1) |
379 | { |
380 | return; |
381 | } |
382 | |
383 | SetOwner (theObjects); |
384 | Bnd_Box aBox; |
385 | const Handle(AIS_InteractiveObject)& aCurObject = theObjects->Value (theObjects->Lower()); |
386 | aCurObject->BoundingBox (aBox); |
387 | |
388 | if (theOptions.AdjustPosition) |
389 | { |
390 | attachToBox (aBox); |
391 | } |
392 | |
393 | if (theOptions.AdjustSize) |
394 | { |
395 | adjustSize (aBox); |
396 | } |
397 | |
398 | const Handle(AIS_InteractiveContext)& aContext = Object()->GetContext(); |
399 | if (!aContext.IsNull()) |
400 | { |
401 | if (!aContext->IsDisplayed (this)) |
402 | { |
403 | aContext->Display (this, Standard_False); |
404 | } |
405 | else |
406 | { |
407 | aContext->Update (this, Standard_False); |
408 | aContext->RecomputeSelectionOnly (this); |
409 | } |
410 | |
411 | aContext->Load (this); |
625e1958 |
412 | } |
413 | |
414 | if (theOptions.EnableModes) |
415 | { |
416 | EnableMode (AIS_MM_Rotation); |
417 | EnableMode (AIS_MM_Translation); |
418 | EnableMode (AIS_MM_Scaling); |
f522ce50 |
419 | EnableMode (AIS_MM_TranslationPlane); |
625e1958 |
420 | } |
421 | } |
422 | |
423 | //======================================================================= |
424 | //function : Detach |
425 | //purpose : |
426 | //======================================================================= |
427 | void AIS_Manipulator::Detach() |
428 | { |
429 | DeactivateCurrentMode(); |
430 | |
431 | if (!IsAttached()) |
432 | { |
433 | return; |
434 | } |
435 | |
436 | Handle(AIS_InteractiveObject) anObject = Object(); |
437 | const Handle(AIS_InteractiveContext)& aContext = anObject->GetContext(); |
438 | if (!aContext.IsNull()) |
439 | { |
440 | aContext->Remove (this, Standard_False); |
441 | } |
442 | |
443 | SetOwner (NULL); |
444 | } |
445 | |
446 | //======================================================================= |
447 | //function : Objects |
448 | //purpose : |
449 | //======================================================================= |
450 | Handle(AIS_ManipulatorObjectSequence) AIS_Manipulator::Objects() const |
451 | { |
452 | return Handle(AIS_ManipulatorObjectSequence)::DownCast (GetOwner()); |
453 | } |
454 | |
455 | //======================================================================= |
456 | //function : Object |
457 | //purpose : |
458 | //======================================================================= |
459 | Handle(AIS_InteractiveObject) AIS_Manipulator::Object (const Standard_Integer theIndex) const |
460 | { |
461 | Handle(AIS_ManipulatorObjectSequence) anOwner = Handle(AIS_ManipulatorObjectSequence)::DownCast (GetOwner()); |
462 | |
463 | Standard_ProgramError_Raise_if (theIndex < anOwner->Lower() || theIndex > anOwner->Upper(), "AIS_Manipulator::Object(): wrong index value"); |
464 | |
465 | if (anOwner.IsNull() || anOwner->IsEmpty()) |
466 | { |
467 | return NULL; |
468 | } |
469 | |
470 | return anOwner->Value (theIndex); |
471 | } |
472 | |
473 | //======================================================================= |
474 | //function : Object |
475 | //purpose : |
476 | //======================================================================= |
477 | Handle(AIS_InteractiveObject) AIS_Manipulator::Object() const |
478 | { |
479 | return Object (1); |
480 | } |
481 | |
482 | //======================================================================= |
483 | //function : ObjectTransformation |
484 | //purpose : |
485 | //======================================================================= |
486 | Standard_Boolean AIS_Manipulator::ObjectTransformation (const Standard_Integer theMaxX, const Standard_Integer theMaxY, |
487 | const Handle(V3d_View)& theView, gp_Trsf& theTrsf) |
488 | { |
489 | // Initialize start reference data |
490 | if (!myHasStartedTransformation) |
491 | { |
625e1958 |
492 | myStartTrsfs.Clear(); |
3ed88fac |
493 | Handle(AIS_ManipulatorObjectSequence) anObjects = Objects(); |
494 | for (AIS_ManipulatorObjectSequence::Iterator anObjIter (*anObjects); anObjIter.More(); anObjIter.Next()) |
625e1958 |
495 | { |
3ed88fac |
496 | myStartTrsfs.Append (anObjIter.Value()->LocalTransformation()); |
625e1958 |
497 | } |
498 | myStartPosition = myPosition; |
499 | } |
500 | |
501 | // Get 3d point with projection vector |
3ed88fac |
502 | Graphic3d_Vec3d anInputPoint, aProj; |
625e1958 |
503 | theView->ConvertWithProj (theMaxX, theMaxY, anInputPoint.x(), anInputPoint.y(), anInputPoint.z(), aProj.x(), aProj.y(), aProj.z()); |
3ed88fac |
504 | const gp_Lin anInputLine (gp_Pnt (anInputPoint.x(), anInputPoint.y(), anInputPoint.z()), gp_Dir (aProj.x(), aProj.y(), aProj.z())); |
625e1958 |
505 | switch (myCurrentMode) |
506 | { |
507 | case AIS_MM_Translation: |
12280e4b |
508 | case AIS_MM_Scaling: |
625e1958 |
509 | { |
12280e4b |
510 | const gp_Lin aLine (myStartPosition.Location(), myAxes[myCurrentIndex].Position().Direction()); |
511 | Extrema_ExtElC anExtrema (anInputLine, aLine, Precision::Angular()); |
512 | if (!anExtrema.IsDone() |
5ac0f989 |
513 | || anExtrema.IsParallel() |
12280e4b |
514 | || anExtrema.NbExt() != 1) |
515 | { |
516 | // translation cannot be done co-directed with camera |
517 | return Standard_False; |
518 | } |
625e1958 |
519 | |
12280e4b |
520 | Extrema_POnCurv anExPnts[2]; |
521 | anExtrema.Points (1, anExPnts[0], anExPnts[1]); |
522 | const gp_Pnt aNewPosition = anExPnts[1].Value(); |
625e1958 |
523 | if (!myHasStartedTransformation) |
524 | { |
525 | myStartPick = aNewPosition; |
526 | myHasStartedTransformation = Standard_True; |
527 | return Standard_True; |
528 | } |
12280e4b |
529 | else if (aNewPosition.Distance (myStartPick) < Precision::Confusion()) |
625e1958 |
530 | { |
531 | return Standard_False; |
532 | } |
533 | |
534 | gp_Trsf aNewTrsf; |
12280e4b |
535 | if (myCurrentMode == AIS_MM_Translation) |
536 | { |
537 | aNewTrsf.SetTranslation (gp_Vec(myStartPick, aNewPosition)); |
538 | theTrsf *= aNewTrsf; |
539 | } |
540 | else if (myCurrentMode == AIS_MM_Scaling) |
541 | { |
542 | if (aNewPosition.Distance (myStartPosition.Location()) < Precision::Confusion()) |
543 | { |
544 | return Standard_False; |
545 | } |
546 | |
547 | Standard_Real aCoeff = myStartPosition.Location().Distance (aNewPosition) |
548 | / myStartPosition.Location().Distance (myStartPick); |
549 | aNewTrsf.SetScale (myPosition.Location(), aCoeff); |
550 | theTrsf = aNewTrsf; |
551 | } |
3ed88fac |
552 | return Standard_True; |
625e1958 |
553 | } |
554 | case AIS_MM_Rotation: |
555 | { |
3ed88fac |
556 | const gp_Pnt aPosLoc = myStartPosition.Location(); |
557 | const gp_Ax1 aCurrAxis = getAx1FromAx2Dir (myStartPosition, myCurrentIndex); |
12280e4b |
558 | IntAna_IntConicQuad aIntersector (anInputLine, gp_Pln (aPosLoc, aCurrAxis.Direction()), Precision::Angular(), Precision::Intersection()); |
5ac0f989 |
559 | if (!aIntersector.IsDone() |
560 | || aIntersector.IsParallel() |
561 | || aIntersector.NbPoints() < 1) |
625e1958 |
562 | { |
563 | return Standard_False; |
564 | } |
565 | |
3ed88fac |
566 | const gp_Pnt aNewPosition = aIntersector.Point (1); |
625e1958 |
567 | if (!myHasStartedTransformation) |
568 | { |
569 | myStartPick = aNewPosition; |
570 | myHasStartedTransformation = Standard_True; |
3ed88fac |
571 | gp_Dir aStartAxis = gce_MakeDir (aPosLoc, myStartPick); |
572 | myPrevState = aStartAxis.AngleWithRef (gce_MakeDir(aPosLoc, aNewPosition), aCurrAxis.Direction()); |
625e1958 |
573 | return Standard_True; |
574 | } |
575 | |
576 | if (aNewPosition.Distance (myStartPick) < Precision::Confusion()) |
577 | { |
578 | return Standard_False; |
579 | } |
580 | |
3ed88fac |
581 | gp_Dir aStartAxis = aPosLoc.IsEqual (myStartPick, Precision::Confusion()) |
582 | ? getAx1FromAx2Dir (myStartPosition, (myCurrentIndex + 1) % 3).Direction() |
583 | : gce_MakeDir (aPosLoc, myStartPick); |
625e1958 |
584 | |
3ed88fac |
585 | gp_Dir aCurrentAxis = gce_MakeDir (aPosLoc, aNewPosition); |
586 | Standard_Real anAngle = aStartAxis.AngleWithRef (aCurrentAxis, aCurrAxis.Direction()); |
625e1958 |
587 | |
588 | // Change value of an angle if it should have different sign. |
589 | if (anAngle * myPrevState < 0 && Abs (anAngle) < M_PI_2) |
590 | { |
3ed88fac |
591 | Standard_Real aSign = myPrevState > 0 ? -1.0 : 1.0; |
625e1958 |
592 | anAngle = aSign * (M_PI * 2 - anAngle); |
593 | } |
594 | |
595 | if (Abs (anAngle) < Precision::Confusion()) |
596 | { |
597 | return Standard_False; |
598 | } |
599 | |
600 | gp_Trsf aNewTrsf; |
3ed88fac |
601 | aNewTrsf.SetRotation (aCurrAxis, anAngle); |
625e1958 |
602 | theTrsf *= aNewTrsf; |
603 | myPrevState = anAngle; |
3ed88fac |
604 | return Standard_True; |
625e1958 |
605 | } |
f522ce50 |
606 | case AIS_MM_TranslationPlane: |
607 | { |
608 | const gp_Pnt aPosLoc = myStartPosition.Location(); |
609 | const gp_Ax1 aCurrAxis = getAx1FromAx2Dir(myStartPosition, myCurrentIndex); |
610 | IntAna_IntConicQuad aIntersector(anInputLine, gp_Pln(aPosLoc, aCurrAxis.Direction()), Precision::Angular(), Precision::Intersection()); |
611 | if (!aIntersector.IsDone() || aIntersector.NbPoints() < 1) |
612 | { |
613 | return Standard_False; |
614 | } |
615 | |
616 | const gp_Pnt aNewPosition = aIntersector.Point(1); |
617 | if (!myHasStartedTransformation) |
618 | { |
619 | myStartPick = aNewPosition; |
620 | myHasStartedTransformation = Standard_True; |
621 | return Standard_True; |
622 | } |
623 | |
624 | if (aNewPosition.Distance(myStartPick) < Precision::Confusion()) |
625 | { |
626 | return Standard_False; |
627 | } |
628 | |
629 | gp_Trsf aNewTrsf; |
630 | aNewTrsf.SetTranslation(gp_Vec(myStartPick, aNewPosition)); |
631 | theTrsf *= aNewTrsf; |
632 | return Standard_True; |
633 | } |
625e1958 |
634 | case AIS_MM_None: |
3ed88fac |
635 | { |
625e1958 |
636 | return Standard_False; |
3ed88fac |
637 | } |
625e1958 |
638 | } |
3ed88fac |
639 | return Standard_False; |
625e1958 |
640 | } |
641 | |
642 | //======================================================================= |
643 | //function : StartTransform |
644 | //purpose : |
645 | //======================================================================= |
646 | void AIS_Manipulator::StartTransform (const Standard_Integer theX, const Standard_Integer theY, const Handle(V3d_View)& theView) |
647 | { |
648 | if (myHasStartedTransformation) |
649 | { |
650 | return; |
651 | } |
652 | |
653 | gp_Trsf aTrsf; |
654 | ObjectTransformation (theX, theY, theView, aTrsf); |
655 | } |
656 | |
657 | //======================================================================= |
658 | //function : StopTransform |
659 | //purpose : |
660 | //======================================================================= |
661 | void AIS_Manipulator::StopTransform (const Standard_Boolean theToApply) |
662 | { |
663 | if (!IsAttached() || !myHasStartedTransformation) |
664 | { |
665 | return; |
666 | } |
667 | |
668 | myHasStartedTransformation = Standard_False; |
3ed88fac |
669 | if (theToApply) |
625e1958 |
670 | { |
3ed88fac |
671 | return; |
672 | } |
625e1958 |
673 | |
3ed88fac |
674 | Handle(AIS_ManipulatorObjectSequence) anObjects = Objects(); |
675 | AIS_ManipulatorObjectSequence::Iterator anObjIter (*anObjects); |
676 | NCollection_Sequence<gp_Trsf>::Iterator aTrsfIter (myStartTrsfs); |
677 | for (; anObjIter.More(); anObjIter.Next(), aTrsfIter.Next()) |
678 | { |
679 | anObjIter.ChangeValue()->SetLocalTransformation (aTrsfIter.Value()); |
625e1958 |
680 | } |
3ed88fac |
681 | SetPosition (myStartPosition); |
625e1958 |
682 | } |
683 | |
684 | //======================================================================= |
685 | //function : Transform |
686 | //purpose : |
687 | //======================================================================= |
688 | void AIS_Manipulator::Transform (const gp_Trsf& theTrsf) |
689 | { |
690 | if (!IsAttached() || !myHasStartedTransformation) |
691 | { |
692 | return; |
693 | } |
694 | |
625e1958 |
695 | { |
3ed88fac |
696 | Handle(AIS_ManipulatorObjectSequence) anObjects = Objects(); |
697 | AIS_ManipulatorObjectSequence::Iterator anObjIter (*anObjects); |
698 | NCollection_Sequence<gp_Trsf>::Iterator aTrsfIter (myStartTrsfs); |
699 | for (; anObjIter.More(); anObjIter.Next(), aTrsfIter.Next()) |
700 | { |
245cbf94 |
701 | const Handle(AIS_InteractiveObject)& anObj = anObjIter.ChangeValue(); |
702 | const gp_Trsf& anOldTrsf = aTrsfIter.Value(); |
7f24b768 |
703 | const Handle(TopLoc_Datum3D)& aParentTrsf = anObj->CombinedParentTransformation(); |
245cbf94 |
704 | if (!aParentTrsf.IsNull() |
705 | && aParentTrsf->Form() != gp_Identity) |
706 | { |
707 | // recompute local transformation relative to parent transformation |
708 | const gp_Trsf aNewLocalTrsf = aParentTrsf->Trsf().Inverted() * theTrsf * aParentTrsf->Trsf() * anOldTrsf; |
709 | anObj->SetLocalTransformation (aNewLocalTrsf); |
710 | } |
711 | else |
712 | { |
713 | anObj->SetLocalTransformation (theTrsf * anOldTrsf); |
714 | } |
3ed88fac |
715 | } |
625e1958 |
716 | } |
717 | |
f522ce50 |
718 | if ((myCurrentMode == AIS_MM_Translation && myBehaviorOnTransform.FollowTranslation) |
719 | || (myCurrentMode == AIS_MM_Rotation && myBehaviorOnTransform.FollowRotation) |
720 | || (myCurrentMode == AIS_MM_TranslationPlane && myBehaviorOnTransform.FollowDragging)) |
625e1958 |
721 | { |
722 | gp_Pnt aPos = myStartPosition.Location().Transformed (theTrsf); |
723 | gp_Dir aVDir = myStartPosition.Direction().Transformed (theTrsf); |
724 | gp_Dir aXDir = myStartPosition.XDirection().Transformed (theTrsf); |
725 | SetPosition (gp_Ax2 (aPos, aVDir, aXDir)); |
726 | } |
727 | } |
728 | |
729 | //======================================================================= |
730 | //function : Transform |
731 | //purpose : |
732 | //======================================================================= |
733 | gp_Trsf AIS_Manipulator::Transform (const Standard_Integer thePX, const Standard_Integer thePY, |
734 | const Handle(V3d_View)& theView) |
735 | { |
736 | gp_Trsf aTrsf; |
737 | if (ObjectTransformation (thePX, thePY, theView, aTrsf)) |
738 | { |
739 | Transform (aTrsf); |
740 | } |
741 | |
742 | return aTrsf; |
743 | } |
744 | |
745 | //======================================================================= |
746 | //function : SetPosition |
747 | //purpose : |
748 | //======================================================================= |
749 | void AIS_Manipulator::SetPosition (const gp_Ax2& thePosition) |
750 | { |
751 | if (!myPosition.Location().IsEqual (thePosition.Location(), Precision::Confusion()) |
752 | || !myPosition.Direction().IsEqual (thePosition.Direction(), Precision::Angular()) |
753 | || !myPosition.XDirection().IsEqual (thePosition.XDirection(), Precision::Angular())) |
754 | { |
755 | myPosition = thePosition; |
3ed88fac |
756 | myAxes[0].SetPosition (getAx1FromAx2Dir (thePosition, 0)); |
757 | myAxes[1].SetPosition (getAx1FromAx2Dir (thePosition, 1)); |
758 | myAxes[2].SetPosition (getAx1FromAx2Dir (thePosition, 2)); |
625e1958 |
759 | updateTransformation(); |
760 | } |
761 | } |
762 | |
763 | //======================================================================= |
764 | //function : updateTransformation |
765 | //purpose : set local transformation to avoid graphics recomputation |
766 | //======================================================================= |
767 | void AIS_Manipulator::updateTransformation() |
768 | { |
769 | gp_Trsf aTrsf; |
770 | |
771 | if (!myIsZoomPersistentMode) |
772 | { |
773 | aTrsf.SetTransformation (myPosition, gp::XOY()); |
774 | } |
775 | else |
776 | { |
777 | const gp_Dir& aVDir = myPosition.Direction(); |
778 | const gp_Dir& aXDir = myPosition.XDirection(); |
779 | aTrsf.SetTransformation (gp_Ax2 (gp::Origin(), aVDir, aXDir), gp::XOY()); |
780 | } |
781 | |
7f24b768 |
782 | Handle(TopLoc_Datum3D) aGeomTrsf = new TopLoc_Datum3D (aTrsf); |
1f7f5a90 |
783 | // we explicitly call here setLocalTransformation() of the base class |
784 | // since AIS_Manipulator::setLocalTransformation() implementation throws exception |
785 | // as protection from external calls |
786 | AIS_InteractiveObject::setLocalTransformation (aGeomTrsf); |
625e1958 |
787 | for (Standard_Integer anIt = 0; anIt < 3; ++anIt) |
788 | { |
789 | myAxes[anIt].Transform (aGeomTrsf); |
790 | } |
791 | |
792 | if (myIsZoomPersistentMode) |
793 | { |
778cd667 |
794 | if (TransformPersistence().IsNull() |
795 | || TransformPersistence()->Mode() != Graphic3d_TMF_ZoomPers |
796 | || !TransformPersistence()->AnchorPoint().IsEqual (myPosition.Location(), 0.0)) |
625e1958 |
797 | { |
778cd667 |
798 | setTransformPersistence (new Graphic3d_TransformPers (Graphic3d_TMF_ZoomPers, myPosition.Location())); |
625e1958 |
799 | } |
800 | } |
801 | } |
802 | |
803 | //======================================================================= |
804 | //function : SetSize |
805 | //purpose : |
806 | //======================================================================= |
807 | void AIS_Manipulator::SetSize (const Standard_ShortReal theSideLength) |
808 | { |
809 | for (Standard_Integer anIt = 0; anIt < 3; ++anIt) |
810 | { |
811 | myAxes[anIt].SetSize (theSideLength); |
812 | } |
813 | |
814 | SetToUpdate(); |
815 | } |
816 | |
817 | //======================================================================= |
818 | //function : SetGap |
819 | //purpose : |
820 | //======================================================================= |
821 | void AIS_Manipulator::SetGap (const Standard_ShortReal theValue) |
822 | { |
823 | for (Standard_Integer anIt = 0; anIt < 3; ++anIt) |
824 | { |
825 | myAxes[anIt].SetIndent (theValue); |
826 | } |
827 | |
828 | SetToUpdate(); |
829 | } |
830 | |
831 | //======================================================================= |
832 | //function : DeactivateCurrentMode |
833 | //purpose : |
834 | //======================================================================= |
835 | void AIS_Manipulator::DeactivateCurrentMode() |
836 | { |
837 | if (!myIsActivationOnDetection) |
838 | { |
839 | Handle(Graphic3d_Group) aGroup = getGroup (myCurrentIndex, myCurrentMode); |
840 | if (aGroup.IsNull()) |
841 | { |
842 | return; |
843 | } |
844 | |
845 | Handle(Prs3d_ShadingAspect) anAspect = new Prs3d_ShadingAspect(); |
846 | anAspect->Aspect()->SetInteriorStyle (Aspect_IS_SOLID); |
847 | anAspect->SetMaterial (myDrawer->ShadingAspect()->Material()); |
f522ce50 |
848 | if (myCurrentMode == AIS_MM_TranslationPlane) |
849 | anAspect->SetTransparency(1.0); |
850 | else |
851 | { |
852 | anAspect->SetTransparency(myDrawer->ShadingAspect()->Transparency()); |
853 | anAspect->SetColor(myAxes[myCurrentIndex].Color()); |
854 | } |
625e1958 |
855 | |
856 | aGroup->SetGroupPrimitivesAspect (anAspect->Aspect()); |
857 | } |
858 | |
859 | myCurrentIndex = -1; |
860 | myCurrentMode = AIS_MM_None; |
861 | |
862 | if (myHasStartedTransformation) |
863 | { |
864 | myHasStartedTransformation = Standard_False; |
865 | } |
866 | } |
867 | |
868 | //======================================================================= |
869 | //function : SetZoomPersistence |
870 | //purpose : |
871 | //======================================================================= |
872 | void AIS_Manipulator::SetZoomPersistence (const Standard_Boolean theToEnable) |
873 | { |
874 | if (myIsZoomPersistentMode != theToEnable) |
875 | { |
876 | SetToUpdate(); |
877 | } |
878 | |
879 | myIsZoomPersistentMode = theToEnable; |
880 | |
881 | if (!theToEnable) |
882 | { |
778cd667 |
883 | setTransformPersistence (Handle(Graphic3d_TransformPers)()); |
625e1958 |
884 | } |
885 | |
886 | updateTransformation(); |
887 | } |
888 | |
889 | //======================================================================= |
890 | //function : SetTransformPersistence |
778cd667 |
891 | //purpose : |
625e1958 |
892 | //======================================================================= |
778cd667 |
893 | void AIS_Manipulator::SetTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers) |
625e1958 |
894 | { |
895 | Standard_ASSERT_RETURN (!myIsZoomPersistentMode, |
896 | "AIS_Manipulator::SetTransformPersistence: " |
778cd667 |
897 | "Custom settings are not allowed by this class in ZoomPersistence mode",); |
625e1958 |
898 | |
778cd667 |
899 | setTransformPersistence (theTrsfPers); |
625e1958 |
900 | } |
901 | |
902 | //======================================================================= |
903 | //function : setTransformPersistence |
904 | //purpose : |
905 | //======================================================================= |
778cd667 |
906 | void AIS_Manipulator::setTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers) |
625e1958 |
907 | { |
778cd667 |
908 | AIS_InteractiveObject::SetTransformPersistence (theTrsfPers); |
625e1958 |
909 | |
910 | for (Standard_Integer anIt = 0; anIt < 3; ++anIt) |
911 | { |
778cd667 |
912 | myAxes[anIt].SetTransformPersistence (theTrsfPers); |
625e1958 |
913 | } |
914 | } |
915 | |
916 | //======================================================================= |
1f7f5a90 |
917 | //function : setLocalTransformation |
918 | //purpose : |
625e1958 |
919 | //======================================================================= |
7f24b768 |
920 | void AIS_Manipulator::setLocalTransformation (const Handle(TopLoc_Datum3D)& /*theTrsf*/) |
625e1958 |
921 | { |
1f7f5a90 |
922 | Standard_ASSERT_INVOKE ("AIS_Manipulator::setLocalTransformation: " |
923 | "Custom transformation is not supported by this class"); |
625e1958 |
924 | } |
925 | |
926 | //======================================================================= |
927 | //function : Compute |
928 | //purpose : |
929 | //======================================================================= |
930 | void AIS_Manipulator::Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr, |
931 | const Handle(Prs3d_Presentation)& thePrs, |
932 | const Standard_Integer theMode) |
933 | { |
934 | if (theMode != AIS_Shaded) |
935 | { |
936 | return; |
937 | } |
938 | |
939 | thePrs->SetInfiniteState (Standard_True); |
940 | thePrs->SetMutable (Standard_True); |
941 | Handle(Graphic3d_Group) aGroup; |
942 | Handle(Prs3d_ShadingAspect) anAspect = new Prs3d_ShadingAspect(); |
943 | anAspect->Aspect()->SetInteriorStyle (Aspect_IS_SOLID); |
944 | anAspect->SetMaterial (myDrawer->ShadingAspect()->Material()); |
945 | anAspect->SetTransparency (myDrawer->ShadingAspect()->Transparency()); |
946 | |
947 | // Display center |
948 | myCenter.Init (myAxes[0].AxisRadius() * 2.0f, gp::Origin()); |
f522ce50 |
949 | aGroup = thePrs->NewGroup (); |
625e1958 |
950 | aGroup->SetPrimitivesAspect (myDrawer->ShadingAspect()->Aspect()); |
951 | aGroup->AddPrimitiveArray (myCenter.Array()); |
952 | |
953 | for (Standard_Integer anIt = 0; anIt < 3; ++anIt) |
954 | { |
955 | // Display axes |
f522ce50 |
956 | aGroup = thePrs->NewGroup (); |
b6472664 |
957 | |
958 | Handle(Prs3d_ShadingAspect) anAspectAx = new Prs3d_ShadingAspect (new Graphic3d_AspectFillArea3d(*anAspect->Aspect())); |
959 | anAspectAx->SetColor (myAxes[anIt].Color()); |
960 | aGroup->SetGroupPrimitivesAspect (anAspectAx->Aspect()); |
961 | myAxes[anIt].Compute (thePrsMgr, thePrs, anAspectAx); |
778cd667 |
962 | myAxes[anIt].SetTransformPersistence (TransformPersistence()); |
625e1958 |
963 | } |
964 | |
965 | updateTransformation(); |
966 | } |
967 | |
968 | //======================================================================= |
969 | //function : HilightSelected |
970 | //purpose : |
971 | //======================================================================= |
972 | void AIS_Manipulator::HilightSelected (const Handle(PrsMgr_PresentationManager3d)& thePM, |
973 | const SelectMgr_SequenceOfOwner& theSeq) |
974 | { |
975 | if (theSeq.IsEmpty()) |
976 | { |
977 | return; |
978 | } |
979 | |
980 | if (myIsActivationOnDetection) |
981 | { |
982 | return; |
983 | } |
984 | |
985 | if (!theSeq (1)->IsKind (STANDARD_TYPE (AIS_ManipulatorOwner))) |
986 | { |
8e5fb5ea |
987 | thePM->Color (this, GetContext()->HighlightStyle(), 0); |
625e1958 |
988 | return; |
989 | } |
990 | |
991 | Handle(AIS_ManipulatorOwner) anOwner = Handle(AIS_ManipulatorOwner)::DownCast (theSeq (1)); |
8e5fb5ea |
992 | myHighlightAspect->Aspect()->SetInteriorColor (GetContext()->HighlightStyle()->Color()); |
625e1958 |
993 | Handle(Graphic3d_Group) aGroup = getGroup (anOwner->Index(), anOwner->Mode()); |
994 | if (aGroup.IsNull()) |
995 | { |
996 | return; |
997 | } |
998 | |
f522ce50 |
999 | if (anOwner->Mode() == AIS_MM_TranslationPlane) |
1000 | { |
1001 | myDraggerHighlight->SetColor(myAxes[anOwner->Index()].Color()); |
1002 | aGroup->SetGroupPrimitivesAspect(myDraggerHighlight->Aspect()); |
1003 | } |
1004 | else |
1005 | aGroup->SetGroupPrimitivesAspect(myHighlightAspect->Aspect()); |
625e1958 |
1006 | |
1007 | myCurrentIndex = anOwner->Index(); |
1008 | myCurrentMode = anOwner->Mode(); |
1009 | } |
1010 | |
1011 | //======================================================================= |
1012 | //function : ClearSelected |
1013 | //purpose : |
1014 | //======================================================================= |
1015 | void AIS_Manipulator::ClearSelected() |
1016 | { |
1017 | DeactivateCurrentMode(); |
1018 | } |
1019 | |
1020 | //======================================================================= |
1021 | //function : HilightOwnerWithColor |
1022 | //purpose : |
1023 | //======================================================================= |
8e5fb5ea |
1024 | void AIS_Manipulator::HilightOwnerWithColor (const Handle(PrsMgr_PresentationManager3d)& thePM, |
f838dac4 |
1025 | const Handle(Prs3d_Drawer)& theStyle, |
8e5fb5ea |
1026 | const Handle(SelectMgr_EntityOwner)& theOwner) |
625e1958 |
1027 | { |
1028 | Handle(AIS_ManipulatorOwner) anOwner = Handle(AIS_ManipulatorOwner)::DownCast (theOwner); |
1029 | Handle(Prs3d_Presentation) aPresentation = getHighlightPresentation (anOwner); |
1030 | if (aPresentation.IsNull()) |
1031 | { |
1032 | return; |
1033 | } |
bbf3fcde |
1034 | |
1035 | aPresentation->CStructure()->ViewAffinity = thePM->StructureManager()->ObjectAffinity (Handle(Standard_Transient) (this)); |
1036 | |
f522ce50 |
1037 | if (anOwner->Mode() == AIS_MM_TranslationPlane) |
1038 | { |
1039 | Handle(Prs3d_Drawer) aStyle = new Prs3d_Drawer(); |
bbf3fcde |
1040 | aStyle->SetColor (myAxes[anOwner->Index()].Color()); |
1041 | aStyle->SetTransparency (0.5); |
1042 | aPresentation->Highlight (aStyle); |
f522ce50 |
1043 | } |
1044 | else |
bbf3fcde |
1045 | { |
1046 | aPresentation->Highlight (theStyle); |
1047 | } |
1048 | |
2831708b |
1049 | for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (aPresentation->Groups()); |
1050 | aGroupIter.More(); aGroupIter.Next()) |
1051 | { |
1052 | Handle(Graphic3d_Group)& aGrp = aGroupIter.ChangeValue(); |
bf5f0ca2 |
1053 | if (!aGrp.IsNull()) |
2831708b |
1054 | { |
1055 | aGrp->SetGroupPrimitivesAspect (myHighlightAspect->Aspect()); |
1056 | } |
1057 | } |
625e1958 |
1058 | aPresentation->SetZLayer (Graphic3d_ZLayerId_Topmost); |
1059 | thePM->AddToImmediateList (aPresentation); |
1060 | |
1061 | if (myIsActivationOnDetection) |
1062 | { |
1063 | if (HasActiveMode()) |
1064 | { |
1065 | DeactivateCurrentMode(); |
1066 | } |
1067 | |
1068 | myCurrentIndex = anOwner->Index(); |
1069 | myCurrentMode = anOwner->Mode(); |
1070 | } |
1071 | } |
1072 | |
1073 | //======================================================================= |
1074 | //function : ComputeSelection |
1075 | //purpose : |
1076 | //======================================================================= |
1077 | void AIS_Manipulator::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection, |
1078 | const Standard_Integer theMode) |
1079 | { |
1080 | //Check mode |
1081 | AIS_ManipulatorMode aMode = (AIS_ManipulatorMode) theMode; |
1082 | if (aMode == AIS_MM_None) |
1083 | { |
1084 | return; |
1085 | } |
1086 | Handle(SelectMgr_EntityOwner) anOwner; |
1087 | if (aMode == AIS_MM_None) |
1088 | { |
1089 | anOwner = new SelectMgr_EntityOwner (this, 5); |
1090 | } |
62ef08df |
1091 | |
625e1958 |
1092 | if (aMode == AIS_MM_Translation || aMode == AIS_MM_None) |
1093 | { |
1094 | for (Standard_Integer anIt = 0; anIt < 3; ++anIt) |
1095 | { |
f15c5f90 |
1096 | if (!myAxes[anIt].HasTranslation()) |
1097 | { |
1098 | continue; |
1099 | } |
625e1958 |
1100 | const Axis& anAxis = myAxes[anIt]; |
1101 | if (aMode != AIS_MM_None) |
1102 | { |
f15c5f90 |
1103 | anOwner = new AIS_ManipulatorOwner (this, anIt, AIS_MM_Translation, 9); |
625e1958 |
1104 | } |
1105 | // define sensitivity by line |
1106 | Handle(Select3D_SensitiveSegment) aLine = new Select3D_SensitiveSegment (anOwner, gp::Origin(), anAxis.TranslatorTipPosition()); |
1107 | aLine->SetSensitivityFactor (15); |
1108 | theSelection->Add (aLine); |
62ef08df |
1109 | |
625e1958 |
1110 | // enlarge sensitivity by triangulation |
62ef08df |
1111 | Handle(Select3D_SensitivePrimitiveArray) aTri = new Select3D_SensitivePrimitiveArray (anOwner); |
1112 | aTri->InitTriangulation (anAxis.TriangleArray()->Attributes(), anAxis.TriangleArray()->Indices(), TopLoc_Location()); |
625e1958 |
1113 | theSelection->Add (aTri); |
1114 | } |
1115 | } |
1116 | |
1117 | if (aMode == AIS_MM_Rotation || aMode == AIS_MM_None) |
1118 | { |
1119 | for (Standard_Integer anIt = 0; anIt < 3; ++anIt) |
1120 | { |
f15c5f90 |
1121 | if (!myAxes[anIt].HasRotation()) |
1122 | { |
1123 | continue; |
1124 | } |
625e1958 |
1125 | const Axis& anAxis = myAxes[anIt]; |
1126 | if (aMode != AIS_MM_None) |
1127 | { |
1128 | anOwner = new AIS_ManipulatorOwner (this, anIt, AIS_MM_Rotation, 9); |
1129 | } |
1130 | // define sensitivity by circle |
7f24b768 |
1131 | const gp_Circ aGeomCircle (gp_Ax2 (gp::Origin(), anAxis.ReferenceAxis().Direction()), anAxis.RotatorDiskRadius()); |
b11aef43 |
1132 | Handle(Select3D_SensitiveCircle) aCircle = new ManipSensCircle (anOwner, aGeomCircle, anAxis.FacettesNumber()); |
625e1958 |
1133 | aCircle->SetSensitivityFactor (15); |
1134 | theSelection->Add (aCircle); |
1135 | // enlarge sensitivity by triangulation |
b11aef43 |
1136 | Handle(Select3D_SensitiveTriangulation) aTri = new ManipSensTriangulation (anOwner, myAxes[anIt].RotatorDisk().Triangulation(), anAxis.ReferenceAxis().Direction()); |
625e1958 |
1137 | theSelection->Add (aTri); |
1138 | } |
1139 | } |
1140 | |
1141 | if (aMode == AIS_MM_Scaling || aMode == AIS_MM_None) |
1142 | { |
1143 | for (Standard_Integer anIt = 0; anIt < 3; ++anIt) |
1144 | { |
f15c5f90 |
1145 | if (!myAxes[anIt].HasScaling()) |
1146 | { |
1147 | continue; |
1148 | } |
625e1958 |
1149 | if (aMode != AIS_MM_None) |
1150 | { |
1151 | anOwner = new AIS_ManipulatorOwner (this, anIt, AIS_MM_Scaling, 9); |
1152 | } |
1153 | // define sensitivity by point |
1154 | Handle(Select3D_SensitivePoint) aPnt = new Select3D_SensitivePoint (anOwner, myAxes[anIt].ScalerCubePosition()); |
1155 | aPnt->SetSensitivityFactor (15); |
1156 | theSelection->Add (aPnt); |
1157 | // enlarge sensitivity by triangulation |
62ef08df |
1158 | Handle(Select3D_SensitiveTriangulation) aTri = new Select3D_SensitiveTriangulation (anOwner, myAxes[anIt].ScalerCube().Triangulation(), TopLoc_Location(), Standard_True); |
625e1958 |
1159 | theSelection->Add (aTri); |
1160 | } |
1161 | } |
f522ce50 |
1162 | |
1163 | if (aMode == AIS_MM_TranslationPlane || aMode == AIS_MM_None) |
1164 | { |
1165 | for (Standard_Integer anIt = 0; anIt < 3; ++anIt) |
1166 | { |
1167 | if (!myAxes[anIt].HasDragging()) |
1168 | { |
1169 | continue; |
1170 | } |
1171 | if (aMode != AIS_MM_None) |
1172 | { |
1173 | anOwner = new AIS_ManipulatorOwner(this, anIt, AIS_MM_TranslationPlane, 9); |
1174 | } |
1175 | |
1176 | // define sensitivity by two crossed lines |
1177 | gp_Pnt aP1, aP2; |
1178 | aP1 = myAxes[((anIt + 1) % 3)].TranslatorTipPosition(); |
1179 | aP2 = myAxes[((anIt + 2) % 3)].TranslatorTipPosition(); |
1180 | gp_XYZ aMidP = (aP1.XYZ() + aP2.XYZ()) / 2.0; |
1181 | |
1182 | Handle(Select3D_SensitiveSegment) aLine1 = new Select3D_SensitiveSegment(anOwner, aP1, aP2); |
1183 | aLine1->SetSensitivityFactor(10); |
1184 | theSelection->Add(aLine1); |
1185 | Handle(Select3D_SensitiveSegment) aLine2 = new Select3D_SensitiveSegment(anOwner, gp::Origin(), aMidP); |
1186 | aLine2->SetSensitivityFactor(10); |
1187 | theSelection->Add(aLine2); |
1188 | |
1189 | // enlarge sensitivity by triangulation |
1190 | Handle(Select3D_SensitiveTriangulation) aTri = new Select3D_SensitiveTriangulation(anOwner, myAxes[anIt].DraggerSector().Triangulation(), TopLoc_Location(), Standard_True); |
1191 | theSelection->Add(aTri); |
1192 | } |
1193 | } |
625e1958 |
1194 | } |
1195 | |
625e1958 |
1196 | //======================================================================= |
1197 | //class : Disk |
1198 | //function : Init |
1199 | //purpose : |
1200 | //======================================================================= |
1201 | void AIS_Manipulator::Disk::Init (const Standard_ShortReal theInnerRadius, |
1202 | const Standard_ShortReal theOuterRadius, |
1203 | const gp_Ax1& thePosition, |
1204 | const Standard_Integer theSlicesNb, |
1205 | const Standard_Integer theStacksNb) |
1206 | { |
1207 | myPosition = thePosition; |
1208 | myInnerRad = theInnerRadius; |
1209 | myOuterRad = theOuterRadius; |
1210 | |
62ef08df |
1211 | Prs3d_ToolDisk aTool (theInnerRadius, theOuterRadius, theSlicesNb, theStacksNb); |
625e1958 |
1212 | gp_Ax3 aSystem (myPosition.Location(), myPosition.Direction()); |
1213 | gp_Trsf aTrsf; |
1214 | aTrsf.SetTransformation (aSystem, gp_Ax3()); |
f0da4970 |
1215 | myArray = aTool.CreateTriangulation (aTrsf); |
1216 | myTriangulation = aTool.CreatePolyTriangulation (aTrsf); |
625e1958 |
1217 | } |
1218 | |
1219 | //======================================================================= |
1220 | //class : Sphere |
1221 | //function : Init |
1222 | //purpose : |
1223 | //======================================================================= |
1224 | void AIS_Manipulator::Sphere::Init (const Standard_ShortReal theRadius, |
1225 | const gp_Pnt& thePosition, |
1226 | const Standard_Integer theSlicesNb, |
1227 | const Standard_Integer theStacksNb) |
1228 | { |
1229 | myPosition = thePosition; |
1230 | myRadius = theRadius; |
1231 | |
62ef08df |
1232 | Prs3d_ToolSphere aTool (theRadius, theSlicesNb, theStacksNb); |
625e1958 |
1233 | gp_Trsf aTrsf; |
1234 | aTrsf.SetTranslation (gp_Vec(gp::Origin(), thePosition)); |
f0da4970 |
1235 | myArray = aTool.CreateTriangulation (aTrsf); |
1236 | myTriangulation = aTool.CreatePolyTriangulation (aTrsf); |
625e1958 |
1237 | } |
1238 | |
1239 | //======================================================================= |
1240 | //class : Cube |
1241 | //function : Init |
1242 | //purpose : |
1243 | //======================================================================= |
1244 | void AIS_Manipulator::Cube::Init (const gp_Ax1& thePosition, const Standard_ShortReal theSize) |
1245 | { |
1246 | myArray = new Graphic3d_ArrayOfTriangles (12 * 3, 0, Standard_True); |
1247 | |
1248 | Poly_Array1OfTriangle aPolyTriangles (1, 12); |
1249 | TColgp_Array1OfPnt aPoints (1, 36); |
1250 | NCollection_Array1<gp_Dir> aNormals (1, 12); |
1251 | myTriangulation = new Poly_Triangulation (aPoints, aPolyTriangles); |
1252 | |
1253 | gp_Ax2 aPln (thePosition.Location(), thePosition.Direction()); |
1254 | gp_Pnt aBottomLeft = thePosition.Location().XYZ() - aPln.XDirection().XYZ() * theSize * 0.5 - aPln.YDirection().XYZ() * theSize * 0.5; |
1255 | gp_Pnt aV2 = aBottomLeft.XYZ() + aPln.YDirection().XYZ() * theSize; |
1256 | gp_Pnt aV3 = aBottomLeft.XYZ() + aPln.YDirection().XYZ() * theSize + aPln.XDirection().XYZ() * theSize; |
1257 | gp_Pnt aV4 = aBottomLeft.XYZ() + aPln.XDirection().XYZ() * theSize; |
1258 | gp_Pnt aTopRight = thePosition.Location().XYZ() + thePosition.Direction().XYZ() * theSize |
1259 | + aPln.XDirection().XYZ() * theSize * 0.5 + aPln.YDirection().XYZ() * theSize * 0.5; |
1260 | gp_Pnt aV5 = aTopRight.XYZ() - aPln.YDirection().XYZ() * theSize; |
1261 | gp_Pnt aV6 = aTopRight.XYZ() - aPln.YDirection().XYZ() * theSize - aPln.XDirection().XYZ() * theSize; |
1262 | gp_Pnt aV7 = aTopRight.XYZ() - aPln.XDirection().XYZ() * theSize; |
1263 | |
1264 | gp_Dir aRight ((gp_Vec(aTopRight, aV7) ^ gp_Vec(aTopRight, aV2)).XYZ()); |
1265 | gp_Dir aFront ((gp_Vec(aV3, aV4) ^ gp_Vec(aV3, aV5)).XYZ()); |
1266 | |
1267 | // Bottom |
1268 | addTriangle (0, aBottomLeft, aV2, aV3, -thePosition.Direction()); |
1269 | addTriangle (1, aBottomLeft, aV3, aV4, -thePosition.Direction()); |
1270 | |
1271 | // Front |
f0da4970 |
1272 | addTriangle (2, aV3, aV5, aV4, -aFront); |
1273 | addTriangle (3, aV3, aTopRight, aV5, -aFront); |
625e1958 |
1274 | |
1275 | // Back |
f0da4970 |
1276 | addTriangle (4, aBottomLeft, aV7, aV2, aFront); |
1277 | addTriangle (5, aBottomLeft, aV6, aV7, aFront); |
625e1958 |
1278 | |
1279 | // aTop |
1280 | addTriangle (6, aV7, aV6, aV5, thePosition.Direction()); |
1281 | addTriangle (7, aTopRight, aV7, aV5, thePosition.Direction()); |
1282 | |
f0da4970 |
1283 | // Left |
1284 | addTriangle (8, aV6, aV4, aV5, aRight); |
1285 | addTriangle (9, aBottomLeft, aV4, aV6, aRight); |
625e1958 |
1286 | |
1287 | // Right |
f0da4970 |
1288 | addTriangle (10, aV3, aV7, aTopRight, -aRight); |
1289 | addTriangle (11, aV3, aV2, aV7, -aRight); |
625e1958 |
1290 | } |
1291 | |
1292 | //======================================================================= |
1293 | //class : Cube |
1294 | //function : addTriangle |
1295 | //purpose : |
1296 | //======================================================================= |
1297 | void AIS_Manipulator::Cube::addTriangle (const Standard_Integer theIndex, |
1298 | const gp_Pnt& theP1, const gp_Pnt& theP2, const gp_Pnt& theP3, |
1299 | const gp_Dir& theNormal) |
1300 | { |
1301 | myTriangulation->ChangeNodes().SetValue (theIndex * 3 + 1, theP1); |
1302 | myTriangulation->ChangeNodes().SetValue (theIndex * 3 + 2, theP2); |
1303 | myTriangulation->ChangeNodes().SetValue (theIndex * 3 + 3, theP3); |
1304 | |
1305 | myTriangulation->ChangeTriangles().SetValue (theIndex + 1, Poly_Triangle (theIndex * 3 + 1, theIndex * 3 + 2, theIndex * 3 + 3)); |
1306 | myArray->AddVertex (theP1, theNormal); |
1307 | myArray->AddVertex (theP2, theNormal); |
1308 | myArray->AddVertex (theP3, theNormal); |
1309 | } |
1310 | |
f522ce50 |
1311 | //======================================================================= |
1312 | //class : Sector |
1313 | //function : Init |
1314 | //purpose : |
1315 | //======================================================================= |
1316 | void AIS_Manipulator::Sector::Init (const Standard_ShortReal theRadius, |
1317 | const gp_Ax1& thePosition, |
1318 | const gp_Dir& theXDirection, |
1319 | const Standard_Integer theSlicesNb, |
1320 | const Standard_Integer theStacksNb) |
1321 | { |
1322 | Prs3d_ToolSector aTool(theRadius, theSlicesNb, theStacksNb); |
1323 | gp_Ax3 aSystem(thePosition.Location(), thePosition.Direction(), theXDirection); |
1324 | gp_Trsf aTrsf; |
1325 | aTrsf.SetTransformation(aSystem, gp_Ax3()); |
f0da4970 |
1326 | myArray = aTool.CreateTriangulation (aTrsf); |
1327 | myTriangulation = aTool.CreatePolyTriangulation (aTrsf); |
f522ce50 |
1328 | } |
1329 | |
625e1958 |
1330 | //======================================================================= |
1331 | //class : Axis |
1332 | //function : Constructor |
1333 | //purpose : |
1334 | //======================================================================= |
1335 | AIS_Manipulator::Axis::Axis (const gp_Ax1& theAxis, |
1336 | const Quantity_Color& theColor, |
1337 | const Standard_ShortReal theLength) |
1338 | : myReferenceAxis (theAxis), |
1339 | myPosition (theAxis), |
1340 | myColor (theColor), |
1341 | myHasTranslation (Standard_True), |
1342 | myLength (theLength), |
1343 | myAxisRadius (0.5f), |
1344 | myHasScaling (Standard_True), |
1345 | myBoxSize (2.0f), |
1346 | myHasRotation (Standard_True), |
1347 | myInnerRadius (myLength + myBoxSize), |
1348 | myDiskThickness (myBoxSize * 0.5f), |
1349 | myIndent (0.2f), |
f522ce50 |
1350 | myHasDragging(Standard_True), |
625e1958 |
1351 | myFacettesNumber (20), |
1352 | myCircleRadius (myLength + myBoxSize + myBoxSize * 0.5f * 0.5f) |
1353 | { |
1354 | // |
1355 | } |
1356 | |
1357 | //======================================================================= |
1358 | //class : Axis |
1359 | //function : Compute |
62ef08df |
1360 | //purpose : |
625e1958 |
1361 | //======================================================================= |
62ef08df |
1362 | |
1363 | void AIS_Manipulator::Axis::Compute (const Handle(PrsMgr_PresentationManager)& thePrsMgr, |
625e1958 |
1364 | const Handle(Prs3d_Presentation)& thePrs, |
1365 | const Handle(Prs3d_ShadingAspect)& theAspect) |
1366 | { |
625e1958 |
1367 | if (myHasTranslation) |
1368 | { |
62ef08df |
1369 | const Standard_Real anArrowLength = 0.25 * myLength; |
1370 | const Standard_Real aCylinderLength = myLength - anArrowLength; |
1371 | myArrowTipPos = gp_Pnt (0.0, 0.0, 0.0).Translated (myReferenceAxis.Direction().XYZ() * aCylinderLength); |
1372 | |
1373 | myTriangleArray = Prs3d_Arrow::DrawShaded (gp_Ax1(gp::Origin(), myReferenceAxis.Direction()), |
1374 | myAxisRadius, |
1375 | myLength, |
1376 | myAxisRadius * 1.5, |
1377 | anArrowLength, |
1378 | myFacettesNumber); |
f0da4970 |
1379 | myTranslatorGroup = thePrs->NewGroup(); |
1380 | myTranslatorGroup->SetClosed (true); |
625e1958 |
1381 | myTranslatorGroup->SetGroupPrimitivesAspect (theAspect->Aspect()); |
62ef08df |
1382 | myTranslatorGroup->AddPrimitiveArray (myTriangleArray); |
625e1958 |
1383 | |
1384 | if (myHighlightTranslator.IsNull()) |
1385 | { |
1386 | myHighlightTranslator = new Prs3d_Presentation (thePrsMgr->StructureManager()); |
1387 | } |
62ef08df |
1388 | else |
1389 | { |
1390 | myHighlightTranslator->Clear(); |
1391 | } |
dc89236f |
1392 | { |
d6c48921 |
1393 | Handle(Graphic3d_Group) aGroup = myHighlightTranslator->CurrentGroup(); |
dc89236f |
1394 | aGroup->SetGroupPrimitivesAspect (theAspect->Aspect()); |
1395 | aGroup->AddPrimitiveArray (myTriangleArray); |
1396 | } |
625e1958 |
1397 | } |
1398 | |
1399 | if (myHasScaling) |
1400 | { |
1401 | myCubePos = myReferenceAxis.Direction().XYZ() * (myLength + myIndent); |
1402 | myCube.Init (gp_Ax1 (myCubePos, myReferenceAxis.Direction()), myBoxSize); |
1403 | |
f0da4970 |
1404 | myScalerGroup = thePrs->NewGroup(); |
1405 | myScalerGroup->SetClosed (true); |
625e1958 |
1406 | myScalerGroup->SetGroupPrimitivesAspect (theAspect->Aspect()); |
1407 | myScalerGroup->AddPrimitiveArray (myCube.Array()); |
1408 | |
1409 | if (myHighlightScaler.IsNull()) |
1410 | { |
1411 | myHighlightScaler = new Prs3d_Presentation (thePrsMgr->StructureManager()); |
1412 | } |
62ef08df |
1413 | else |
1414 | { |
1415 | myHighlightScaler->Clear(); |
1416 | } |
dc89236f |
1417 | { |
d6c48921 |
1418 | Handle(Graphic3d_Group) aGroup = myHighlightScaler->CurrentGroup(); |
dc89236f |
1419 | aGroup->SetGroupPrimitivesAspect (theAspect->Aspect()); |
1420 | aGroup->AddPrimitiveArray (myCube.Array()); |
1421 | } |
625e1958 |
1422 | } |
1423 | |
1424 | if (myHasRotation) |
1425 | { |
1426 | myCircleRadius = myInnerRadius + myIndent * 2 + myDiskThickness * 0.5f; |
1427 | myCircle.Init (myInnerRadius + myIndent * 2, myInnerRadius + myDiskThickness + myIndent * 2, gp_Ax1(gp::Origin(), myReferenceAxis.Direction()), myFacettesNumber * 2); |
f522ce50 |
1428 | myRotatorGroup = thePrs->NewGroup (); |
625e1958 |
1429 | myRotatorGroup->SetGroupPrimitivesAspect (theAspect->Aspect()); |
1430 | myRotatorGroup->AddPrimitiveArray (myCircle.Array()); |
1431 | |
1432 | if (myHighlightRotator.IsNull()) |
1433 | { |
1434 | myHighlightRotator = new Prs3d_Presentation (thePrsMgr->StructureManager()); |
1435 | } |
62ef08df |
1436 | else |
1437 | { |
1438 | myHighlightRotator->Clear(); |
1439 | } |
dc89236f |
1440 | { |
d6c48921 |
1441 | Handle(Graphic3d_Group) aGroup = myHighlightRotator->CurrentGroup(); |
dc89236f |
1442 | aGroup->SetGroupPrimitivesAspect (theAspect->Aspect()); |
1443 | aGroup->AddPrimitiveArray (myCircle.Array()); |
1444 | } |
625e1958 |
1445 | } |
f522ce50 |
1446 | |
1447 | if (myHasDragging) |
1448 | { |
1449 | gp_Dir aXDirection; |
1450 | if (myReferenceAxis.Direction().X() > 0) |
1451 | aXDirection = gp::DY(); |
1452 | else if (myReferenceAxis.Direction().Y() > 0) |
1453 | aXDirection = gp::DZ(); |
1454 | else |
1455 | aXDirection = gp::DX(); |
1456 | |
1457 | mySector.Init(myInnerRadius + myIndent * 2, gp_Ax1(gp::Origin(), myReferenceAxis.Direction()), aXDirection, myFacettesNumber * 2); |
1458 | myDraggerGroup = thePrs->NewGroup(); |
1459 | |
1460 | Handle(Graphic3d_AspectFillArea3d) aFillArea = new Graphic3d_AspectFillArea3d(); |
1461 | myDraggerGroup->SetGroupPrimitivesAspect(aFillArea); |
1462 | myDraggerGroup->AddPrimitiveArray(mySector.Array()); |
1463 | |
1464 | if (myHighlightDragger.IsNull()) |
1465 | { |
1466 | myHighlightDragger = new Prs3d_Presentation(thePrsMgr->StructureManager()); |
1467 | } |
1468 | else |
1469 | { |
1470 | myHighlightDragger->Clear(); |
1471 | } |
1472 | { |
d6c48921 |
1473 | Handle(Graphic3d_Group) aGroup = myHighlightDragger->CurrentGroup(); |
f522ce50 |
1474 | aGroup->SetGroupPrimitivesAspect(aFillArea); |
1475 | aGroup->AddPrimitiveArray(mySector.Array()); |
1476 | } |
1477 | } |
625e1958 |
1478 | } |