]> OCCT Git - occt-copy.git/commitdiff
0028954: Visualization - implement interactive object for camera manipulations -...
authornds <nds@opencascade.com>
Wed, 5 Sep 2018 13:39:30 +0000 (16:39 +0300)
committernds <nds@opencascade.com>
Wed, 5 Sep 2018 13:39:30 +0000 (16:39 +0300)
Conflicts:
src/AIS/AIS_ViewCube.cxx
tests/v3d/viewcube/style

src/AIS/AIS_ViewCube.cxx
src/AIS/AIS_ViewCube.hxx
tests/v3d/viewcube/part
tests/v3d/viewcube/style
tests/v3d/viewcube/view [new file with mode: 0644]
tests/v3d/viewcube/view2 [new file with mode: 0644]

index 6dfb969b2ce4e2f5bde6ec3bd40b90536e6a66da..7f199622d494c650b264b3b73e3d1f19ebeb73d0 100644 (file)
@@ -186,8 +186,10 @@ void AIS_ViewCube::setDefaultAttributes()
   myDrawer->TextAspect()->SetFont (Font_NOF_GREEK_MONO);
 
   Graphic3d_MaterialAspect aShadingMaterial;
-  aShadingMaterial.SetReflectionModeOff (Graphic3d_TOR_SPECULAR);
   aShadingMaterial.SetMaterialType (Graphic3d_MATERIAL_ASPECT);
+  aShadingMaterial.SetReflectionModeOff (Graphic3d_TOR_SPECULAR);
+  aShadingMaterial.SetReflectionModeOff (Graphic3d_TOR_EMISSION);
+  aShadingMaterial.SetReflectionModeOff (Graphic3d_TOR_DIFFUSE);
   aShadingMaterial.SetTransparency (0.0);
 
   Graphic3d_MaterialAspect aBackMaterial;
@@ -224,6 +226,7 @@ void AIS_ViewCube::setDefaultHighlightAttributes()
   aHighlightMaterial.SetReflectionModeOff (Graphic3d_TOR_SPECULAR);
   aHighlightMaterial.SetReflectionModeOff (Graphic3d_TOR_EMISSION);
   aHighlightMaterial.SetMaterialType (Graphic3d_MATERIAL_ASPECT);
+  myDynHilightDrawer->SetShadingAspect (new Prs3d_ShadingAspect);
   myDynHilightDrawer->ShadingAspect()->Aspect()->SetInteriorStyle (Aspect_IS_SOLID);
   myDynHilightDrawer->ShadingAspect()->SetMaterial (aHighlightMaterial);
   myDynHilightDrawer->ShadingAspect()->SetColor (Quantity_NOC_CYAN1);
@@ -298,12 +301,7 @@ Graphic3d_Vec2i AIS_ViewCube::Position() const
   Standard_Integer aHeight = 0;
   myView->Window()->Size (aWidth, aHeight);
 
-  if (myPosition & Aspect_TOTP_CENTER)
-  {
-    return Graphic3d_Vec2i (aWidth / 2, aHeight / 2);
-  }
-
-  Graphic3d_Vec2i aPosition;
+  Graphic3d_Vec2i aPosition (aWidth / 2, aHeight / 2);
   if (myPosition & Aspect_TOTP_TOP)
   {
     aPosition.y() = myOffset.y();
@@ -977,21 +975,39 @@ void AIS_ViewCube::AddTo (const Handle(AIS_InteractiveContext)& theContext,
   SetView (theView);
 
   theContext->Display (this, 0, 0, Standard_False);
+  SetViewAffinity (theView);
+}
+
+//=======================================================================
+//function : SetViewAffinity
+//purpose  :
+//=======================================================================
+void AIS_ViewCube::SetViewAffinity (const Handle(V3d_View)& theView)
+{
+  const Handle(AIS_InteractiveContext)& aContext = GetContext();
+  if (aContext.IsNull())
+  {
+    return;
+  }
 
   // Set view affinity for child object
-  Handle(Graphic3d_ViewAffinity) anAffinity = GetContext()->CurrentViewer()->StructureManager()->RegisterObject (myFlatPart);
+  myFlatPart->Presentation()->CStructure()->ViewAffinity = new Graphic3d_ViewAffinity;
+  myFlatPart->Presentation()->CStructure()->ViewAffinity->SetVisible (Standard_False);
+
+  Handle(Graphic3d_ViewAffinity) anAffinity = aContext->CurrentViewer()->StructureManager()->ObjectAffinity (this);
   anAffinity->SetVisible (Standard_False);
 
   // View Affinity should be applied after Display
-  for (V3d_ListOfViewIterator aViewIter (theContext->CurrentViewer()->DefinedViewIterator()); aViewIter.More(); aViewIter.Next())
+  /*for (V3d_ListOfViewIterator aViewIter (aContext->CurrentViewer()->DefinedViewIterator()); aViewIter.More(); aViewIter.Next())
   {
-    theContext->SetViewAffinity (this, aViewIter.Value(), Standard_False);
-    aViewIter.Value()->View()->ChangeHiddenObjects()->Add (myFlatPart.get());
-
+    aContext->SetViewAffinity (this, aViewIter.Value(), Standard_False);
   }
-  theContext->SetViewAffinity (this, theView, Standard_True);
+  aContext->SetViewAffinity (this, theView, Standard_True);
+  */
+
   anAffinity->SetVisible (theView->View()->Identification(), Standard_True);
-  theView->View()->ChangeHiddenObjects()->Remove (myFlatPart.get());
+  myFlatPart->Presentation()->CStructure()->ViewAffinity->SetVisible (theView->View()->Identification(), Standard_True);
+
 }
 
 //=======================================================================
@@ -1143,8 +1159,8 @@ Standard_Boolean AIS_ViewCube::IsAutoTransform() const
 //purpose  :
 //=======================================================================
 Standard_Integer AIS_ViewCube::addPart (const Handle(Part)& thePart,
-                                         const gp_Dir& theDir, const gp_Dir& theUp,
-                                         const Standard_Integer thePriority)
+                                        const gp_Dir& theDir, const gp_Dir& theUp,
+                                        const Standard_Integer thePriority)
 {
   Handle(SelectMgr_EntityOwner) anOwner = new AIS_ViewCubeOwner (this, thePriority);
   myStates.Add (anOwner, new CameraStateReplace (theDir, theUp));
@@ -1156,8 +1172,8 @@ Standard_Integer AIS_ViewCube::addPart (const Handle(Part)& thePart,
 //purpose  :
 //=======================================================================
 Standard_Integer AIS_ViewCube::addPart (const Handle(Part)& thePart,
-                                         const Standard_Real theAngleX, const Standard_Real theAngleY, const Standard_Real theAngleZ,
-                                         const Standard_Integer thePriority)
+                                        const Standard_Real theAngleX, const Standard_Real theAngleY, const Standard_Real theAngleZ,
+                                        const Standard_Integer thePriority)
 {
   Handle(SelectMgr_EntityOwner) anOwner = new AIS_ViewCubeOwner (this, thePriority);
   myStates.Add (anOwner, new CameraStateRotate (theAngleX, theAngleY, theAngleZ));
@@ -1225,8 +1241,8 @@ void AIS_ViewCube::setLocalTransformation (const Handle(Geom_Transformation)& /*
 //purpose  :
 //=======================================================================
 void AIS_ViewCube::HilightOwnerWithColor (const Handle(PrsMgr_PresentationManager3d)& thePM,
-                                           const Handle(Prs3d_Drawer)& theStyle,
-                                           const Handle(SelectMgr_EntityOwner)& theOwner)
+                                          const Handle(Prs3d_Drawer)& theStyle,
+                                          const Handle(SelectMgr_EntityOwner)& theOwner)
 {
   if (theOwner.IsNull())
   {
@@ -1240,6 +1256,18 @@ void AIS_ViewCube::HilightOwnerWithColor (const Handle(PrsMgr_PresentationManage
     return;
   }
 
+  // Manage view affinity if it is enabled for object
+  Handle(Graphic3d_ViewAffinity) anAffinity = GetContext()->CurrentViewer()->StructureManager()->ObjectAffinity (this);
+  if (anAffinity->IsVisible (View()->View()->Identification()))
+  {
+    if (aPresentation->CStructure()->ViewAffinity.IsNull())
+    {
+      aPresentation->CStructure()->ViewAffinity = new Graphic3d_ViewAffinity;
+    }
+    aPresentation->CStructure()->ViewAffinity->SetVisible (Standard_False);
+    aPresentation->CStructure()->ViewAffinity->SetVisible (View()->View()->Identification(), Standard_True);
+  }
+
   aPresentation->Highlight (theStyle);
   for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (aPresentation->Groups());
        aGroupIter.More(); aGroupIter.Next())
@@ -1591,7 +1619,7 @@ void AIS_ViewCube::Side::Display (const Handle(PrsMgr_PresentationManager)& theP
   aTopRight = aTopLeft.XYZ() + aPosition.XDirection().XYZ() * aSize;
   aBottomRight = aBottomLeft.XYZ() + aPosition.XDirection().XYZ() * aSize;
   const Standard_Real aCoef = aSize * 0.5;
-  gp_Ax2 aTextPosition (aPosition.Translated (gp_Vec (aPosition.XDirection().XYZ() * aCoef + aPosition.YDirection().XYZ() * aCoef + aPosition.Direction().XYZ() * aSize * 0.05)));
+  gp_Ax2 aTextPosition (aPosition.Translated (gp_Vec (aPosition.XDirection().XYZ() * aCoef + aPosition.YDirection().XYZ() * aCoef + aPosition.Direction().XYZ() * aSize * 0.02)));
 
   Handle(Graphic3d_ArrayOfTriangles) anArray;
   Handle(Poly_Triangulation) aTri;
index 008e0ca303ef37046a45ca46a9dc237efe87a929..a903ce640285b34051f13d73d2647cda23ff7b73 100644 (file)
@@ -58,12 +58,13 @@ class AIS_ViewCubeFlat;
 //! Handle(AIS_ViewCube) aViewCube = new AIS_ViewCube();
 //! aViewCube->AddTo (aContext, aView);
 //! @endcode
-//! or
+//! or it can be just be displayed without iew affinity option (in this case it will be displayed in all views):
 //! @code
-//! aView->SetView (aView);
-//! aContext->Display (aViewCube, 0, 0, Standard_False);
+//! Handle(AIS_ViewCube) aViewCube = new AIS_ViewCube();
+//! Handle(AIS_InteractiveContext) aContext;
+//! aContext->Display (aViewCube, Standard_False);
 //! @endcode
-//! But View Affinity should be taken into account here also.
+//!
 //! View Cube parts are sensitive to detection, or dynamic highlighting (but not selection), and every its owner corresponds to camera transformation.
 //! So, once one of the owners of View Cube is detected, application is to be call StartTransform (anOwner) and Transform (anOwner) for starting
 //! animation of transformation.
@@ -81,6 +82,9 @@ class AIS_ViewCubeFlat;
 //! that includes transformation loop.
 //! This loop allows external actions like application updating. For this purpose AIS_ViewCube has virtual interface onAfterTransform(),
 //! that is to be redefined on application level.
+//! Note that after modification end no highlighting is restored by default.
+//! This means that after transformation of box if mouse pointer still points to box, it will not be highlighted. 
+//! Highlighting restoring of box is to be made on application level with AIS_InteracitveContext::MoveTo() method.
 //!
 //! @b Positioning:
 //! View Cube is attached to one defined point in the view plane. This point of attachment is placed in the center of view
@@ -114,6 +118,12 @@ public:
   //! @param theView [in] 3D view.
   Standard_EXPORT void AddTo (const Handle(AIS_InteractiveContext)& theContext, const Handle(V3d_View)& theView);
 
+  //! Make view cube visible only in the input view
+  //! @param theView [in] V3d View object
+  //! @warning This method should be called after View Cube is displayed in context
+  //!          or it will have no effect
+  Standard_EXPORT void SetViewAffinity (const Handle(V3d_View)& theView);
+
   //! Hide View Cube in view
   Standard_EXPORT void Hide();
 
@@ -145,13 +155,18 @@ protected:
   //! Set default visual attributes
   Standard_EXPORT void setDefaultAttributes();
 
+  //! Set default dynamic highlight properties
   Standard_EXPORT void setDefaultHighlightAttributes();
 
 public: //! @name Geometry management API
 
+  //! @return position of center of View Cube in terms of 2d trandform  persistence.
+  //! @sa Aspect_TypeOfTriedronPosition, Graphic3d_Vec2i
   Standard_EXPORT void Position (Aspect_TypeOfTriedronPosition& thePosition,
                                  Graphic3d_Vec2i& theOffset);
 
+  //! @return position of center of View Cube in screen cooordinates
+  //! (origin of system if topleft corner). 
   Standard_EXPORT Graphic3d_Vec2i Position() const;
 
   //! Set position of center of View Cube in view plane depending on size of view.
index d94673598a0b6519e36a0a414c7a1026ed57f4a2..0b9f05346ad267e2e7d221aa1bacd8b4d2f598fc 100644 (file)
@@ -11,7 +11,7 @@ vclose ALL
 vinit
 
 vviewcube -enable -hideedges
-if {[vreadpixel 186 236 name] != "BLACK 1"} {
+if {[vreadpixel 186 236 name] != "BLACK 0"} {
   puts "ERROR: Invalid display of View Cube without edges."
 }
 vdump $anImage1
@@ -24,7 +24,7 @@ vdump $anImage2
 
 vviewcube -hideedges -hidevertices
 
-if {[vreadpixel 186 236 name] != "BLACK 1" || [vreadpixel 150 258 name] != "BLACK 0"} {
+if {[vreadpixel 186 236 name] != "BLACK 0" || [vreadpixel 150 258 name] != "BLACK 0"} {
   puts "ERROR: Invalid display of View Cube without edges & vertices."
 }
 vdump $anImage3
index b98b607b60ab6a444da4383f40e25951362c27d3..d810a2c54dffded9fe8871ff926d68b26a5ed14c 100644 (file)
@@ -17,7 +17,7 @@ vinit
 # Color
 # -------------------------------------
 vviewcube -enable -boxcolor 0.69 0.88 1 -arrowcolor 0 0.4 0.54 -textcolor 0 0.4 0.54
-if {[vreadpixel 118 273 name] != "LIGHTSLATEGRAY 1" || [vreadpixel 270 260 name] != "GRAY15 0.24705882352941178"} {
+if {[vreadpixel 118 273 name] != "LIGHTSLATEGRAY 1" || [vreadpixel 270 260 name] != "GRAY15 0.24705882370471954"} {
   puts "ERROR: Errors in changing View Cube colors."
 }
 vdump $anImage1
@@ -27,14 +27,14 @@ vdump $anImage1
 # -------------------------------------
 vviewcube -reset
 vviewcube -transparency 0.5
-if {[vreadpixel 118 273 name] != "GRAY17 0.37254901960784315" || [vreadpixel 270 260 name] != "GRAY48 0.24705882352941178"} {
+if {[vreadpixel 118 273 name] != "GRAY17 0.37254902720451355" || [vreadpixel 270 260 name] != "GRAY48 0.24705882370471954"} {
   puts "ERROR: Errors in changing View Cube common transparency."
 }
 vdump $anImage2
 
 vviewcube -reset
 vviewcube -boxtransparency 0.4 -arrowtransparency 0.2
-if {[vreadpixel 118 273 name] != "GRAY16 0.50588235294117645" || [vreadpixel 270 260 name] != "GRAY76 0.63921568627450975"} {
+if {[vreadpixel 118 273 name] != "GRAY16 0.5058823823928833" || [vreadpixel 270 260 name] != "GRAY76 0.63921570777893066"} {
   puts "ERROR: Errors in changing View Cube separate transparency."
 }
 vdump $anImage3
@@ -44,7 +44,7 @@ vdump $anImage3
 # -------------------------------------
 vviewcube -reset
 vviewcube -arrowangle 30 -arrowlength 30
-if {[vreadpixel 270 268 name] != "BLACK 0" || [vreadpixel 291 259 name] != "GRAY48 0.24705882352941178"} {
+if {[vreadpixel 270 268 name] != "BLACK 0" || [vreadpixel 291 259 name] != "GRAY48 0.24705882370471954"} {
   puts "ERROR: Errors in changing View Cube arrow style."
 }
 vdump $anImage4
@@ -53,8 +53,8 @@ vdump $anImage4
 # Font
 # -------------------------------------
 vviewcube -reset
-vviewcube -font "Impact"
-if {[vreadpixel 151 198 name] != "BLACK 1" || [vreadpixel 168 391 name] != "RED 1"} {
+vviewcube -font "Impact" -fontheight 16
+if {[vreadpixel 150 200 name] != "BLACK 0.729411780834198" || [vreadpixel 168 391 name] != "RED 1"} {
   puts "ERROR: Errors in changing View Cube font."
 }
 vdump $anImage5
@@ -73,7 +73,10 @@ vdump $anImage6
 # Corner radius
 # -------------------------------------
 vviewcube -reset
-vviewcube -cornerradius 0.3
+vviewcube -cornerradius 0.2
 vdump $anImage7
 
+vviewcube -remove
+vclear
+
 
diff --git a/tests/v3d/viewcube/view b/tests/v3d/viewcube/view
new file mode 100644 (file)
index 0000000..c978565
--- /dev/null
@@ -0,0 +1,28 @@
+puts "=================================="
+puts "AIS_ViewCube - check view affinity"
+puts "=================================="
+
+set anImage1 $imagedir/${casename}_1.png
+set anImage2 $imagedir/${casename}_2.png
+
+vclear
+vclose ALL
+vinit view1
+vinit view2
+
+vviewcube -enable
+
+if {[vreadpixel 150 220 name] != "GRAY68 1"} {
+  puts "ERROR: display of View Cube in view2 fails."
+}
+vdump $anImage1
+
+vactivate view1
+
+if {[vreadpixel 150 220 name] != "BLACK 0"} {
+  puts "ERROR: View Cube should not be displayed in view1."
+}
+vdump $anImage2
+
+vactivate view2
+vviewcube -remove
\ No newline at end of file
diff --git a/tests/v3d/viewcube/view2 b/tests/v3d/viewcube/view2
new file mode 100644 (file)
index 0000000..27c277f
--- /dev/null
@@ -0,0 +1,25 @@
+puts "=================================="
+puts "AIS_ViewCube - check view affinity"
+puts "=================================="
+
+set anImage1 $imagedir/${casename}_1.png
+set anImage2 $imagedir/${casename}_2.png
+
+vclear
+vclose ALL
+vinit view1
+
+vviewcube -enable
+if {[vreadpixel 150 220 name] != "GRAY68 1"} {
+  puts "ERROR: display of View Cube in view1 fails."
+}
+vdump $anImage1
+vviewcube -remove
+
+vinit view2
+vviewcube -enable
+if {[vreadpixel 150 220 name] != "GRAY68 1"} {
+  puts "ERROR: View Cube should not be displayed in view1."
+}
+vdump $anImage2
+vviewcube -remove
\ No newline at end of file