/// <summary> /// Initializes the components of the unit rect to the specified values. /// </summary> /// <param name="X">The x positioning of the unit rect relative to the parent as governed by the horizontal alignment as follows: /// <list type="table"> /// <listheader> /// <term>Alignment</term> /// <term>X Position</term> /// </listheader> /// <item> /// <term>Left</term> /// <term>x units from parent's left edge</term> /// </item> /// <item> /// <term>Center</term> /// <term>x position is ignored</term> /// </item> /// <item> /// <term>Right</term> /// <term>x units from parent's right edge</term> /// </item> /// </list> /// </param> /// <param name="Y">The y positioning of the unit rect relative to the parent as governed by the vertical alignment as follows: /// <list type="table"> /// <listheader> /// <term>Alignment</term> /// <term>Y Position</term> /// </listheader> /// <item> /// <term>Top</term> /// <term>y units from parent's top edge</term> /// </item> /// <item> /// <term>Center</term> /// <term>y position is ignored</term> /// </item> /// <item> /// <term>Bottom</term> /// <term>y units from parent's bottom edge</term> /// </item> /// </list> /// </param> /// <param name="W">The width of the unit rect.</param> /// <param name="H">The height of the unit rect.</param> /// <param name="HAlign">The horizontal alignemnt of the unit rect within the parent rect. /// </param> /// <param name="VAlign">The horizontal alignemnt of the unit rect within the parent rect. /// </param> /// <example> /// Instantiate a unit rect object spaced 10% from the left edge of the parent rect, measuring 100x100 virtual units and centered vertically: /// <code> /// UnitRect r = new UnitRect(new Unit(10, Unit.Type.Percentage), null, new Unit(100, Unit.Type.Virtual), new Unit(100, Unit.Type.Virtual), null, new Alignment(Alignment.Type.Vertical, Alignment.Direction.Bottom)); /// </code> /// </example> public UnitRect(Unit X, Unit Y, Unit W, Unit H, Alignment HAlign, Alignment VAlign) { pos = new UnitVector2d(X, Y); dim = new UnitVector2d(W, H); hAlign = new Alignment(HAlign); vAlign = new Alignment(VAlign); }
/// <summary> /// Initializes the components of the unit rect to null values. /// </summary> public UnitRect() { pos = new UnitVector2d(); dim = new UnitVector2d(); hAlign = new Alignment(null, null); vAlign = new Alignment(null, null); }
/// <summary> /// Initializes the components of the unit rect to the values specified by the strings. /// </summary> /// <param name="X">The x positioning of the unit rect relative to the parent as governed by the horizontal alignment as follows: /// <list type="table"> /// <listheader> /// <term>Alignment</term> /// <term>X Position</term> /// </listheader> /// <item> /// <term>null or empty</term> /// <term>x units from parent's left edge</term> /// </item> /// <item> /// <term>Left</term> /// <term>x units from parent's left edge</term> /// </item> /// <item> /// <term>Center</term> /// <term>x position is ignored</term> /// </item> /// <item> /// <term>Right</term> /// <term>x units from parent's right edge</term> /// </item> /// </list> /// </param> /// <param name="Y">The y positioning of the rect relative to the parent as governed by the vertical alignment as follows: /// <list type="table"> /// <listheader> /// <term>Alignment</term> /// <term>Y Position</term> /// </listheader> /// <item> /// <term>null or empty</term> /// <term>y units from parent's top edge</term> /// </item> /// <item> /// <term>Top</term> /// <term>y units from parent's top edge</term> /// </item> /// <item> /// <term>Center</term> /// <term>y position is ignored</term> /// </item> /// <item> /// <term>Bottom</term> /// <term>y units from parent's bottom edge</term> /// </item> /// </list> /// </param> /// <param name="W">The width of the unit rect.</param> /// <param name="H">The height of the unit rect.</param> /// <param name="HAlign">The horizontal alignemnt of the unit rect within the parent rect as specified by the following values: /// <list type="table"> /// <listheader> /// <term>String Value</term> /// <term>Alignment.Type</term> /// </listheader> /// <item> /// <term>null or empty</term> /// <term>null</term> /// </item> /// <item> /// <term>left</term> /// <term>Alignment.Type.Left</term> /// </item> /// <item> /// <term>center</term> /// <term>Alignment.Type.Center</term> /// </item> /// <item> /// <term>right</term> /// <term>Alignment.Type.Right</term> /// </item> /// </list> /// </param> /// <param name="VAlign">The horizontal alignemnt of the unit rect within the parent rect as specified by the following values: /// <list type="table"> /// <listheader> /// <term>String Value</term> /// <term>Alignment.Type</term> /// </listheader> /// <item> /// <term>null or empty</term> /// <term>null</term> /// </item> /// <item> /// <term>top</term> /// <term>Alignment.Type.Top</term> /// </item> /// <item> /// <term>center</term> /// <term>Alignment.Type.Center</term> /// </item> /// <item> /// <term>bottom</term> /// <term>Alignment.Type.Bottom</term> /// </item> /// </list> /// </param> /// <remarks>This constructor is used primarily in conjunction with XML-based layouts</remarks> /// <example> /// Instantiate a unit rect object spaced 10% from the left edge of the parent rect, measuring 100x100 virtual units and centered vertically: /// <code> /// UnitRect r = new UnitRect("10%", null, "100", "100", null, "center"); /// </code> /// </example> public UnitRect(string X, string Y, string W, string H, string HAlign, string VAlign) { pos = new UnitVector2d(X, Y); dim = new UnitVector2d(W, H); hAlign = new Alignment(Alignment.Type.Horizontal, HAlign); vAlign = new Alignment(Alignment.Type.Vertical, VAlign); }
public override void draw() { sp = null; UnitVector2d v = null; double sAng = 0; if (prev.ent.Type == ObjectTypeEnum.kSketchPointObject) { sp = prev.ent as SketchPoint; } else if (prev.ent.Type == ObjectTypeEnum.kSketchLineObject) { sl = prev.ent as SketchLine; setCenter(); if (cen == null) { setCenter(sl); } sp = sl.EndSketchPoint; v = sl.Geometry.Direction; sAng = v.AngleTo(u.createUnitVector2d(1, 0)); } //SketchArc arc = ps.SketchArcs.AddByCenterStartSweepAngle(cen, R, sAng, -ang); //constraints.addConsid(arc.StartSketchPoint as SketchEntity, sl.EndSketchPoint as SketchEntity); if (ang < 0) { clockwise = false; } if (ang < 0) { sAng = sAng - Math.PI; } SketchArc arc = ps.SketchArcs.AddByThreePoints(sp, pointToArc(x, y, sp.Geometry, ang / 2 + sAng), pointToArc(x, y, sp.Geometry, ang + sAng)); //SketchArc arc = ps.SketchArcs.AddByCenterStartEndPoint(cen, sp, pointToArc(x, y, sp.Geometry, ang + sAng), clockwise); if (ang > 0) { startPt = arc.StartSketchPoint; endPt = arc.EndSketchPoint; } else { startPt = arc.EndSketchPoint; endPt = arc.StartSketchPoint; } ent = (SketchEntity)arc; constr(prev); dimConstr(); }
public double scalar(UnitVector2d v1, UnitVector2d v2) { return(v1.X * v2.X + v1.Y * v2.Y); }
override protected void ButtonDefinition_OnExecute(NameValueMap context) { try { //MessageBox.Show("ERES UN CAPO"); AutodeskInventorInterop AII = new AutodeskInventorInterop(); string filename = "..\\CMUdata\\meshanid.srf"; // Parses files into location and vertex connectivity from an SRF file AII.ReadFileDataToList(filename); //log.Info("Reading meshanid.srf"); // Parses file for elements in riemanian metric matrix in 3D filename = "..\\CMUdata\\meshanid.nt3m"; AII.ReadFileDataToList_nt3m(filename); // log.Info("Reading meshanid.nt3m"); // Decomposes the Riemanian Matrix M=Q.L.Q^-1 AII.EigenDecomp3D(AII.EigenList); // log.Info("EigenDecomposition"); // log.Info("User Coordinate System"); Inventor.Application mApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application") as Inventor.Application; Inventor.PartDocument oDoc = (Inventor.PartDocument)mApp.ActiveDocument; PartComponentDefinition oCompDef = default(PartComponentDefinition); //Defines a part component oCompDef = oDoc.ComponentDefinition; //Used to create a Unitvector where to store MajorAxis 2D for ellipse TransientGeometry oTG = mApp.TransientGeometry; UnitVector2d oUniVector = oTG.CreateUnitVector2d(1, 1); Point2d oPoint2d = mApp.TransientGeometry.CreatePoint2d(0, 0); Profile oProfile = default(Profile); //Creates a profile //EdgeCollection oEdge = default(EdgeCollection); Edge[] oSideEdges = new Edge[5]; //FilletFeature oFillet = default(FilletFeature); WorkPoint oWorkPoint1 = default(WorkPoint); WorkPoint oWorkPoint2 = default(WorkPoint); WorkPoint oWorkPoint3 = default(WorkPoint); UserCoordinateSystemDefinition oUCSDef = oCompDef.UserCoordinateSystems.CreateDefinition(); UserCoordinateSystem oUCS = default(UserCoordinateSystem); EigenVectorPatternSketchPlane selectPlaneToSketch = new EigenVectorPatternSketchPlane(); //ERASE THIS NOT USEFUL PartComponentDefinition oDef = oDoc.ComponentDefinition; PlanarSketch oSketch = default(PlanarSketch); ObjectCollection oFitPoints = mApp.TransientObjects.CreateObjectCollection(); Point2d oPoint2d_a = default(Point2d); SketchEllipticalArc oEllipticalArc = default(SketchEllipticalArc); SketchLine oAxis = default(SketchLine); RevolveFeature oRevolve = default(RevolveFeature); // WorkPlane oWPain = default(WorkPlane); #region "This is my life" /****************************************** COMMENT ***********************************************/ // Philippe Leefsma : [email protected] // Here is where all the pain happens // thank you for your help in advance. // Here is where I create a User defined coordinate system per each one of the features shown // I do not know if there is a way of making this faster? /****************************************** COMMENT ***********************************************/ for (int i = 0; i < AII.VertexLocation.Count; i++) { oWorkPoint1 = oCompDef.WorkPoints.AddFixed( oTG.CreatePoint( (double)AII.VertexLocation[i].origen.X, (double)AII.VertexLocation[i].origen.Y, (double)AII.VertexLocation[i].origen.Z) ); //Change here u1/10 this is to make it closer to the mm value check if needs to be chage to in oWorkPoint2 = oCompDef.WorkPoints.AddFixed( oTG.CreatePoint( (double)AII.EigenVectorValue[i].evc.u1 + (double)AII.VertexLocation[i].origen.X, (double)AII.EigenVectorValue[i].evc.u2 + (double)AII.VertexLocation[i].origen.Y, (double)AII.EigenVectorValue[i].evc.u3 + (double)AII.VertexLocation[i].origen.Z) ); //Check here maybe this is why my rotations are screwd up, instead of v1 maybe is w1 //If w is use I have a cool effect with the protution coming out of the screen oWorkPoint3 = oCompDef.WorkPoints.AddFixed( oTG.CreatePoint( (double)AII.EigenVectorValue[i].evc.v1 + (double)AII.VertexLocation[i].origen.X, (double)AII.EigenVectorValue[i].evc.v2 + (double)AII.VertexLocation[i].origen.Y, (double)AII.EigenVectorValue[i].evc.v3 + (double)AII.VertexLocation[i].origen.Z) ); //User Define Coordinate oUCSDef.SetByThreePoints(oWorkPoint1, oWorkPoint2, oWorkPoint3); oUCS = oCompDef.UserCoordinateSystems.Add(oUCSDef); oPoint2d.X = 0; oPoint2d.Y = 0; double l1 = AII.EigenVectorValue[i].evl.l1; double l2 = AII.EigenVectorValue[i].evl.l2; //Here maybe we can reduece time by pre-working these numbers double h1 = (1 / Math.Sqrt(l1)); //Check here double h2 = (1 / Math.Sqrt(l2)); //Change here to add alfa angle oUniVector.X = 1; // Math.Abs(AII.EigenVectorValue[i].evc.u1); //CHNAGE HERE 0 ,1 //if this is negative changes the direction oUniVector.Y = 0; // Math.Abs(AII.EigenVectorValue[i].evc.u2); oSketch = selectPlaneToSketch.SelectPlane(oDoc, oUCS); //Candidates for config file oWorkPoint1.Visible = false; oWorkPoint2.Visible = false; oWorkPoint3.Visible = false; oUCS.Visible = false; double PI = Math.Atan(1) * 4.0; double duoPI = 2 * PI; double sizeBubbleInverse = 3.5; //this changes the sizes in the features contracts the bubbles "SIZING METRIC" #region "Revolve and Join" oPoint2d_a = mApp.TransientGeometry.CreatePoint2d(0, 0); //Create Elliptical Arc oEllipticalArc = oSketch.SketchEllipticalArcs.Add(oPoint2d_a, oUniVector, h1 / (sizeBubbleInverse), h2 / (sizeBubbleInverse), 0, PI); oAxis = oSketch.SketchLines.AddByTwoPoints( oEllipticalArc.StartSketchPoint, oEllipticalArc.EndSketchPoint); oProfile = oSketch.Profiles.AddForSolid(); oRevolve = oDoc.ComponentDefinition.Features.RevolveFeatures.AddFull (oProfile, oAxis, PartFeatureOperationEnum.kJoinOperation); #endregion } #endregion } catch (Exception e) { MessageBox.Show(e.ToString()); } }
static public void swap() { double xd = dir.X, yd = dir.Y; dir = I.CUV2d(xd, yd); }
public static void addProjectCut(PartDocument oDoc, WorkPlane oWpReference, bool manual = false) { SheetMetalComponentDefinition oCompDef = (SheetMetalComponentDefinition)oDoc.ComponentDefinition; WorkPlane oWpWork = oCompDef.WorkPlanes.AddByPlaneAndOffset(oWpReference, 0); oWpWork.Name = "wpWork"; oWpWork.Visible = false; PlanarSketch oSketch = oCompDef.Sketches.Add(oWpWork); ProjectedCut oProjectCut = oSketch.ProjectedCuts.Add(); if (!manual) { int tmpSegmThk = countThicknessSegment(oProjectCut.SketchEntities); int loop = 0; double offset = 1; while (tmpSegmThk != 2) { // Devo spostare il piano se ci sono cose nel mezzo oWpWork.SetByPlaneAndOffset(oWpReference, offset); tmpSegmThk = countThicknessSegment(oProjectCut.SketchEntities); loop++; offset += offset; if (loop == 20) { throw new Exception("Numero massimo offset piano."); } } oProjectCut.Delete(); oProjectCut = oSketch.ProjectedCuts.Add(); } List <ObjectCollection> dataLine = splittoLinea(oProjectCut.SketchEntities); ObjectCollection linea = lengthPerimetro(); TransientGeometry oTransGeom = iApp.TransientGeometry; UnitVector oNormalVector = oSketch.PlanarEntityGeometry.Normal; UnitVector2d oLineDir = linea[1].Geometry.Direction; UnitVector oLineVector = (UnitVector)oTransGeom.CreateUnitVector(oLineDir.X, oLineDir.Y, 0); UnitVector oOffsetVector = (UnitVector)oLineVector.CrossProduct(oNormalVector); UnitVector oDesiredVector = (UnitVector)oTransGeom.CreateUnitVector(0, 1, 0); bool bNaturalOffsetDir; if (oOffsetVector.IsEqualTo(oDesiredVector)) { bNaturalOffsetDir = true; } else { bNaturalOffsetDir = false; } SketchEntitiesEnumerator oSSketchEntitiesEnum = oSketch.OffsetSketchEntitiesUsingDistance(linea, 0.5, bNaturalOffsetDir, false); oProjectCut.Delete(); styleSketch(oSketch.SketchEntities); int countThicknessSegment(SketchEntitiesEnumerator oSketchEntities) { int result = 0; foreach (SketchEntity e in oSketchEntities) { if (e.Type == ObjectTypeEnum.kSketchLineObject) { SketchLine oSketchLine = (SketchLine)e; double length = Math.Round(oSketchLine.Length * 100) / 100; if (length == Math.Round(oCompDef.Thickness.Value * 100) / 100) { result++; } } } return(result); } List <ObjectCollection> splittoLinea(SketchEntitiesEnumerator oSketchEntities) { List <ObjectCollection> tmp = new List <ObjectCollection>(); tmp.Add(iApp.TransientObjects.CreateObjectCollection()); tmp.Add(iApp.TransientObjects.CreateObjectCollection()); tmp.Add(iApp.TransientObjects.CreateObjectCollection()); int indice = 0; foreach (SketchEntity oSketchEntity in oSketchEntities) { if (oSketchEntity.Type != ObjectTypeEnum.kSketchPointObject) { if (oSketchEntity.Type == ObjectTypeEnum.kSketchLineObject) { SketchLine oSketchLine = (SketchLine)oSketchEntity; if (Math.Round(oSketchLine.Length * 100) / 100 == Math.Round(oCompDef.Thickness.Value * 100) / 100) { if (indice == 0) { indice = 1; } else { indice = 2; } } else { tmp[indice].Add(oSketchEntity); } } if (oSketchEntity.Type == ObjectTypeEnum.kSketchArcObject) { tmp[indice].Add(oSketchEntity); } } } foreach (SketchEntity oSketchEntity in tmp[0]) { tmp[2].Add(oSketchEntity); } List <ObjectCollection> result = new List <ObjectCollection>(); result.Add(tmp[1]); result.Add(tmp[2]); return(result); } void styleSketch(SketchEntitiesEnumerator oSketchEntities) { foreach (SketchEntity oSe in oSketchEntities) { if (oSe.Type == ObjectTypeEnum.kSketchLineObject) { SketchLine se = (SketchLine)oSe; se.OverrideColor = iApp.TransientObjects.CreateColor(0, 0, 255); se.LineType = LineTypeEnum.kDashDottedLineType; } else if (oSe.Type == ObjectTypeEnum.kSketchArcObject) { SketchArc sa = (SketchArc)oSe; sa.OverrideColor = iApp.TransientObjects.CreateColor(0, 0, 255); sa.LineType = LineTypeEnum.kDashDottedLineType; } } } ObjectCollection lengthPerimetro() { double l0 = 0; double l1 = 0; foreach (SketchEntity oSE in dataLine[0]) { if (oSE.Type == ObjectTypeEnum.kSketchLineObject) { SketchLine se = (SketchLine)oSE; l0 = l0 + se.Length; } else if (oSE.Type == ObjectTypeEnum.kSketchArcObject) { SketchArc se = (SketchArc)oSE; l0 = l0 + se.Length; } } foreach (SketchEntity oSE in dataLine[1]) { if (oSE.Type == ObjectTypeEnum.kSketchLineObject) { SketchLine se = (SketchLine)oSE; l1 = l1 + se.Length; } else if (oSE.Type == ObjectTypeEnum.kSketchArcObject) { SketchArc se = (SketchArc)oSE; l1 = l1 + se.Length; } } if (l0 > l1) { return(dataLine[0]); } else { return(dataLine[1]); } } }