public DisplayModeDescription GetMode(DisplayModeType modeType) { if (modeType == DisplayModeType.Other) { return(null); } if (DisplayModes.ContainsKey(modeType)) { return(DisplayModes[modeType]); // return from cache } var modeName = "SolidFix_" + modeType; var mode = DisplayModeDescription.FindByName(modeName); if (mode == null) { log.info(g.SolidFix, "\n * Cannot find SolidFix Display Mode '{0}'", modeName); var path = Path.Combine(Utils.AssemblyDirectory, @"DisplayModes\"); log.info(g.SolidFix, "* Please go to 'Options->View->Display Modes' \n and import SolidFix display mode \n from location: '{0}'\n", path); return(null); } else { DisplayModes[modeType] = mode; // cache } return(mode); }
public CanvasViewportControl() { // stupid hack to get GH to draw preview geometry in this control this.Viewport.Name = "GH_HACK"; bool gridtoggle = CanvasViewport.settings.GetValue("gridtoggle", true); bool axestoggle = CanvasViewport.settings.GetValue("axestoggle", true); bool worldtoggle = CanvasViewport.settings.GetValue("worldtoggle", true); Viewport.DisplayMode = DisplayModeDescription.FindByName(CanvasViewport.settings.GetValue("displaymode", "Wireframe")); Viewport.ConstructionGridVisible = gridtoggle; Viewport.ConstructionAxesVisible = axestoggle; Viewport.WorldAxesVisible = worldtoggle; ViewReset(); CamFetcher(); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { RhinoView view = doc.Views.ActiveView; if (null == view) { return(Result.Failure); } const string englishName = @"Shaded"; DisplayModeDescription display_mode_description = DisplayModeDescription.FindByName(englishName); if (null != display_mode_description) { view.ActiveViewport.DisplayMode = display_mode_description; view.Redraw(); } return(Result.Success); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { List <Plane> camPlanes = new List <Plane>(); DA.GetDataList <Plane>(0, camPlanes); string folder = string.Empty; DA.GetData <string>(1, ref folder); folder = Path.GetFullPath(folder); if (!folder.EndsWith(Path.DirectorySeparatorChar.ToString())) { folder += Path.DirectorySeparatorChar; } string prefix = string.Empty; DA.GetData <string>(2, ref prefix); int imageWidth = 0; DA.GetData <int>(3, ref imageWidth); imageWidth = imageWidth / 4; Size size = new Size(imageWidth, imageWidth); string displayMode = string.Empty; DA.GetData <string>(4, ref displayMode); bool run = false; DA.GetData <bool>(5, ref run); int pad = camPlanes.Count.ToString().Length; List <string> cubemaps = new List <string>(); ///Save the intial camera saveCam = camFromVP(Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport); ///Set the display mode to be used for bitmaps DisplayModeDescription viewMode = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport.DisplayMode; if (DisplayModeDescription.FindByName(displayMode) != null) { viewMode = DisplayModeDescription.FindByName(displayMode); } Message = viewMode.EnglishName; if (run) { for (int i = 0; i < camPlanes.Count; i++) { ///Setup camera Rhino.Display.RhinoView view = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView; Rhino.Display.RhinoViewport vp = view.ActiveViewport; ///Get the bounding box of all visible object in the doc for use in setting up the camera ///target so that the far frustrum plane doesn't clip anything double zoomDistance = Rhino.RhinoDoc.ActiveDoc.Objects.BoundingBoxVisible.Diagonal.Length; Plane camPlane = camPlanes[i]; Point3d camPoint = camPlane.Origin; Vector3d camDir = camPlane.YAxis; Point3d tarPoint = Transform.Translation(camDir * zoomDistance / 2) * camPoint; vp.ChangeToPerspectiveProjection(false, 12.0); //vp.Size = size; vp.DisplayMode = viewMode; //view.Redraw(); ///Set up final bitmap Bitmap cubemap = new Bitmap(imageWidth * 4, imageWidth * 3); ///Place the images on cubemap bitmap using (Graphics gr = Graphics.FromImage(cubemap)) { ///Grab bitmap ///Set up camera directions Point3d tarLeft = Transform.Translation(-camPlane.XAxis * zoomDistance / 2) * camPoint; Point3d tarFront = Transform.Translation(camPlane.YAxis * zoomDistance / 2) * camPoint; Point3d tarRight = Transform.Translation(camPlane.XAxis * zoomDistance / 2) * camPoint; Point3d tarBack = Transform.Translation(-camPlane.YAxis * zoomDistance / 2) * camPoint; Point3d tarUp = Transform.Translation(camPlane.ZAxis * zoomDistance / 2) * camPoint; Point3d tarDown = Transform.Translation(-camPlane.ZAxis * zoomDistance / 2) * camPoint; List <Point3d> camTargets = new List <Point3d>() { tarLeft, tarFront, tarRight, tarBack, tarUp, tarDown }; ///Loop through pano directions int insertLoc = 0; for (int d = 0; d < 4; d++) { ///Set camera direction vp.SetCameraLocations(camTargets[d], camPoint); ///Redraw //view.Redraw(); gr.DrawImage(view.CaptureToBitmap(size, viewMode), insertLoc, imageWidth); insertLoc = insertLoc + imageWidth; } ///Get up and down views ///Get up view vp.SetCameraLocations(tarUp, camPoint); ///Redraw view.Redraw(); var bmTop = view.CaptureToBitmap(size, viewMode); bmTop.RotateFlip(RotateFlipType.Rotate180FlipNone); gr.DrawImage(bmTop, imageWidth, 0); ///Get down view vp.SetCameraLocations(tarDown, camPoint); ///Redraw view.Redraw(); var bmBottom = view.CaptureToBitmap(size, viewMode); gr.DrawImage(view.CaptureToBitmap(size, viewMode), imageWidth, imageWidth * 2); } ///End cubemap construction loop ///Save cubemap bitmap string s = i.ToString().PadLeft(pad, '0'); string saveText = folder + prefix + "_" + s + ".png"; cubemap.Save(saveText, System.Drawing.Imaging.ImageFormat.Png); cubemaps.Add(saveText); cubemap.Dispose(); } } ///Restore initial camera setCamera(saveCam, Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport); Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.Redraw(); DA.SetDataList(0, cubemaps); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { List <Plane> camPlanes = new List <Plane>(); DA.GetDataList <Plane>(0, camPlanes); string folder = string.Empty; DA.GetData <string>(1, ref folder); bool saveCubemaps = !string.IsNullOrEmpty(folder); if (saveCubemaps) { folder = Path.GetFullPath(folder); if (!folder.EndsWith(Path.DirectorySeparatorChar.ToString())) { folder += Path.DirectorySeparatorChar; } } string prefix = string.Empty; DA.GetData <string>(2, ref prefix); int imageWidth = 0; DA.GetData <int>(3, ref imageWidth); imageWidth = imageWidth / 4; Size size = new Size(imageWidth, imageWidth); string displayMode = string.Empty; DA.GetData <string>(4, ref displayMode); List <Color> colors = new List <Color>(); DA.GetDataList <Color>(5, colors); bool filterColors = colors.Any(); GH_Structure <GH_Mesh> ghObstacles = new GH_Structure <GH_Mesh>(); DA.GetDataTree <GH_Mesh>(6, out ghObstacles); ///Flatten obstacle meshes and join them into one mesh ghObstacles.FlattenData(); Mesh obstacles = new Mesh(); bool showRays = false; if (ghObstacles.DataCount > 0) { showRays = true; foreach (var obstacle in ghObstacles) { Mesh temp = new Mesh(); GH_Convert.ToMesh(obstacle, ref temp, GH_Conversion.Primary); obstacles.Append(temp); } } bool run = false; DA.GetData <bool>(7, ref run); int pad = camPlanes.Count.ToString().Length; List <string> cubemaps = new List <string>(); GH_Structure <GH_Line> rayTree = new GH_Structure <GH_Line>(); GH_Structure <GH_Colour> colorTree = new GH_Structure <GH_Colour>(); ///Save the intial camera saveCam = camFromVP(Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport); ///Set the display mode to be used for bitmaps ///TODO: Add menu item to use "Heron View Analysis" display mode DisplayModeDescription viewMode = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport.DisplayMode; if (DisplayModeDescription.FindByName(displayMode) != null) { viewMode = DisplayModeDescription.FindByName(displayMode); } Message = viewMode.EnglishName; if (run) { for (int i = 0; i < camPlanes.Count; i++) { ///TODO: setup ability to save cameras to the Rhino doc ///Setup camera Rhino.Display.RhinoView view = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView; Rhino.Display.RhinoViewport vp = view.ActiveViewport; ///Get the bounding box of all visible object in the doc for use in setting up the camera ///target so that the far frustrum plane doesn't clip anything double zoomDistance = Rhino.RhinoDoc.ActiveDoc.Objects.BoundingBoxVisible.Diagonal.Length; Plane camPlane = camPlanes[i]; Point3d camPoint = camPlane.Origin; Vector3d camDir = camPlane.YAxis; Point3d tarPoint = Transform.Translation(camDir * zoomDistance / 2) * camPoint; vp.ChangeToPerspectiveProjection(false, 12.0); vp.Size = size; vp.DisplayMode = viewMode; //view.Redraw(); ///Set up final bitmap Bitmap cubemap = new Bitmap(imageWidth * 4, imageWidth * 3); ///Place the images on cubemap bitmap using (Graphics gr = Graphics.FromImage(cubemap)) { ///Grab bitmap ///Set up camera directions Point3d tarLeft = Transform.Translation(-camPlane.XAxis * zoomDistance / 2) * camPoint; Point3d tarFront = Transform.Translation(camPlane.YAxis * zoomDistance / 2) * camPoint; Point3d tarRight = Transform.Translation(camPlane.XAxis * zoomDistance / 2) * camPoint; Point3d tarBack = Transform.Translation(-camPlane.YAxis * zoomDistance / 2) * camPoint; Point3d tarUp = Transform.Translation(camPlane.ZAxis * zoomDistance / 2) * camPoint; Point3d tarDown = Transform.Translation(-camPlane.ZAxis * zoomDistance / 2) * camPoint; List <Point3d> camTargets = new List <Point3d>() { tarLeft, tarFront, tarRight, tarBack, tarUp, tarDown }; ///Loop through pano directions int insertLoc = 0; for (int d = 0; d < 4; d++) { ///Set camera direction vp.SetCameraLocations(camTargets[d], camPoint); //view.Redraw(); Bitmap bitmap = new Bitmap(view.CaptureToBitmap(size, viewMode)); if (saveCubemaps) { gr.DrawImage(bitmap, insertLoc, imageWidth); } if (showRays) { GH_MemoryBitmap sampler = new GH_MemoryBitmap(bitmap); Color col = Color.Transparent; for (int x = 0; x < bitmap.Width; x++) { for (int y = 0; y < bitmap.Height; y++) { if (sampler.Sample(x, y, ref col)) { if (colors.Contains(col)) { GH_Path path = new GH_Path(i, colors.IndexOf(col)); Line line = vp.ClientToWorld(new System.Drawing.Point(x, y)); Ray3d ray = new Ray3d(vp.CameraLocation, -line.Direction); double rayEnd = (double)Rhino.Geometry.Intersect.Intersection.MeshRay(obstacles, ray); Point3d rayIntersection = ray.PointAt(rayEnd); Line ln = new Line(camPoint, rayIntersection); if (ln.IsValid & rayEnd > 0) { rayTree.Append(new GH_Line(ln), path); colorTree.Append(new GH_Colour(col), path); } } else if (!filterColors) { colors.Add(col); GH_Path path = new GH_Path(i, colors.IndexOf(col)); Line line = vp.ClientToWorld(new System.Drawing.Point(x, y)); Ray3d ray = new Ray3d(vp.CameraLocation, -line.Direction); double rayEnd = (double)Rhino.Geometry.Intersect.Intersection.MeshRay(obstacles, ray); Point3d rayIntersection = ray.PointAt(rayEnd); Line ln = new Line(camPoint, rayIntersection); if (ln.IsValid & rayEnd > 0) { rayTree.Append(new GH_Line(ln), path); colorTree.Append(new GH_Colour(col), path); } } } } } sampler.Release(false); } insertLoc = insertLoc + imageWidth; bitmap.Dispose(); } ///Get up and down views ///Get up view vp.SetCameraLocations(tarUp, camPoint); view.Redraw(); Bitmap bitmapUp = new Bitmap(view.CaptureToBitmap(size, viewMode)); if (showRays) { GH_MemoryBitmap sampler = new GH_MemoryBitmap(bitmapUp); Color col = Color.Transparent; for (int x = 0; x < bitmapUp.Width; x++) { for (int y = 0; y < bitmapUp.Height; y++) { if (sampler.Sample(x, y, ref col)) { if (colors.Contains(col)) { GH_Path path = new GH_Path(i, colors.IndexOf(col)); Line line = vp.ClientToWorld(new System.Drawing.Point(x, y)); Ray3d ray = new Ray3d(vp.CameraLocation, -line.Direction); double rayEnd = (double)Rhino.Geometry.Intersect.Intersection.MeshRay(obstacles, ray); Point3d rayIntersection = ray.PointAt(rayEnd); Line ln = new Line(camPoint, rayIntersection); if (ln.IsValid & rayEnd > 0) { rayTree.Append(new GH_Line(ln), path); colorTree.Append(new GH_Colour(col), path); } } else if (!filterColors) { colors.Add(col); GH_Path path = new GH_Path(i, colors.IndexOf(col)); Line line = vp.ClientToWorld(new System.Drawing.Point(x, y)); Ray3d ray = new Ray3d(vp.CameraLocation, -line.Direction); double rayEnd = (double)Rhino.Geometry.Intersect.Intersection.MeshRay(obstacles, ray); Point3d rayIntersection = ray.PointAt(rayEnd); Line ln = new Line(camPoint, rayIntersection); if (ln.IsValid & rayEnd > 0) { rayTree.Append(new GH_Line(ln), path); colorTree.Append(new GH_Colour(col), path); } } } } } sampler.Release(false); } bitmapUp.RotateFlip(RotateFlipType.Rotate180FlipNone); if (saveCubemaps) { gr.DrawImage(bitmapUp, imageWidth, 0); } bitmapUp.Dispose(); ///Get down view vp.SetCameraLocations(tarDown, camPoint); view.Redraw(); Bitmap bitmapDown = new Bitmap(view.CaptureToBitmap(size, viewMode)); if (saveCubemaps) { gr.DrawImage(bitmapDown, imageWidth, imageWidth * 2); } if (showRays) { GH_MemoryBitmap sampler = new GH_MemoryBitmap(bitmapDown); Color col = Color.Transparent; for (int x = 0; x < bitmapDown.Width; x++) { for (int y = 0; y < bitmapDown.Height; y++) { if (sampler.Sample(x, y, ref col)) { if (colors.Contains(col)) { GH_Path path = new GH_Path(i, colors.IndexOf(col)); Line line = vp.ClientToWorld(new System.Drawing.Point(x, y)); Ray3d ray = new Ray3d(vp.CameraLocation, -line.Direction); double rayEnd = (double)Rhino.Geometry.Intersect.Intersection.MeshRay(obstacles, ray); Point3d rayIntersection = ray.PointAt(rayEnd); Line ln = new Line(camPoint, rayIntersection); if (ln.IsValid & rayEnd > 0) { rayTree.Append(new GH_Line(ln), path); colorTree.Append(new GH_Colour(col), path); } } else if (!filterColors) { colors.Add(col); GH_Path path = new GH_Path(i, colors.IndexOf(col)); Line line = vp.ClientToWorld(new System.Drawing.Point(x, y)); Ray3d ray = new Ray3d(vp.CameraLocation, -line.Direction); double rayEnd = (double)Rhino.Geometry.Intersect.Intersection.MeshRay(obstacles, ray); Point3d rayIntersection = ray.PointAt(rayEnd); Line ln = new Line(camPoint, rayIntersection); if (ln.IsValid & rayEnd > 0) { rayTree.Append(new GH_Line(ln), path); colorTree.Append(new GH_Colour(col), path); } } } } } sampler.Release(false); } bitmapDown.Dispose(); } ///End pano directions loop if (saveCubemaps) { ///Save cubemap bitmap string s = i.ToString().PadLeft(pad, '0'); string saveText = folder + prefix + "_" + s + ".png"; cubemap.Save(saveText, System.Drawing.Imaging.ImageFormat.Png); cubemaps.Add(saveText); } cubemap.Dispose(); } } ///Restore initial camera setCamera(saveCam, Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport); Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.Redraw(); DA.SetDataList(0, cubemaps); DA.SetDataTree(1, rayTree); DA.SetDataTree(2, colorTree); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { string view_name = ""; DA.GetData <string>(0, ref view_name); string server_msg = ""; DA.GetData <string>(1, ref server_msg); string post = "{\"id\": \"" + screenshot_id + "\"}"; //if (!active) if (Equals(server_msg, "100")) { string url = "http://127.0.0.1:5000/api/v1.0/ss-register-id"; Tuple <bool, string> result = Helpers.PostToServer(url, post); string message = result.Item2; if (!result.Item1) { Helpers.Print(DA, "Error:" + message); throw new Exception(message); } else { var serializer = new JavaScriptSerializer(); var json = serializer.Deserialize <ScreenshotMSG>(message); Helpers.Print(DA, json.status); addFileWatcher(DA, json.path); } } if (active) { RhinoView view = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView; if (view_name == "") { Helpers.Print(DA, "Using active viewport " + view.MainViewport.Name); } else { ViewTable view_table = Rhino.RhinoDoc.ActiveDoc.Views; RhinoView[] views = view_table.GetViewList(true, false); bool exists = false; for (int i = 0; i < views.Length; i++) { view = views[i]; string vp_name = view.MainViewport.Name; if (string.Equals(vp_name, view_name)) { Helpers.Print(DA, "Viewport " + view_name + " found"); exists = true; break; } } if (exists) { } else { Helpers.Print(DA, "New viewport " + view_name + " created"); Rectangle rec = new Rectangle(0, 0, 800, 600); RhinoView new_view = view_table.Add(view_name, Rhino.Display.DefinedViewportProjection.Perspective, rec, true); new_view.MainViewport.WorldAxesVisible = false; new_view.MainViewport.ConstructionGridVisible = false; new_view.MainViewport.ConstructionAxesVisible = false; new_view.MainViewport.DisplayMode = DisplayModeDescription.FindByName("shaded"); view = new_view; } Bitmap bitmap = view.CaptureToBitmap(false, false, false); string url = "http://127.0.0.1:5000/api/v1.0/ss-get-path"; Tuple <bool, string> result = Helpers.PostToServer(url, post); string message = result.Item2; if (!result.Item1) { Helpers.Print(DA, "Error:" + message); throw new Exception(message); } else { var serializer = new JavaScriptSerializer(); var json = serializer.Deserialize <ScreenshotMSG>(message); if (string.Equals(json.status, "success")) { string[] components = { json.path, "png" }; string path = string.Join(".", components); Helpers.Print(DA, "Screenshot captured to: " + path); bitmap.Save(path); } else { Helpers.Print(DA, json.status); } } Helpers.PingServer("http://127.0.0.1:5000/api/v1.0/ss-done"); } //else //{ // Helpers.Print(DA, screenshot_id + " active."); //} active = false; } }
void ShowContextMenu(System.Drawing.Point location) { var contextMenu = new ContextMenu(); var lockMenuMain = new MenuItem("Locking Options"); var lockMenu1 = new MenuItem("Lock Rotation"); bool locked1 = CanvasViewport.settings.GetValue("locked1", false); lockMenu1.Click += (s, e) => { locked1 = !locked1; CanvasViewport.settings.SetValue("locked1", locked1); CanvasViewport.settings.WritePersistentSettings(); CanvasViewport.UpdateViewport(true); }; lockMenu1.Checked = locked1; lockMenuMain.MenuItems.Add(lockMenu1); contextMenu.MenuItems.Add(lockMenuMain); var lockMenu2 = new MenuItem("Lock Dragging"); bool locked2 = CanvasViewport.settings.GetValue("locked2", false); lockMenu2.Click += (s, e) => { locked2 = !locked2; CanvasViewport.settings.SetValue("locked2", locked2); CanvasViewport.settings.WritePersistentSettings(); CanvasViewport.UpdateViewport(true); }; lockMenu2.Checked = locked2; lockMenuMain.MenuItems.Add(lockMenu2); contextMenu.MenuItems.Add(lockMenuMain); var iconToggle = new MenuItem("Disable Lock Icons"); bool icontoggle = CanvasViewport.settings.GetValue("icontoggle", false); iconToggle.Click += (s, e) => { icontoggle = !icontoggle; CanvasViewport.settings.SetValue("icontoggle", icontoggle); CanvasViewport.settings.WritePersistentSettings(); CanvasViewport.UpdateViewport(true); }; iconToggle.Checked = icontoggle; lockMenuMain.MenuItems.Add(iconToggle); lockMenuMain.MenuItems.Add("-"); var dockiconsMenu = new MenuItem("Dock Icons"); string dockicons = CanvasViewport.settings.GetValue("dockicons", "topleft"); var dockiconsMenuItem = new MenuItem("Top Left"); dockiconsMenuItem.RadioCheck = true; dockiconsMenuItem.Click += (s, e) => { dockicons = "topleft"; CanvasViewport.settings.SetValue("dockicons", dockicons); CanvasViewport.settings.WritePersistentSettings(); CanvasViewport.UpdateViewport(true); }; dockiconsMenuItem.Checked = (dockicons == "topleft"); dockiconsMenu.MenuItems.Add(dockiconsMenuItem); dockiconsMenuItem = new MenuItem("Top Right"); dockiconsMenuItem.RadioCheck = true; dockiconsMenuItem.Click += (s, e) => { dockicons = "topright"; CanvasViewport.settings.SetValue("dockicons", dockicons); CanvasViewport.settings.WritePersistentSettings(); CanvasViewport.UpdateViewport(true); }; dockiconsMenuItem.Checked = (dockicons == "topright"); dockiconsMenu.MenuItems.Add(dockiconsMenuItem); dockiconsMenuItem = new MenuItem("Bottom Left"); dockiconsMenuItem.RadioCheck = true; dockiconsMenuItem.Click += (s, e) => { dockicons = "bottomleft"; CanvasViewport.settings.SetValue("dockicons", dockicons); CanvasViewport.settings.WritePersistentSettings(); CanvasViewport.UpdateViewport(true); }; dockiconsMenuItem.Checked = (dockicons == "bottomleft"); dockiconsMenu.MenuItems.Add(dockiconsMenuItem); dockiconsMenuItem = new MenuItem("Bottom Right"); dockiconsMenuItem.RadioCheck = true; dockiconsMenuItem.Click += (s, e) => { dockicons = "bottomright"; CanvasViewport.settings.SetValue("dockicons", dockicons); CanvasViewport.settings.WritePersistentSettings(); CanvasViewport.UpdateViewport(true); }; dockiconsMenuItem.Checked = (dockicons == "bottomright"); dockiconsMenu.MenuItems.Add(dockiconsMenuItem); lockMenuMain.MenuItems.Add(dockiconsMenu); var styleMenu = new MenuItem("Icon Style"); string iconstyle = CanvasViewport.settings.GetValue("iconstyle", "colored"); var styleMenuItem = new MenuItem("Colored"); styleMenuItem.RadioCheck = true; styleMenuItem.Click += (s, e) => { iconstyle = "colored"; CanvasViewport.settings.SetValue("iconstyle", iconstyle); CanvasViewport.settings.WritePersistentSettings(); CanvasViewport.UpdateViewport(true); }; styleMenuItem.Checked = (iconstyle == "colored"); styleMenu.MenuItems.Add(styleMenuItem); styleMenuItem = new MenuItem("Simple"); styleMenuItem.RadioCheck = true; styleMenuItem.Click += (s, e) => { iconstyle = "simple"; CanvasViewport.settings.SetValue("iconstyle", iconstyle); CanvasViewport.settings.WritePersistentSettings(); CanvasViewport.UpdateViewport(true); }; styleMenuItem.Checked = (iconstyle == "simple"); styleMenu.MenuItems.Add(styleMenuItem); lockMenuMain.MenuItems.Add(styleMenu); contextMenu.MenuItems.Add(lockMenuMain); var displayModeMenu = new MenuItem("Display Mode"); var displayModeName = DisplayModeDescription.FindByName(CanvasViewport.settings.GetValue("displaymode", "Wireframe")); Guid displaymode = displayModeName.Id; var modes = DisplayModeDescription.GetDisplayModes(); var currentModeId = displaymode; if (Viewport.DisplayMode != null) { currentModeId = Viewport.DisplayMode.Id; } foreach (var mode in modes) { var modeMenuItem = new MenuItem(mode.LocalName); modeMenuItem.RadioCheck = true; modeMenuItem.Checked = (currentModeId == mode.Id); modeMenuItem.Click += (s, e) => { Viewport.DisplayMode = mode; if (Viewport.DisplayMode.LocalName == "V-Ray Interactive" || Viewport.DisplayMode.LocalName == "Raytraced") { CanvasViewport.settings.SetValue("iconoffset", true); } else { CanvasViewport.settings.SetValue("iconoffset", false); } CanvasViewport.settings.SetValue("displaymode", mode.LocalName); CanvasViewport.settings.WritePersistentSettings(); CanvasViewport.UpdateViewport(true); Invalidate(); }; displayModeMenu.MenuItems.Add(modeMenuItem); displayModeMenu.Tag = mode.Id; } contextMenu.MenuItems.Add(displayModeMenu); var viewMenu = new MenuItem("Set View"); string view = CanvasViewport.settings.GetValue("view", "Perspective"); var viewMenuItem = new MenuItem("Top"); viewMenuItem.RadioCheck = true; viewMenuItem.Click += (s, e) => { Viewport.SetProjection(DefinedViewportProjection.Top, "Top", true); view = "Top"; CanvasViewport.settings.SetValue("view", view); CanvasViewport.settings.WritePersistentSettings(); Invalidate(); }; viewMenuItem.Checked = (view == "Top"); viewMenu.MenuItems.Add(viewMenuItem); viewMenuItem = new MenuItem("Bottom"); viewMenuItem.RadioCheck = true; viewMenuItem.Click += (s, e) => { Viewport.SetProjection(DefinedViewportProjection.Bottom, "Bottom", true); view = "Bottom"; CanvasViewport.settings.SetValue("view", view); CanvasViewport.settings.WritePersistentSettings(); Invalidate(); }; viewMenuItem.Checked = (view == "Bottom"); viewMenu.MenuItems.Add(viewMenuItem); viewMenuItem = new MenuItem("Left"); viewMenuItem.RadioCheck = true; viewMenuItem.Click += (s, e) => { Viewport.SetProjection(DefinedViewportProjection.Left, "Left", true); view = "Left"; CanvasViewport.settings.SetValue("view", view); CanvasViewport.settings.WritePersistentSettings(); Invalidate(); }; viewMenuItem.Checked = (view == "Left"); viewMenu.MenuItems.Add(viewMenuItem); viewMenuItem = new MenuItem("Right"); viewMenuItem.RadioCheck = true; viewMenuItem.Click += (s, e) => { Viewport.SetProjection(DefinedViewportProjection.Right, "Right", true); view = "Right"; CanvasViewport.settings.SetValue("view", view); CanvasViewport.settings.WritePersistentSettings(); Invalidate(); }; viewMenuItem.Checked = (view == "Right"); viewMenu.MenuItems.Add(viewMenuItem); viewMenuItem = new MenuItem("Front"); viewMenuItem.RadioCheck = true; viewMenuItem.Click += (s, e) => { Viewport.SetProjection(DefinedViewportProjection.Front, "Front", true); view = "Front"; CanvasViewport.settings.SetValue("view", view); CanvasViewport.settings.WritePersistentSettings(); Invalidate(); }; viewMenuItem.Checked = (view == "Front"); viewMenu.MenuItems.Add(viewMenuItem); viewMenuItem = new MenuItem("Back"); viewMenuItem.RadioCheck = true; viewMenuItem.Click += (s, e) => { Viewport.SetProjection(DefinedViewportProjection.Back, "Back", true); view = "Back"; CanvasViewport.settings.SetValue("view", view); CanvasViewport.settings.WritePersistentSettings(); Invalidate(); }; viewMenuItem.Checked = (view == "Back"); viewMenu.MenuItems.Add(viewMenuItem); viewMenuItem = new MenuItem("Perspective"); viewMenuItem.RadioCheck = true; viewMenuItem.Click += (s, e) => { Viewport.SetProjection(DefinedViewportProjection.Perspective, "Perspective", true); view = "Perspective"; CanvasViewport.settings.SetValue("view", view); CanvasViewport.settings.WritePersistentSettings(); Invalidate(); }; viewMenuItem.Checked = (view == "Perspective"); viewMenu.MenuItems.Add(viewMenuItem); viewMenuItem = new MenuItem("TwoPointPerspective"); viewMenuItem.RadioCheck = true; viewMenuItem.Click += (s, e) => { Viewport.SetProjection(DefinedViewportProjection.TwoPointPerspective, "TwoPointPerspective", true); view = "TwoPointPerspective"; CanvasViewport.settings.SetValue("view", view); CanvasViewport.settings.WritePersistentSettings(); Invalidate(); }; viewMenuItem.Checked = (view == "TwoPointPerspective"); viewMenu.MenuItems.Add(viewMenuItem); contextMenu.MenuItems.Add(viewMenu); string dock = CanvasViewport.settings.GetValue("dock", "topleft"); var dockMenu = new MenuItem("Dock"); var mnu = new MenuItem("Top Left"); mnu.RadioCheck = true; mnu.Checked = (dock == "topleft"); mnu.Click += (s, args) => { CanvasViewport.DockPanel(Parent, AnchorStyles.Top | AnchorStyles.Left); dock = "topleft"; CanvasViewport.settings.SetValue("dock", dock); CanvasViewport.settings.WritePersistentSettings(); }; dockMenu.MenuItems.Add(mnu); mnu = new MenuItem("Top Right"); mnu.Checked = (dock == "topright"); mnu.RadioCheck = true; mnu.Click += (s, args) => { CanvasViewport.DockPanel(Parent, AnchorStyles.Top | AnchorStyles.Right); dock = "topright"; CanvasViewport.settings.SetValue("dock", dock); CanvasViewport.settings.WritePersistentSettings(); }; dockMenu.MenuItems.Add(mnu); mnu = new MenuItem("Bottom Left"); mnu.Checked = (dock == "bottomleft"); mnu.RadioCheck = true; mnu.Click += (s, args) => { CanvasViewport.DockPanel(Parent, AnchorStyles.Bottom | AnchorStyles.Left); dock = "bottomleft"; CanvasViewport.settings.SetValue("dock", dock); CanvasViewport.settings.WritePersistentSettings(); }; dockMenu.MenuItems.Add(mnu); mnu = new MenuItem("Bottom Right"); mnu.Checked = (dock == "bottomright"); mnu.RadioCheck = true; mnu.Click += (s, args) => { CanvasViewport.DockPanel(Parent, AnchorStyles.Bottom | AnchorStyles.Right); dock = "bottomright"; CanvasViewport.settings.SetValue("dock", dock); CanvasViewport.settings.WritePersistentSettings(); }; dockMenu.MenuItems.Add(mnu); contextMenu.MenuItems.Add(dockMenu); dockMenu.Popup += (s, args) => { var anchor = this.Parent.Anchor; dockMenu.MenuItems[0].Checked = (anchor == (AnchorStyles.Top | AnchorStyles.Left)); dockMenu.MenuItems[1].Checked = (anchor == (AnchorStyles.Bottom | AnchorStyles.Left)); dockMenu.MenuItems[2].Checked = (anchor == (AnchorStyles.Top | AnchorStyles.Right)); dockMenu.MenuItems[3].Checked = (anchor == (AnchorStyles.Bottom | AnchorStyles.Right)); }; contextMenu.MenuItems.Add("-"); bool gridtoggle = CanvasViewport.settings.GetValue("gridtoggle", true); var grid = new MenuItem("Toggle Grid"); grid.Checked = (gridtoggle); grid.Click += (s, args) => { Viewport.ConstructionGridVisible = !gridtoggle; gridtoggle = !gridtoggle; CanvasViewport.settings.SetValue("gridtoggle", gridtoggle); CanvasViewport.settings.WritePersistentSettings(); Invalidate(); }; contextMenu.MenuItems.Add(grid); bool axestoggle = CanvasViewport.settings.GetValue("axestoggle", true); var gridaxes = new MenuItem("Toggle Grid Axes"); gridaxes.Checked = (axestoggle); gridaxes.Click += (s, args) => { Viewport.ConstructionAxesVisible = !axestoggle; axestoggle = !axestoggle; CanvasViewport.settings.SetValue("axestoggle", axestoggle); CanvasViewport.settings.WritePersistentSettings(); Invalidate(); }; contextMenu.MenuItems.Add(gridaxes); bool worldtoggle = CanvasViewport.settings.GetValue("worldtoggle", true); var worldaxes = new MenuItem("Toggle World Axes"); worldaxes.Checked = (worldtoggle); worldaxes.Click += (s, args) => { Viewport.WorldAxesVisible = !worldtoggle; worldtoggle = !worldtoggle; CanvasViewport.settings.SetValue("worldtoggle", worldtoggle); CanvasViewport.settings.WritePersistentSettings(); Invalidate(); }; contextMenu.MenuItems.Add(worldaxes); contextMenu.MenuItems.Add("Reset Camera", (s, e) => { Viewport.SetCameraLocation(camLocation, true); Viewport.SetCameraTarget(camTarget, true); Refresh(); }); contextMenu.MenuItems.Add("Reset View", (s, e) => { ViewReset(); Viewport.SetCameraLocation(camLocation, true); Viewport.SetCameraTarget(camTarget, true); Viewport.Camera35mmLensLength = 50; Viewport.ZoomExtents(); Refresh(); }); contextMenu.MenuItems.Add("Zoom Extents", (s, e) => { Viewport.Camera35mmLensLength = 50; Viewport.ZoomExtents(); Refresh(); }); contextMenu.MenuItems.Add("-"); contextMenu.MenuItems.Add("Restore Defaults", (s, e) => { CanvasViewport.settings.SetValue("width", 400); CanvasViewport.settings.SetValue("height", 300); CanvasViewport.settings.SetValue("dock", "topleft"); CanvasViewport.settings.SetValue("locked1", false); CanvasViewport.settings.SetValue("locked2", false); CanvasViewport.settings.SetValue("icontoggle", false); CanvasViewport.settings.SetValue("iconoffset", false); CanvasViewport.settings.SetValue("dockicons", "topleft"); CanvasViewport.settings.SetValue("iconstyle", "colored"); CanvasViewport.settings.SetValue("view", "Perspective"); CanvasViewport.settings.SetValue("displaymode", "Wireframe"); CanvasViewport.settings.SetValue("gridtoggle", true); CanvasViewport.settings.SetValue("axestoggle", true); CanvasViewport.settings.SetValue("worldtoggle", true); CanvasViewport.settings.WritePersistentSettings(); CanvasViewport.UpdateViewport(true); Viewport.DisplayMode = DisplayModeDescription.FindByName("Wireframe"); Viewport.WorldAxesVisible = true; Viewport.ConstructionAxesVisible = true; Viewport.ConstructionGridVisible = true; Parent.Width = 400; Parent.Height = 300; Viewport.SetProjection(DefinedViewportProjection.Perspective, "Perspective", true); ViewReset(); Viewport.SetCameraLocation(camLocation, true); Viewport.SetCameraTarget(camTarget, true); Viewport.Camera35mmLensLength = 50; Viewport.ZoomExtents(); CanvasViewport.DockPanel(Parent, base.Anchor); Invalidate(); }); contextMenu.MenuItems.Add("Close Viewport", (s, e) => { CanvasViewport.viewportMenuItem.Checked = false; CanvasViewport.settings.SetValue("state", false); CanvasViewport.settings.WritePersistentSettings(); CanvasViewport.viewportMenuItem.CheckedChanged += CanvasViewport.ViewportMenuItem_CheckedChanged; }); contextMenu.Show(this, location); }