0028895: Visualization, V3d_View::SetComputedMode() - HLR calculation is performed...
[occt.git] / samples / CSharp / OCCTProxy_D3D / OCCTProxyD3D.cpp
index 44a637a..413674e 100644 (file)
 #include <Graphic3d_Camera.hxx>
 #include <Graphic3d_TextureParams.hxx>
 #include <D3DHost_GraphicDriver.hxx>
+#include <D3DHost_View.hxx>
 //for object display
 #include <V3d_Viewer.hxx>
 #include <V3d_View.hxx>
-#include <Visual3d_View.hxx>
 #include <AIS_InteractiveContext.hxx>
 #include <AIS_Shape.hxx>
 //topology
@@ -78,12 +78,7 @@ public:
     myGraphicDriver()->ChangeOptions().buffersNoSwap = true;
     //myGraphicDriver()->ChangeOptions().contextDebug = true;
 
-    TCollection_ExtendedString a3DName ("Visu3D");
-    myViewer() = new V3d_Viewer (myGraphicDriver(), a3DName.ToExtString(), "", 1000.0,
-                                 V3d_XposYnegZpos, Quantity_NOC_GRAY30,
-                                 V3d_ZBUFFER, V3d_GOURAUD, V3d_WAIT,
-                                 Standard_True, Standard_False);
-
+    myViewer() = new V3d_Viewer (myGraphicDriver());
     myViewer()->SetDefaultLights();
     myViewer()->SetLightOn();
     myView() = myViewer()->CreateView();
@@ -106,7 +101,7 @@ public:
     aWNTWindow->SetPos (0, 0, theWinSizeX, theWinSizeY);
     myView()->MustBeResized();
     myView()->Invalidate();
-    return System::IntPtr(myGraphicDriver()->D3dColorSurface (myView()->View()));
+    return System::IntPtr(Handle(D3DHost_View)::DownCast (myView()->View())->D3dColorSurface());
   }
 
   /// <summary>
@@ -153,6 +148,7 @@ public:
     if (!myView().IsNull())
     {
       myView()->SetComputedMode (Standard_False);
+      myView()->Redraw();
     }
   }
 
@@ -164,6 +160,7 @@ public:
     if (!myView().IsNull())
     {
       myView()->SetComputedMode (Standard_True);
+      myView()->Redraw();
     }
   }
 
@@ -185,7 +182,7 @@ public:
   /// <param name="theZoomFactor">Current zoom</param>
   void Place (int theX, int theY, float theZoomFactor)
   {    
-    Quantity_Factor aZoomFactor = theZoomFactor;
+    Standard_Real aZoomFactor = theZoomFactor;
     if (!myView().IsNull())
     {
       myView()->Place (theX, theY, aZoomFactor);
@@ -243,7 +240,7 @@ public:
   {
     if (!myAISContext().IsNull())
     {
-      myAISContext()->Select (theX1, theY1, theX2, theY2, myView());
+      myAISContext()->Select (theX1, theY1, theX2, theY2, myView(), Standard_True);
     }
   }
 
@@ -254,7 +251,7 @@ public:
   {
     if (!myAISContext().IsNull())
     {
-      myAISContext()->Select();
+      myAISContext()->Select (Standard_True);
     }
   }
 
@@ -265,7 +262,7 @@ public:
   {
     if (!myAISContext().IsNull() && !myView().IsNull())
     {
-      myAISContext()->MoveTo (theX, theY, myView());
+      myAISContext()->MoveTo (theX, theY, myView(), Standard_True);
     }
   }
 
@@ -276,7 +273,7 @@ public:
   {
     if (!myAISContext().IsNull() && !myView().IsNull())
     {
-      myAISContext()->ShiftSelect (theX1, theY1, theX2, theY2, myView());
+      myAISContext()->ShiftSelect (theX1, theY1, theX2, theY2, myView(), Standard_True);
     }
   }
 
@@ -287,7 +284,7 @@ public:
   {
     if (!myAISContext().IsNull())
     {
-      myAISContext()->ShiftSelect();
+      myAISContext()->ShiftSelect (Standard_True);
     }
   }
 
@@ -353,7 +350,7 @@ public:
   {
     if (!myView().IsNull())
     {
-      myView()->SetProj (V3d_Xpos);
+      myView()->SetProj (V3d_Yneg);
     }
   }
 
@@ -375,7 +372,7 @@ public:
   {
     if (!myView().IsNull())
     {
-      myView()->SetProj (V3d_Ypos);
+      myView()->SetProj (V3d_Xneg);
     }
   }
 
@@ -386,7 +383,7 @@ public:
   {
     if (!myView().IsNull())
     {
-      myView()->SetProj (V3d_Xneg);
+      myView()->SetProj (V3d_Ypos);
     }
   }
 
@@ -397,7 +394,7 @@ public:
   {
     if (!myView().IsNull())
     {
-      myView()->SetProj (V3d_Yneg);
+      myView()->SetProj (V3d_Xpos);
     }
   }
 
@@ -470,16 +467,15 @@ public:
     AIS_DisplayMode aCurrentMode = theMode == 0
                                  ? AIS_WireFrame
                                  : AIS_Shaded;
-    if (myAISContext()->NbCurrents() == 0
-     || myAISContext()->NbSelected() == 0)
+    if (myAISContext()->NbSelected() == 0)
     {
-       myAISContext()->SetDisplayMode (aCurrentMode);
+       myAISContext()->SetDisplayMode (aCurrentMode, Standard_False);
     }
     else
     {
-       for (myAISContext()->InitCurrent(); myAISContext()->MoreCurrent(); myAISContext()->NextCurrent())
+       for (myAISContext()->InitSelected(); myAISContext()->MoreSelected(); myAISContext()->NextSelected())
        {
-         myAISContext()->SetDisplayMode (myAISContext()->Current(), theMode, Standard_False);
+         myAISContext()->SetDisplayMode (myAISContext()->SelectedInteractive(), theMode, Standard_False);
        }
     }
     myAISContext()->UpdateCurrentViewer();
@@ -496,10 +492,11 @@ public:
     }
 
     Quantity_Color aCol (theR / 255.0, theG / 255.0, theB / 255.0, Quantity_TOC_RGB);
-    for (; myAISContext()->MoreCurrent(); myAISContext()->NextCurrent())
+    for (; myAISContext()->MoreSelected(); myAISContext()->NextSelected())
     {
-      myAISContext()->SetColor (myAISContext()->Current(), aCol.Name());
+      myAISContext()->SetColor (myAISContext()->SelectedInteractive(), aCol, false);
     }
+    myAISContext()->UpdateCurrentViewer();
   }
 
   /// <summary>
@@ -545,16 +542,17 @@ public:
     theRed   = 255;
     theGreen = 255;
     theBlue  = 255;
-    myAISContext()->InitCurrent();
-    if (!myAISContext()->MoreCurrent())
+    myAISContext()->InitSelected();
+    if (!myAISContext()->MoreSelected())
     {
       return;
     }
 
-    Handle(AIS_InteractiveObject) aCurrent = myAISContext()->Current();
+    Handle(AIS_InteractiveObject) aCurrent = myAISContext()->SelectedInteractive();
     if (aCurrent->HasColor())
     {
-      Quantity_Color anObjCol = myAISContext()->Color (myAISContext()->Current());
+      Quantity_Color anObjCol;
+      myAISContext()->Color (aCurrent, anObjCol);
       theRed   = int(anObjCol.Red()   * 255.0);
       theGreen = int(anObjCol.Green() * 255.0);
       theBlue  = int(anObjCol.Blue()  * 255.0);
@@ -582,8 +580,8 @@ public:
       return;
     }
 
-    myAISContext()->EraseSelected (Standard_True);
-    myAISContext()->ClearCurrents();
+    myAISContext()->EraseSelected (Standard_False);
+    myAISContext()->ClearSelected (Standard_True);
   }
 
   /// <summary>
@@ -603,9 +601,9 @@ public:
     {
       return;
     }
-    for (myAISContext()->InitCurrent(); myAISContext()->MoreCurrent(); myAISContext()->NextCurrent())
+    for (myAISContext()->InitSelected(); myAISContext()->MoreSelected(); myAISContext()->NextSelected())
     {
-      myAISContext()->SetMaterial (myAISContext()->Current(), (Graphic3d_NameOfMaterial )theMaterial);
+      myAISContext()->SetMaterial (myAISContext()->SelectedInteractive(), (Graphic3d_NameOfMaterial )theMaterial, Standard_False);
     }
     myAISContext()->UpdateCurrentViewer();
   }
@@ -619,10 +617,11 @@ public:
     {
       return;
     }
-    for (myAISContext()->InitCurrent(); myAISContext()->MoreCurrent(); myAISContext()->NextSelected())
+    for (myAISContext()->InitSelected(); myAISContext()->MoreSelected(); myAISContext()->NextSelected())
     {
-      myAISContext()->SetTransparency (myAISContext()->Current(), ((Standard_Real )theTrans) / 10.0);
+      myAISContext()->SetTransparency (myAISContext()->Current(), ((Standard_Real )theTrans) / 10.0, Standard_False);
     }
+    myAISContext()->UpdateCurrentViewer();
   }
 
   /// <summary>
@@ -634,8 +633,8 @@ public:
     {
       return false;
     }
-    myAISContext()->InitCurrent();
-    return myAISContext()->MoreCurrent() != Standard_False;
+    myAISContext()->InitSelected();
+    return myAISContext()->MoreSelected() != Standard_False;
   }
 
   /// <summary>
@@ -650,13 +649,13 @@ public:
 
     bool isOneOrMoreInShading   = false;
     bool isOneOrMoreInWireframe = false;
-    for (myAISContext()->InitCurrent(); myAISContext()->MoreCurrent(); myAISContext()->NextCurrent())
+    for (myAISContext()->InitSelected(); myAISContext()->MoreSelected(); myAISContext()->NextSelected())
     {
-      if (myAISContext()->IsDisplayed (myAISContext()->Current(), AIS_Shaded))
+      if (myAISContext()->IsDisplayed (myAISContext()->SelectedInteractive(), AIS_Shaded))
       {
         isOneOrMoreInShading = true;
       }
-      if (myAISContext()->IsDisplayed (myAISContext()->Current(), AIS_WireFrame))
+      if (myAISContext()->IsDisplayed (myAISContext()->SelectedInteractive(), AIS_WireFrame))
       {
         isOneOrMoreInWireframe = true;
       }
@@ -693,7 +692,7 @@ public:
   /// <summary>
   ///Get AISContext
   /// </summary>
-  Handle_AIS_InteractiveContext GetContext()
+  Handle(AIS_InteractiveContext) GetContext()
   {
     return myAISContext();
   }
@@ -734,14 +733,11 @@ public:
     {
       return false;
     }
-    if (myAISContext()->HasOpenedContext())
-    {
-      myAISContext()->CloseLocalContext();
-    }
+
     Handle(AIS_Shape) aPrs = new AIS_Shape (aShape);
-    myAISContext()->SetMaterial   (aPrs, Graphic3d_NOM_GOLD);
+    myAISContext()->SetMaterial   (aPrs, Graphic3d_NOM_GOLD, Standard_False);
     myAISContext()->SetDisplayMode(aPrs, AIS_Shaded, Standard_False);
-    myAISContext()->Display (aPrs);
+    myAISContext()->Display (aPrs, Standard_True);
     return true;
   }
 
@@ -770,8 +766,9 @@ public:
       {
         for (int aShapeIter = 1; aShapeIter <= aNbShap; ++aShapeIter)
         {
-          myAISContext()->Display (new AIS_Shape (aReader.Shape (aShapeIter)), Standard_True);
+          myAISContext()->Display (new AIS_Shape (aReader.Shape (aShapeIter)), Standard_False);
         }
+        myAISContext()->UpdateCurrentViewer();
       }
     }
     return true;
@@ -802,13 +799,13 @@ public:
   /// <param name="theFileName">Name of export file</param>
   bool ExportBRep (char* theFileName)
   {
-    myAISContext()->InitCurrent();
-    if (!myAISContext()->MoreCurrent())
+    myAISContext()->InitSelected();
+    if (!myAISContext()->MoreSelected())
     {
       return false;
     }
 
-    Handle(AIS_Shape) anIS = Handle(AIS_Shape)::DownCast (myAISContext()->Current());
+    Handle(AIS_Shape) anIS = Handle(AIS_Shape)::DownCast (myAISContext()->SelectedInteractive());
     return !anIS.IsNull()
          && BRepTools::Write (anIS->Shape(), theFileName);
   }
@@ -821,9 +818,9 @@ public:
   {
     STEPControl_StepModelType aType = STEPControl_AsIs;
     STEPControl_Writer        aWriter;
-    for (myAISContext()->InitCurrent(); myAISContext()->MoreCurrent(); myAISContext()->NextCurrent())
+    for (myAISContext()->InitSelected(); myAISContext()->MoreSelected(); myAISContext()->NextSelected())
     {
-      Handle(AIS_Shape) anIS = Handle(AIS_Shape)::DownCast (myAISContext()->Current());
+      Handle(AIS_Shape) anIS = Handle(AIS_Shape)::DownCast (myAISContext()->SelectedInteractive());
       if (anIS.IsNull())
       {
         return false;
@@ -847,9 +844,9 @@ public:
     IGESControl_Controller::Init();
     IGESControl_Writer aWriter (Interface_Static::CVal ("XSTEP.iges.unit"),
                                 Interface_Static::IVal ("XSTEP.iges.writebrep.mode"));
-    for (myAISContext()->InitCurrent(); myAISContext()->MoreCurrent(); myAISContext()->NextCurrent())
+    for (myAISContext()->InitSelected(); myAISContext()->MoreSelected(); myAISContext()->NextSelected())
     {
-      Handle(AIS_Shape) anIS = Handle(AIS_Shape)::DownCast (myAISContext()->Current());
+      Handle(AIS_Shape) anIS = Handle(AIS_Shape)::DownCast (myAISContext()->SelectedInteractive());
       if (anIS.IsNull())
       {
         return false;
@@ -871,9 +868,9 @@ public:
     TopoDS_Compound aRes;
     BRep_Builder    aBuilder;
     aBuilder.MakeCompound (aRes);
-    for (myAISContext()->InitCurrent(); myAISContext()->MoreCurrent(); myAISContext()->NextCurrent())
+    for (myAISContext()->InitSelected(); myAISContext()->MoreSelected(); myAISContext()->NextSelected())
     {
-      Handle(AIS_Shape) anIS = Handle(AIS_Shape)::DownCast (myAISContext()->Current());
+      Handle(AIS_Shape) anIS = Handle(AIS_Shape)::DownCast (myAISContext()->SelectedInteractive());
       if (anIS.IsNull())
       {
         return false;
@@ -895,9 +892,9 @@ public:
     TopoDS_Compound aComp;
     BRep_Builder    aBuilder;
     aBuilder.MakeCompound (aComp);
-    for (myAISContext()->InitCurrent(); myAISContext()->MoreCurrent(); myAISContext()->NextCurrent())
+    for (myAISContext()->InitSelected(); myAISContext()->MoreSelected(); myAISContext()->NextSelected())
     {
-      Handle(AIS_Shape) anIS = Handle(AIS_Shape)::DownCast (myAISContext()->Current());
+      Handle(AIS_Shape) anIS = Handle(AIS_Shape)::DownCast (myAISContext()->SelectedInteractive());
       if (anIS.IsNull())
       {
         return false;
@@ -965,9 +962,9 @@ public:
 
 private:
 
-  NCollection_Haft<Handle_V3d_Viewer>             myViewer;
-  NCollection_Haft<Handle_V3d_View>               myView;
-  NCollection_Haft<Handle_AIS_InteractiveContext> myAISContext;
-  NCollection_Haft<Handle_D3DHost_GraphicDriver>  myGraphicDriver;
+  NCollection_Haft<Handle(V3d_Viewer)>             myViewer;
+  NCollection_Haft<Handle(V3d_View)>               myView;
+  NCollection_Haft<Handle(AIS_InteractiveContext)> myAISContext;
+  NCollection_Haft<Handle(D3DHost_GraphicDriver)>  myGraphicDriver;
 
 };