public override void MyTestInitialize() { base.MyTestInitialize(); // Import parent surface _parentSurface = (PSSurface)ImportAndGetEntity(TestFiles.SINGLE_SURFACE_WITH_BULGE); }
/// <summary> /// Connects to PowerSHAPE and a specific entity using its name /// </summary> internal PSSpine(PSAutomation powerSHAPE, int id, string name, PSSurface surface) : base(powerSHAPE, id, name) { _powerSHAPE = powerSHAPE; _id = id; _name = name; _surface = surface; }
/// <summary> /// Connects to PowerSHAPE and a specific entity using its name /// </summary> internal PSLateral(PSAutomation powerSHAPE, string name, PSSurface surface) : base(powerSHAPE, surface) { _powerSHAPE = powerSHAPE; _name = name; _surface = surface; _id = _powerSHAPE.ReadIntValue(Identifier + "[" + name + "].ID"); _internalId = Guid.NewGuid(); }
/// <summary> /// Creates CompCurves from an intersection between a surface and a mesh. /// </summary> /// <param name="surface">The surface to intersect.</param> /// <param name="mesh">The mesh to intersect.</param> /// <returns>The list of the created CompCurves.</returns> /// <remarks></remarks> public List <PSCompCurve> CreateCompCurvesFromIntersectionOfSurfaceAndMesh(PSSurface surface, PSMesh mesh) { // Create lists from individual surfaces List <PSEntity> firstList = new List <PSEntity>(); List <PSEntity> secondList = new List <PSEntity>(); firstList.Add(surface); secondList.Add(mesh); // Carry out operation return(CreateCompCurvesFromIntersectionOfTwoSetsOfEntities(firstList, secondList)); }
//--------------------------------------------------------------------- private static void Arrows() { Action <Surface> draw = surface => { using (var c = new Context(surface)) { c.Scale(300, 300); // Is only relevant to PNG c.Antialias = Antialias.Subpixel; // adjust line width due scaling double ux = 1, uy = 1; c.DeviceToUserDistance(ref ux, ref uy); c.LineWidth = Math.Max(ux, uy); c.MoveTo(0, 0.1); c.LineTo(1, 0.1); c.MoveTo(0, 0.9); c.LineTo(1, 0.9); c.Stroke(); var arrow = new Arrow(); c.Color = KnownColors.Blue; arrow.DrawArrow(c, 0.1, 0.1, 0.2, 0.9); arrow.DrawVector(c, 0.2, 0.1, 0.3, 0.9); arrow = new OpenArrow(); c.Color = new Color(0, 1, 0); arrow.DrawArrow(c, 0.3, 0.1, 0.4, 0.9); arrow.DrawVector(c, 0.4, 0.1, 0.5, 0.9); arrow = new CircleArrow(0.01); c.Color = new Color(1, 0, 0); arrow.DrawArrow(c, 0.5, 0.1, 0.6, 0.9); arrow.DrawVector(c, 0.6, 0.1, 0.7, 0.9); } }; using (Surface surface = new PdfSurface("arrows.pdf", 300, 300)) { draw(surface); // PNG can also be created this way surface.WriteToPng("arrows.png"); } using (Surface surface = new PSSurface("arrows.eps", 300, 300)) draw(surface); using (Surface surface = new SvgSurface("arrows.svg", 300, 300)) draw(surface); }
/// <summary> /// This constructor connects to PowerSHAPE /// </summary> internal PSpCurve(PSAutomation powerSHAPE, PSSurface surface, string name) : base(powerSHAPE) { _powerSHAPE = powerSHAPE; _surface = surface; // A pCurve can't be evaluated in PowerSHAPE using its ID, so the ID is set from its name _name = name; _id = _powerSHAPE.ReadIntValue(Identifier + "['" + name + "'].ID"); // Because many properties of the pCurve are not available through the PowerSHAPE interface, a polyline // is created internally to emulate it _polyLine = new Polyline(Points); }
/// <summary> /// This operation creates a new PSPoint at the point of intersection of a surface and a wireframe. /// Note that if the two do not intersect then a point will be created at the origin of the active workplane. /// The user should be sure that the surface and wireframe intersect before calling this function /// </summary> /// <param name="surface">The surface to create a point on where the wireframe intersects</param> /// <param name="wireframe">The wireframe that intersects the surface</param> /// <returns>The created PSPoint at the point of intersection</returns> public PSPoint CreatePointAtIntersectionOfSurfaceAndWireframe(PSSurface surface, PSWireframe wireframe) { _powerSHAPE.ActiveModel.ClearSelectedItems(); _powerSHAPE.DoCommand("CREATE POINT SINGLE", "POSITION", "INTERSECT"); wireframe.AddToSelection(); surface.AddToSelection(); _powerSHAPE.DoCommand("ACCEPT"); PSPoint point = (PSPoint)_powerSHAPE.ActiveModel.SelectedItems[0]; AddNoChecks(point); return(point); }
//--------------------------------------------------------------------- private static void Shapes() { Action <Surface> draw = surface => { using (var c = new Context(surface)) { c.Antialias = Antialias.Subpixel; // Hexagon: Shape shape = new Hexagon(50); shape.Draw(c, 50, 50); shape.Fill(c, 50, 50, new Color(0.5, 0.5, 0.5)); // Square: shape = new Square(50); shape.Draw(c, 150, 50); shape.Fill(c, 150, 50, new Color(0.5, 0.5, 0.5)); // Circle: shape = new Circle(50); shape.Draw(c, 100, 150); shape.Fill(c, 100, 150, new Color(0.5, 0.5, 0.5)); // Bounding box: var boundingBox = new Square(50); c.LineWidth = 1; var red = new Color(1, 0, 0); boundingBox.Draw(c, 50, 50, red); boundingBox.Draw(c, 150, 50, red); boundingBox.Draw(c, 100, 150, red); } }; using (Surface surface = new ImageSurface(Format.Argb32, 180, 180)) { draw(surface); surface.WriteToPng("shapes.png"); } using (Surface surface = new PdfSurface("shapes.pdf", 180, 180)) draw(surface); using (Surface surface = new PSSurface("shapes.eps", 300, 300)) draw(surface); using (Surface surface = new SvgSurface("shapes.svg", 180, 180)) draw(surface); }
public static void Main(string[] args) { // call the snippets Snippets snip = new Snippets(); Surface surface = new PSSurface("snippets.ps", IMAGE_WIDTH, IMAGE_WIDTH); Context cr = new Context(surface); foreach (string snippet in Snippets.snippets) { cr.Save(); Snippets.InvokeSnippet(snip, snippet, cr, IMAGE_WIDTH, IMAGE_HEIGHT); cr.ShowPage(); cr.Restore(); } surface.Finish(); }
public void CreateMeshFromSurfaceTest() { // Import Surface dgk _powerSHAPE.ActiveModel.Import(new FileSystem.File(TestFiles.SINGLE_SURFACE)); // Select everything _powerSHAPE.ActiveModel.SelectAll(false); // Get surface PSSurface meshSurface = (PSSurface)_powerSHAPE.ActiveModel.SelectedItems[0]; // Create mesh from surface _powerSHAPE.ActiveModel.Meshes.CreateMeshFromSurface(meshSurface); Assert.AreEqual(_powerSHAPE.ActiveModel.Meshes.Count, 1, "Failed to add mesh to collection"); Assert.AreEqual(_powerSHAPE.ActiveModel.CreatedItems.Count, 1, "Failed to create mesh in PowerSHAPE"); }
/// <summary> /// Allows the user to select a hole on the mesh and fill it /// </summary> public void FillHole() { // Pick a point that will define where the hole is Point pickedPoint = _powerSHAPE.PickPoint(); // Create a CompCurve around the hole _powerSHAPE.DoCommand("CREATE CURVE COMPCURVE"); _powerSHAPE.DoCommand(pickedPoint.X.ToString() + " " + pickedPoint.Y.ToString() + " " + pickedPoint.Z.ToString()); _powerSHAPE.DoCommand("FASTFORWARDS"); _powerSHAPE.DoCommand("SAVE"); PSCompCurve createdCompCurve = (PSCompCurve)_powerSHAPE.ActiveModel.CreatedItems[0]; createdCompCurve.AddToSelection(true); // The curve must be closed for this to work if (createdCompCurve.IsClosed) { _powerSHAPE.DialogsOff(); // Create a fillin surface from the curve PSSurface fillinSurface = _powerSHAPE.ActiveModel.Surfaces.CreateFillInSurface(createdCompCurve); PSMesh fillinMesh = _powerSHAPE.ActiveModel.Meshes.CreateMeshFromSurface(fillinSurface); fillinSurface.Delete(); fillinMesh.AddToSelection(true); // Append the fillin mesh to this mesh Append(fillinMesh); // Delete the curve that was created createdCompCurve.Delete(); _powerSHAPE.DialogsOn(); } else { // Delete the curve that was created and throw an exception createdCompCurve.Delete(); _powerSHAPE.DialogsOn(); throw new Exception("Unable to create closed curve"); } }
/// <summary> /// Return the last generated surface. /// </summary> /// <returns>The last surface that was generated from the mesh.</returns> public PSSurface Extract() { if (!_isToolCurrentlyActive) { throw new Exception("Tool has not been started."); } _powershape.DoCommand("Apply"); // Process any new entities PSSurface newEntity = null; if (_powershape.ActiveModel.CreatedItems.Count == 1) { newEntity = (PSSurface)_powershape.ActiveModel.CreatedItems[0]; newEntity.Id = _powershape.ReadIntValue(newEntity.Identifier + "['" + newEntity.Name + "'].ID"); } return(newEntity); }
/// <summary> /// Creates a new Mesh from a Surface /// </summary> /// <param name="surface">The Surface from which to create the mesh</param> /// <returns>Mesh created by operation</returns> public PSMesh CreateMeshFromSurface(PSSurface surface) { PSSurface newSurface = (PSSurface)surface.Duplicate(); newSurface.AddToSelection(true); // Carry out operation _powerSHAPE.ActiveModel.ClearCreatedItems(); _powerSHAPE.DoCommand("CONVERT MESH"); // Add new Mesh to collection of Meshes PSMesh newMesh = (PSMesh)_powerSHAPE.ActiveModel.CreatedItems[0]; _powerSHAPE.ActiveModel.Meshes.Add(newMesh); // Remove this Surface from the collection of surfaces newSurface.Delete(); return(newMesh); }
/// <summary> /// Projects the Point onto the specified surface /// </summary> /// <param name="surface">The surface onto which the Point is to be projected</param> /// <returns>A boolean indicating whether the proection was successful</returns> public bool ProjectPointOntoSurface(PSSurface surface) { // Get original point coordinates Point originalCoordinates = ToPoint(); // Select point and surface AddToSelection(true); surface.AddToSelection(false); // Carry out projection _powerSHAPE.ActiveModel.ClearCreatedItems(); _powerSHAPE.DoCommand("EDIT PROJECTPOINT"); // Check whether projection occurred if (ToPoint() == originalCoordinates) { return(false); } return(true); }
/// <summary> /// Creates instance surfaces based on a string identifying a surface's type in PowerSHAPE /// </summary> /// <param name="powerSHAPE">PowerSHAPE instance to create the surface in</param> /// <param name="id">ID for the new surface</param> /// <param name="name">Name for the new surface</param> /// <returns>New surface created by the operation</returns> public static object CreateSurface(PSAutomation powerSHAPE, int id, string name) { // Get surface attributes //Dim id As String = baseSurface.Id //Dim name As String = baseSurface.Name switch (PSSurface.GetSurfaceType(powerSHAPE, id)) { case SurfaceTypes.Block: return(new PSSurfaceBlock(powerSHAPE, id, name)); case SurfaceTypes.Cone: return(new PSSurfaceCone(powerSHAPE, id, name)); case SurfaceTypes.Cylinder: return(new PSSurfaceCylinder(powerSHAPE, id, name)); case SurfaceTypes.Extrusion: return(new PSSurfaceExtrusion(powerSHAPE, id, name)); case SurfaceTypes.Plane: return(new PSSurfacePlane(powerSHAPE, id, name)); case SurfaceTypes.Revolution: return(new PSSurfaceRevolution(powerSHAPE, id, name)); case SurfaceTypes.Sphere: return(new PSSurfaceSphere(powerSHAPE, id, name)); case SurfaceTypes.Spring: return(new PSSurfaceSpring(powerSHAPE, id, name)); case SurfaceTypes.Torus: return(new PSSurfaceTorus(powerSHAPE, id, name)); } // Surface is not a primitive, so return surface that was passed in return(new PSSurface(powerSHAPE, id, name)); }
public void CreateSolidsFromSurfaceTestMultipleSolids() { var activeModel = _powerSHAPE.Models.CreateModelFromFile(new File(TestFiles.CREATE_SOLIDS_FROM_SURFACES_MODEL)); activeModel.GeneralTolerance = 0.001; PSSolid body = activeModel.Solids.GetByName("1"); // Convert to collection of surfaces List <PSSurface> surfaces = activeModel.Surfaces.CreateSurfacesFromSolid(body); // Copy End Caps to use in the solid construction ... PSSurface top = activeModel.Surfaces.GetByName("2"); PSSurface bottom = activeModel.Surfaces.GetByName("3"); // Add copies to collection surfaces.Add(top); surfaces.Add(bottom); var stockModel = activeModel.Solids.CreateSolidsFromSurfaces(surfaces)[0]; Assert.AreEqual(2, activeModel.Solids.Count, "Wrong number of solids created"); }
/// <summary> /// This constructor is required as collection inherits from EntitiesCollection /// </summary> internal PSLateralsCollection(PSAutomation powerSHAPE, PSSurface parentSurface) : base(powerSHAPE, parentSurface) { }
/// <summary> /// Creates a new collection. /// </summary> /// <param name="powershape">The base instance to interact with PowerShape.</param> /// <param name="parentSurface">The parent surface for the lateral.</param> public PSSurfaceCurvesCollection(PSAutomation powershape, PSSurface parentSurface) : base(powershape) { _parentSurface = parentSurface; }
/// <summary> /// Creates new curves and compcurves by projecting wireframe onto a surface /// </summary> /// <param name="surfaceToWrapTo">The surface that will have wireframe wrapped onto it</param> /// <param name="wireframeToWrap">The curves and compcurves that will be wrapped</param> /// <param name="rotation">The desired rotation or the wireframe before wrapping</param> /// <returns>A list of the created curves and compcurves</returns> public List <PSGenericCurve> CreateCurvesFromWrap( PSSurface surfaceToWrapTo, IEnumerable <PSGenericCurve> wireframeToWrap, Degree rotation) { // First page is to select the object to wrap to surfaceToWrapTo.AddToSelection(true); // Raise the dialog (but not really) _powerSHAPE.DoCommand("CREATE CURVE WRAPWIRE"); // Next page _powerSHAPE.DoCommand("NEXT"); // Select the items to wrap foreach (PSGenericCurve wireframe in wireframeToWrap) { wireframe.AddToSelection(false); } // Next page _powerSHAPE.DoCommand("NEXT"); // Select workplane _powerSHAPE.DoCommand("SELECTWORKPLANE REFERENCE"); // Next page _powerSHAPE.DoCommand("NEXT"); // Select method _powerSHAPE.DoCommand("METHOD CHORD"); // Next page _powerSHAPE.DoCommand("NEXT"); // Select distortion _powerSHAPE.DoCommand("MINDISTORTION X_AXIS"); // Next page _powerSHAPE.DoCommand("NEXT"); // Set rotation angle _powerSHAPE.DoCommand("ROTATE " + rotation); // Next page _powerSHAPE.DoCommand("NEXT"); // Next page _powerSHAPE.DoCommand("FINISH"); // Get the list of everything selected List <PSGenericCurve> wrappedCurves = new List <PSGenericCurve>(); foreach (PSGenericCurve wrappedCurve in _powerSHAPE.ActiveModel.SelectedItems) { wrappedCurves.Add(wrappedCurve); } // Need to find out if any workplanes got created and add them to the workplanes collection _powerSHAPE.DoCommand("SELECT WORKPLANES"); int numberOfWorkplanes = _powerSHAPE.ActiveModel.SelectedItems.Count; for (int i = 0; i <= numberOfWorkplanes - 1; i++) { // Get new workplane PSWorkplane workplane = (PSWorkplane)_powerSHAPE.ActiveModel.SelectedItems[i]; // The workplane is added to the active collection only if it is not already in there _powerSHAPE.ActiveModel.Workplanes.Add(workplane); } // Return the curves return(wrappedCurves); }
/// <summary> /// Morphs surfaces between a control and reference surface. Note that you can morph one surface if it is a PowerSurface but you /// must morph more than one surface if it is not a PowerSurface. Also, the control and reference surfaces must have the same number /// of laterals and longitudinals /// </summary> /// <param name="surfacesToMorph">The surfaces to be morphed</param> /// <param name="referenceSurface">The reference surface</param> /// <param name="controlSurface"></param> /// <param name="decayDefinitionOption"></param> /// <param name="decayDefinitionBlend"></param> /// <param name="keepReferenceAndControlSurfaces"></param> /// <param name="normalOffsetting"></param> /// <param name="decaySelection"></param> /// <param name="decayLimit"></param> /// <param name="decayValue"></param> public static void MorphSurfacesBetweenTwoSurfaces( List <PSSurface> surfacesToMorph, PSSurface referenceSurface, PSSurface controlSurface, DecayDefinitionOptions decayDefinitionOption, DecayDefinitionBlend decayDefinitionBlend = DecayDefinitionBlend.Quartic, bool keepReferenceAndControlSurfaces = false, bool normalOffsetting = false, PSSurface decaySurface = null, PSGenericCurve decayCurve = null, int decayLimit = 100, double decayValue = 0.5) { _powerSHAPE = referenceSurface.PowerSHAPE; var activeModel = _powerSHAPE.ActiveModel; activeModel.ClearSelectedItems(); surfacesToMorph.ForEach(x => x.AddToSelection()); _powerSHAPE.DoCommand("MORPH", "TWOSURFS", "REFERENCE ON"); referenceSurface.AddToSelection(); _powerSHAPE.DoCommand("CONTROL ON"); controlSurface.AddToSelection(); // Always keep the surfaces as they are only actually hidden from view but kept in the database. If // the user wants to lose them then we can delete them afterwards. _powerSHAPE.DoCommand("KEEP ON", "WRAP " + normalOffsetting.ToOnOff(), "DECAY " + decayDefinitionOption); if (decayDefinitionOption != DecayDefinitionOptions.None) { _powerSHAPE.DoCommand("BLEND " + decayDefinitionBlend); if (decayDefinitionOption == DecayDefinitionOptions.Distance) { if (decayValue < 0.05) { decayValue = 0.05; } if (decayValue > 0.5) { decayValue = 0.5; } _powerSHAPE.DoCommand("LIMIT " + decayLimit, "HALFLIFE " + decayValue); } else { _powerSHAPE.DoCommand("DECAYSELECT ON"); if (decaySurface != null) { decaySurface.AddToSelection(); } if (decayCurve != null) { decayCurve.AddToSelection(); } } } _powerSHAPE.DoCommand("ACCEPT"); // Delete the reference and control surfaces if chosen to if (keepReferenceAndControlSurfaces == false) { referenceSurface.Delete(); controlSurface.Delete(); } }
/// <summary> /// Connects to PowerSHAPE /// </summary> internal PSSpine(PSAutomation powerSHAPE, PSSurface surface) : base(powerSHAPE) { _powerSHAPE = powerSHAPE; _surface = surface; }