private static bool CreateLights(V3dViewer viewer) { var ambientLight = new V3dAmbientLight(viewer, QuantityNameOfColor.Quantity_NOC_GRAY50); Debug.Assert(ambientLight != null); var directionalLight = new V3dDirectionalLight(viewer, V3dTypeOfOrientation.V3d_XnegYnegZneg, QuantityNameOfColor.Quantity_NOC_GRAY75, false); Debug.Assert(directionalLight != null); var directionalLight1 = new V3dDirectionalLight(viewer, V3dTypeOfOrientation.V3d_Xpos, QuantityNameOfColor.Quantity_NOC_GRAY25, false); Debug.Assert(directionalLight1 != null); var directionalLight2 = new V3dDirectionalLight(viewer, V3dTypeOfOrientation.V3d_Ypos, QuantityNameOfColor.Quantity_NOC_GRAY25, false); Debug.Assert(directionalLight2 != null); var directionalLight3 = new V3dDirectionalLight(viewer, V3dTypeOfOrientation.V3d_Zpos, QuantityNameOfColor.Quantity_NOC_GRAY25, false); Debug.Assert(directionalLight3 != null); return(true); }
/// <summary> /// Initializes the OpenCascade views and assigns them View handles. /// </summary> private static void Setup(ref V3dViewer viewer, ref AISInteractiveContext context, ref V3dPerspectiveView view, Control control) { // Initialize the Device var device = new Graphic3dWNTGraphicDevice(); // Create the V3d Viewer //QuantityColor color = new QuantityColor(70 / 255.0, 82 / 255.0, 102 / 255.0, QuantityTypeOfColor.Quantity_TOC_RGB); viewer = new V3dViewer(device, "Preview", "Render", 1000, V3dTypeOfOrientation.V3d_XposYnegZpos, QuantityNameOfColor.Quantity_NOC_GRAY30, V3dTypeOfVisualization.V3d_ZBUFFER, V3dTypeOfShadingModel.V3d_GOURAUD, V3dTypeOfUpdate.V3d_WAIT, true, true, V3dTypeOfSurfaceDetail.V3d_TEX_NONE); if (CreateLights(viewer)) { viewer.SetLightOn(); } // Create the Interactive Context context = new AISInteractiveContext(viewer); // Create an OpenCascade view for each visible Custom controls view = CreateView(device, viewer, control); SetVisualMode(context); }
private void ExractViews(DataPackage data) { var viewItems = data.Get<ViewInput.Items>(); Viewer = viewItems.Viewer; View = viewItems.View; KeysMappingSingleton.Instance.UpdateView(View); }
//-------------------------------------------------------------------------------------------------- public void InitAisContext() { if (V3dViewer == null) { InitV3dViewer(); } if (AisContext == null) { AisContext = new AIS_InteractiveContext(V3dViewer); AisContext.UpdateCurrentViewer(); } AisContext.SetAutoActivateSelection(true); AisContext.SetPickingStrategy(SelectMgr_PickingStrategy.SelectMgr_PickingStrategy_OnlyTopmost); AisContext.SetDisplayMode((int)AIS_DisplayMode.AIS_Shaded, false); V3dViewer.DisplayPrivilegedPlane(true, 1.0); AisContext.EnableDrawHiddenLine(); // Reinit ais parameters _ApplyWorkingContext(); AisContext?.SetPixelTolerance(2); var drawer = AisContext.DefaultDrawer(); drawer.SetWireAspect(new Prs3d_LineAspect(Colors.Selection, Aspect_TypeOfLine.Aspect_TOL_SOLID, 1.0)); //drawer.SetTypeOfHLR(Prs3d_TypeOfHLR.Prs3d_TOH_Algo); drawer.SetTypeOfHLR(Prs3d_TypeOfHLR.Prs3d_TOH_PolyAlgo); }
//-------------------------------------------------------------------------------------------------- public XY ComputeGridPoint(XY coord) { double resX = 0, resY = 0; V3dViewer.Grid().Compute(coord.X, coord.Y, ref resX, ref resY); return(new XY(resX, resY)); }
public ViewInput(V3dView view, V3dViewer viewer, Control control) : base(InputNames.View) { _view = view; _viewer = viewer; _manager = new OcLayer2DManager(view, control); }
//-------------------------------------------------------------------------------------------------- void _UpdateGrid() { if (V3dViewer is null) { return; } if (_GridEnabled) { if (_CurrentWorkingContext.GridType == GridTypes.Rectangular) { V3dViewer.ActivateGrid(Aspect_GridType.Aspect_GT_Rectangular, Aspect_GridDrawMode.Aspect_GDM_Lines); V3dViewer.SetRectangularGridValues(0, 0, _CurrentWorkingContext.GridStep, _CurrentWorkingContext.GridStep, _CurrentWorkingContext.GridRotation.ToRad()); V3dViewer.SetRectangularGridGraphicValues(100 * _CurrentWorkingContext.GridStep, 100 * _CurrentWorkingContext.GridStep, -0.0001); } else { V3dViewer.ActivateGrid(Aspect_GridType.Aspect_GT_Circular, Aspect_GridDrawMode.Aspect_GDM_Lines); V3dViewer.SetCircularGridValues(0, 0, _CurrentWorkingContext.GridStep, _CurrentWorkingContext.GridDivisions, _CurrentWorkingContext.GridRotation.ToRad()); V3dViewer.SetCircularGridGraphicValues(100 * _CurrentWorkingContext.GridStep, -0.0001); } V3dViewer.SetGridEcho(true); } else { V3dViewer.SetGridEcho(false); V3dViewer.DeactivateGrid(); } NeedsRedraw = true; NeedsImmediateRedraw = true; }
/// <summary> /// Initializes the OpenCascade views and assigns them View handles. /// </summary> public static void Setup(ref Graphic3dWNTGraphicDevice device, ref V3dViewer viewer, ref AISInteractiveContext context, out V3dView view, IOccContainerMultiView attachedView) { // Initialize the Device try { device = new Graphic3dWNTGraphicDevice(); Debug.Assert(device != null); } catch (Exception ex) { Debug.Assert(false, ex.Message); } // Create the V3d Viewer try { //QuantityColor color = new QuantityColor(70 / 255.0, 82 / 255.0, 102 / 255.0, QuantityTypeOfColor.Quantity_TOC_RGB); viewer = new V3dViewer(device, "Visu3D", "", 1000, V3dTypeOfOrientation.V3d_XposYnegZpos, QuantityNameOfColor.Quantity_NOC_GRAY30, V3dTypeOfVisualization.V3d_ZBUFFER, V3dTypeOfShadingModel.V3d_GOURAUD, V3dTypeOfUpdate.V3d_WAIT, true, true, V3dTypeOfSurfaceDetail.V3d_TEX_NONE); Debug.Assert(viewer != null); if (CreateLights(viewer)) { viewer.SetLightOn(); } } catch (Exception ex) { Debug.Assert(false, ex.Message); } // Create the Interactive Context try { context = new AISInteractiveContext(viewer); Debug.Assert(context != null); context.HilightColor = (QuantityNameOfColor.Quantity_NOC_RED); } catch (Exception ex) { Debug.Assert(false, ex.Message); } // Create an OpenCascade view for each visible Custom controls CreateView(device, viewer, out view, attachedView); //PaintBackground(view, Color.LightBlue, Color.Blue); SetVisualMode(context); }
//-------------------------------------------------------------------------------------------------- public void Dispose() { AisContext?.Dispose(); AisContext = null; if (V3dViewer != null && !V3dViewer.IsDisposed()) { V3dViewer.SetViewOff(); V3dViewer.Dispose(); V3dViewer = null; } Model = null; }
private static bool CreateLights(V3dViewer viewer) { new V3dAmbientLight(viewer, QuantityNameOfColor.Quantity_NOC_GRAY50); new V3dDirectionalLight(viewer, V3dTypeOfOrientation.V3d_XnegYnegZneg, QuantityNameOfColor.Quantity_NOC_GRAY75, false); new V3dDirectionalLight(viewer, V3dTypeOfOrientation.V3d_Xpos, QuantityNameOfColor.Quantity_NOC_GRAY25, false); new V3dDirectionalLight(viewer, V3dTypeOfOrientation.V3d_Ypos, QuantityNameOfColor.Quantity_NOC_GRAY25, false); new V3dDirectionalLight(viewer, V3dTypeOfOrientation.V3d_Zpos, QuantityNameOfColor.Quantity_NOC_GRAY25, false); return(true); }
public static int Main() { var confusion = Precision.Confusion; var mainWindow = new MainWindow(); var panel = mainWindow.panel1; Graphic3dWNTGraphicDevice device = null; V3dViewer viewer = null; AISInteractiveContext context = null; V3dView view; OccInitialize.Setup(ref device, ref viewer, ref context, out view, panel); //var point = new gpPnt(); //var secondPoint = point.Convert<gpPnt>(); //Console.WriteLine(point.X); return(0); }
protected override void OnReceiveInputData(string inputName, DataPackage data) { switch (inputName) { case InputNames.View: { var viewItems = data.Get <ViewInput.Items>(); View = viewItems.View; Viewer = viewItems.Viewer; } break; default: base.OnReceiveInputData(inputName, data); break; } }
//-------------------------------------------------------------------------------------------------- public void InitV3dViewer() { if (V3dViewer == null) { var ocGraphicDriver = Occt.Helper.Graphic3d.CreateOpenGlDriver(); V3dViewer = new V3d_Viewer(ocGraphicDriver); } V3dViewer.SetDefaultViewSize(1000.0); V3dViewer.SetDefaultViewProj(V3d_TypeOfOrientation.V3d_XposYposZpos); V3dViewer.SetDefaultBackgroundColor(Quantity_NameOfColor.Quantity_NOC_GRAY30.ToColor()); V3dViewer.SetDefaultVisualization(V3d_TypeOfVisualization.V3d_ZBUFFER); V3dViewer.SetLightOn(new V3d_DirectionalLight(V3d_TypeOfOrientation.V3d_Zneg, Quantity_NameOfColor.Quantity_NOC_WHITE.ToColor(), true)); V3dViewer.SetLightOn(new V3d_AmbientLight(Quantity_NameOfColor.Quantity_NOC_WHITE.ToColor())); V3dViewer.Grid().SetColors(Quantity_NameOfColor.Quantity_NOC_GRAY45.ToColor(), Quantity_NameOfColor.Quantity_NOC_GRAY30.ToColor()); // Reinit viewer parameters _ApplyWorkingContext(); }
private static void CreateView(WNTGraphicDevice device, V3dViewer viewer, out V3dView view, IOccContainerMultiView attachedView) { // Assign to each Custom control an OpenCascade View view = null; Ensure.AreEqual(attachedView.VisibleViewCount, 1); for (var i = 0; i < attachedView.VisibleViewCount; i++) { view = viewer.CreateView; Debug.Assert(view != null); view.SetDegenerateModeOn(); view.Transparency = true; view.SurfaceDetail = V3dTypeOfSurfaceDetail.V3d_TEX_ALL; // Attach to the OpenCascade view a Custom control var control = attachedView.GetView(i); if (control == null) { continue; } //IntPtr attachedViewHandle = (attachedView as Form).Handle; var aWntWindow = new WNTWindow(device, control.Handle, QuantityNameOfColor.Quantity_NOC_MATRAGRAY); Debug.Assert(aWntWindow != null); view.SetWindow(aWntWindow); view.TriedronDisplay(AspectTypeOfTriedronPosition.Aspect_TOTP_LEFT_LOWER, QuantityNameOfColor.Quantity_NOC_WHITE, 0.02, V3dTypeOfVisualization.V3d_WIREFRAME); if (!aWntWindow.IsMapped) { aWntWindow.Map(); } //view[i].SetAntialiasingOn(); //view[i].Redraw(); view.MustBeResized(); } }
//-------------------------------------------------------------------------------------------------- public void InitV3dViewer() { if (V3dViewer == null) { var ocGraphicDriver = Occt.Helper.Graphic3d.CreateOpenGlDriver(); V3dViewer = new V3d_Viewer(ocGraphicDriver, "MyView", "", 1000.0, V3d_TypeOfOrientation.V3d_XposYposZpos, Quantity_NameOfColor.Quantity_NOC_GRAY30.ToColor(), V3d_TypeOfVisualization.V3d_ZBUFFER); } V3dViewer.SetLightOn(new V3d_DirectionalLight(V3d_TypeOfOrientation.V3d_Zneg, Quantity_NameOfColor.Quantity_NOC_WHITE.ToColor(), true)); V3dViewer.SetLightOn(new V3d_AmbientLight(Quantity_NameOfColor.Quantity_NOC_WHITE.ToColor())); //V3dViewer.Grid().SetColors(new Quantity_Color(Quantity_NameOfColor.Quantity_NOC_GRAY55), new Quantity_Color(Quantity_NameOfColor.Quantity_NOC_GRAY70)); V3dViewer.Grid().SetColors(Quantity_NameOfColor.Quantity_NOC_GRAY45.ToColor(), Quantity_NameOfColor.Quantity_NOC_GRAY30.ToColor()); // Reinit viewer parameters _ApplyWorkingContext(); _UpdateGrid(); }
private static V3dPerspectiveView CreateView(WNTGraphicDevice device, V3dViewer viewer, Control control) { // Assign to each Custom control an OpenCascade View var view = new V3dPerspectiveView(viewer); view.SetDegenerateModeOn(); view.Transparency = true; view.SurfaceDetail = V3dTypeOfSurfaceDetail.V3d_TEX_ALL; // Attach to the OpenCascade view a Custom control //IntPtr attachedViewHandle = (attachedView as Form).Handle; var aWntWindow = new WNTWindow(device, control.Handle, QuantityNameOfColor.Quantity_NOC_MATRAGRAY); view.SetWindow(aWntWindow); view.TriedronDisplay( AspectTypeOfTriedronPosition.Aspect_TOTP_LEFT_LOWER, QuantityNameOfColor.Quantity_NOC_WHITE, 0.02, V3dTypeOfVisualization.V3d_WIREFRAME); if (!aWntWindow.IsMapped) { aWntWindow.Map(); } //view.SetAntialiasingOn(); view.Redraw(); view.MustBeResized(); view.Reset(true); return(view); }
public Items(V3dView view, V3dViewer viewer) { View = view; Viewer = viewer; }
/// <summary> /// Initializes the OpenCascade views and assigns them View handles. /// </summary> private void InitializeOpenCascade() { // Initialize the Devices device3d = new Graphic3dWNTGraphicDevice(); // Create the V3d Viewer try { viewer3d = new V3dViewer(device3d, "Hello", "", 100, V3dTypeOfOrientation.V3d_XnegYpos, QuantityNameOfColor.Quantity_NOC_ALICEBLUE, V3dTypeOfVisualization.V3d_ZBUFFER, V3dTypeOfShadingModel.V3d_GOURAUD, V3dTypeOfUpdate.V3d_WAIT, true, true, V3dTypeOfSurfaceDetail.V3d_TEX_ALL); // manual default Debug.Assert(viewer3d != null); if (CreateLights()) { viewer3d.SetLightOn(); } } catch (Exception ex) { Debug.Assert(false, ex.Message); throw; //re-throw exception } // Create the 3D Interactive Context try { context3d = new AISInteractiveContext(this.viewer3d); Debug.Assert(context3d != null); if (context3d != null) { //context3d.HilightColor = NameOfColor.Quantity_NOC_DARKSLATEGRAY; //context3d.SelectionColor = NameOfColor.Quantity_NOC_WHITE; } } catch (Exception ex) { Debug.Assert(false, ex.Message); throw; // re-throw exception } // create the 2D interactive context //try //{ // context2d = new AIS2D_InteractiveContext(this.viewer2d); // Debug.Assert(context2d != null); // if (context2d != null) // { // //context.HilightColor = NameOfColor.Quantity_NOC_DARKSLATEGRAY; // //context.SelectionColor = NameOfColor.Quantity_NOC_WHITE; // } //} //catch (Exception ex) //{ // Debug.Assert(false, ex.Message); // throw; // re-throw exception //} // Create an OpenCascade view for each visible Custom controls CreateView3D(); //CreateView2D(); //SetVisualMode(); //bool executeTemporaryCode = true; //if (executeTemporaryCode) //{ // temporary code ------------------- // Draw a box for (int i = 0; i < 500; i += 10) { var pnt = new gpPnt(i, i, i); //OCBRepPrimAPI_MakeBox box = new BRepPrimAPI_MakeBox(pnt, 100, 100, 100); var box = new BRepPrimAPIMakeBox(pnt, 50, 50, 50); var shape = new AISShape(box.Shape); context3d.Display(shape, false); // manual default } view3d.FitAll(0.01, false, true); // manual default // ----------------------------------- //} // Build an XYZ axis trihedron and add it to Ocaf var coords = gp.ZOX; coords.Location = new gpPnt(0, 0, 0); var axis = new GeomAxis2Placement(coords); var trihedron = new AISTrihedron(axis) { Size = 200 }; context3d.Display(trihedron, false); }