//Reuse hash functions public Sketch(Sketch sketch) { SketchVector[] existingSketches = sketch.sketches; sketches = new Tuple<Hash, double[]>[existingSketches.Length]; for(int i =0; i< existingSketches.Length; i++){ var exSketch = existingSketches[i]; sketches[i] = Tuple.Create(exSketch.Hash(), new double[exSketch.Counters().Length]); } }
public static void EditSketch(Sketch S, Action<Factory2D> A) { if (S == null) throw new ArgumentException("Sketch is null", "S"); Factory2D F = S.OpenEdition(); if (F == null) throw new Exception("Could not open edition"); try { A(F); } finally { S.CloseEdition(); } }
public static void CreateCam(double angle) { double dRad = angle*dPi/180; double dDSin1 = iCircle1Rad*Math.Sin(dRad); double dDCos1 = iCircle1Rad*Math.Cos(dRad); double dDSin2 = iCircle2Rad*Math.Sin(dRad); double dDCos2 = iCircle2Rad*Math.Cos(dRad); double dCSin = iCircleDist*Math.Sin(dRad); double dCCos = iCircleDist*Math.Cos(dRad); oCurrentSketch = oPartBody.Sketches.Add ( oPlaneYZ ); Factory2D oFactory2D = oCurrentSketch.OpenEdition(); double dRad1 = dRad - dPi/4; double dRad2 = dRad + dPi/4; oCurrentLine1 = oFactory2D.CreateLine( iCenterX - dDSin1, iCenterY + dDCos1, iCenterX + dCCos + dDSin2, iCenterY - dCSin + dDCos2); oCurrentLine2 = oFactory2D.CreateLine( iCenterX + dDSin1, iCenterY - dDCos1, iCenterX + dCCos - dDSin2, iCenterY - dCSin - dDCos2 ); oCurrentCircle1 = oFactory2D.CreateCircle( iCenterX, iCenterY, iCircle1Rad, dRad2, dRad1); oCurrentCircle2 = oFactory2D.CreateCircle( iCenterX + dCCos, iCenterY + dCSin, iCircle2Rad, dRad1, dRad2); Reference oRefLine1 = oPart.CreateReferenceFromObject(oCurrentLine1); Reference oRefCircle1 = oPart.CreateReferenceFromObject(oCurrentCircle1); Reference oRefLine2 = oPart.CreateReferenceFromObject(oCurrentLine2); Reference oRefCircle2 = oPart.CreateReferenceFromObject(oCurrentCircle2); Reference oRefLine1StartPt = oPart.CreateReferenceFromObject(oCurrentLine1.StartPoint); Reference oRefLine1EndPt = oPart.CreateReferenceFromObject(oCurrentLine1.EndPoint); Reference oRefLine2StartPt = oPart.CreateReferenceFromObject(oCurrentLine2.StartPoint); Reference oRefLine2EndPt = oPart.CreateReferenceFromObject(oCurrentLine2.EndPoint); Reference oRefCircle1StartPt = oPart.CreateReferenceFromObject(oCurrentCircle1.StartPoint); Reference oRefCircle1EndPt = oPart.CreateReferenceFromObject(oCurrentCircle1.EndPoint); Reference oRefCircle2StartPt = oPart.CreateReferenceFromObject(oCurrentCircle2.StartPoint); Reference oRefCircle2EndPt = oPart.CreateReferenceFromObject(oCurrentCircle2.EndPoint); Constraints oConstraints = oCurrentSketch.Constraints; Constraint oConstraint = oConstraints.AddMonoEltCst(CatConstraintType.catCstTypeReference, oRefCircle1); oConstraint = oConstraints.AddMonoEltCst(CatConstraintType.catCstTypeReference, oRefCircle2); oConstraint = oConstraints.AddBiEltCst(CatConstraintType.catCstTypeTangency, oRefLine1, oRefCircle1); oConstraint = oConstraints.AddBiEltCst(CatConstraintType.catCstTypeTangency, oRefCircle2, oRefLine1); oConstraint = oConstraints.AddBiEltCst(CatConstraintType.catCstTypeOn, oRefCircle1StartPt, oRefLine1StartPt); oConstraint = oConstraints.AddBiEltCst(CatConstraintType.catCstTypeOn, oRefCircle2EndPt, oRefLine1EndPt); oConstraint = oConstraints.AddBiEltCst(CatConstraintType.catCstTypeTangency, oRefLine2, oRefCircle1); oConstraint = oConstraints.AddBiEltCst(CatConstraintType.catCstTypeTangency, oRefLine2, oRefCircle2); oConstraint = oConstraints.AddBiEltCst(CatConstraintType.catCstTypeOn, oRefCircle1EndPt, oRefLine2StartPt); oConstraint = oConstraints.AddBiEltCst(CatConstraintType.catCstTypeOn, oRefCircle2StartPt, oRefLine2EndPt); oCurrentSketch.CloseEdition(); ShapeFactory oShapeFactory = (ShapeFactory)oPart.ShapeFactory; Pad oPad = oShapeFactory.AddNewPad ( oCurrentSketch, iCamThickness + iCurrentLevel ); oPad.SecondLimit.Dimension.Value = iCurrentLevel*-1; }
public ActionResult Save(Sketch sketch) { try { if (String.IsNullOrEmpty(sketch.Config) || String.IsNullOrEmpty(sketch.Settings) || String.IsNullOrEmpty(sketch.Version)) return Json(new { Status = "Failed", Message = "Required Fields are missing. Required Fields are config, Settings, Version and Public" }); if (sketch.Config.Length > 8000 || sketch.Settings.Length > 2000 || sketch.Version.Length > 20) return Json(new { Status = "Failed", Message = "Too much data" }); var ctx = new Context(); var maxID = 0; if (ctx.Sketches.Count() > 0) maxID = (int)ctx.Sketches.Max(x => x.Id); for (int i = 0; i < 10; i++) { string reference = MakeReference(maxID); // check if already exists if (ctx.Sketches.Any(x => x.Ref == reference)) continue; sketch.Timestamp = DateTime.Now; sketch.Ref = reference; ctx.Sketches.Add(sketch); ctx.SaveChanges(); return Json(new { Status = "OK", Ref = reference }); } return Json(new { Status = "Failed", Message = "Failed to generate reference key" }); } catch (Exception e) { string msg = e.Message; if(e.InnerException != null) msg += " - " + e.InnerException.Message; return Json(new { Status = "Failed", Message = "An unexpected error occured" }); } }
public Sketch ToDomainModel() { Sketch sketch = new Sketch { Id = SketchId ?? -1, Data = Data, ImageUri = ImageUri, Position = Position, Title = Title, User = new User {Id = UserId ?? -1}, Dimension = new Dimension { Id = DimensionId ?? -1, Project = new Project {Id = ProjectId ?? -1} } }; return sketch; }
public EditSketchViewModel(Sketch sketch) { if (sketch != null) { SketchId = sketch.Id; Data = sketch.Data; ImageUri = sketch.ImageUri; Position = sketch.Position; Title = sketch.Title; if (sketch.Dimension != null) { DimensionId = sketch.Dimension.Id; if (sketch.Dimension.Project != null) ProjectId = sketch.Dimension.Project.Id; } if (sketch.User != null) UserId = sketch.User.Id; } }
private void Stream( ArrayList data, Sketch sketch ) { data.Add( new Snoop.Data.ClassSeparator( typeof( Sketch ) ) ); data.Add( new Snoop.Data.Enumerable( "Profile", sketch.Profile ) ); data.Add( new Snoop.Data.Object( "Sketch plane", sketch.SketchPlane ) ); }
/// <exception cref="ArgumentNullException"><paramref name="sketchNode"/> is <see langword="null" />.</exception> public Sketch ParseSketchNode(INode sketchNode) { if (sketchNode == null) throw new ArgumentNullException("sketchNode"); var sketchUrl = sketchNode.GetAttributeValue(Constants.SketchUrlAttribute); var sketchUriBuilder = new UriBuilder(new Uri(sketchUrl)) { Scheme = Uri.UriSchemeHttp }; var sketchUri = sketchUriBuilder.Uri; var sketch = new Sketch { Url = sketchUri.ToString(), FileName = sketchUri.Segments.Last().EndsWith("/", StringComparison.Ordinal) ? null : sketchUri.Segments.Last() }; return sketch; }
static void ResolveGUISelection(Sketch sketch) { RaycastHit hitInfo; int hitTriangle; if (Physics.Raycast (Event.current.mouseRay.origin, Event.current.mouseRay.direction, out hitInfo)) { if (hitInfo.transform == sketch.transform) { Event.current.Use (); hitTriangle = sketch.GetNearestTriangle (hitInfo.point); sketch.Select (hitTriangle); } else { Debug.Log ("Obstructed by " + hitInfo.transform.gameObject.name); } } }
public static void CreateCylinder(double thickness, double radius) { oCurrentSketch = oPartBody.Sketches.Add ( oPlaneYZ ); Factory2D oFactory2D = (Factory2D)oCurrentSketch.OpenEdition(); oCurrentCircle1 = oFactory2D.CreateClosedCircle (iCenterX, iCenterY, radius); oCurrentSketch.CloseEdition(); ShapeFactory oShapeFactory = (ShapeFactory)oPart; Pad oPad = oShapeFactory.AddNewPad ( oCurrentSketch, thickness + iCurrentLevel ); oPad.SecondLimit.Dimension.Value = iCurrentLevel*-1; iCurrentLevel = iCurrentLevel + thickness; }
public static void CreatePatternBearing() { oCurrentSketch = oPartBody.Sketches.Add ( oPlaneYZ ); Factory2D oFactory2D = oCurrentSketch.OpenEdition(); oCurrentCircle1 = oFactory2D.CreateClosedCircle ( iCenterX, iCenterY, iBearingDiam/2 ); oCurrentSketch.CloseEdition(); ShapeFactory oShapeFactory = (ShapeFactory)oPart.ShapeFactory; Pad oPad = oShapeFactory.AddNewPad ( oCurrentSketch, iBearingLength ); OriginElements originElements1 = oPart.OriginElements; Reference oRefPlaneXY = oPart.CreateReferenceFromGeometry( oPart.OriginElements.PlaneXY ); RectPattern rectPattern1 = oShapeFactory.AddNewRectPattern(oPad,iNumberOfCylinders+1,1,iCylinderSpacing,0,1,1,oRefPlaneXY,oRefPlaneXY,true,true,0); iCurrentLevel = iBearingLength; }
protected override void OnMouseClick(MouseEventArgs e) { base.OnMouseClick(e); Sketch.OnMouseClick(e); }
protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); Sketch.OnMouseDown(e); }
protected override void OnKeyUp(KeyEventArgs e) { base.OnKeyUp(e); Sketch.OnKeyUp(e, (int)e.KeyData); }
protected override void OnKeyPress(KeyPressEventArgs e) { base.OnKeyPress(e); Sketch.OnKeyPress(e, e.KeyChar); }
//-------------------------------------------------------------------------------------------------- void _OnActionFinished(ToolAction toolAction) { bool finished = false; var selectAction = toolAction as SelectSubshapeAction; Debug.Assert(selectAction != null); if (selectAction.SelectedSubshapeType == SubshapeTypes.Face) { var face = TopoDS.Face(selectAction.SelectedSubshape); var brepAdaptor = new BRepAdaptor_Surface(face, true); if (brepAdaptor.GetGeomType() != GeomAbs_SurfaceType.GeomAbs_Plane) { StatusText = "Selected face is not a plane type surface."; } else { selectAction.Stop(); Stop(); finished = true; var faceRef = _TargetShape.GetSubshapeReference(_TargetBrep, face); if (faceRef == null) { Messages.Error("A subshape reference could not be produced for this face."); return; } if (_Mode == ToolMode.CreateNew) { // Create new var sketch = new Sketch { Body = _TargetBody, }; var imprint = Imprint.Create(_TargetBody, faceRef, sketch); if (imprint != null) { imprint.Mode = _ImprintMode; InteractiveContext.Current.UndoHandler.Commit(); InteractiveContext.Current.WorkspaceController.Selection.SelectEntity(_TargetBody); WorkspaceController.StartTool(new SketchEditorTool(sketch)); } } else if (_Mode == ToolMode.ReselectFace) { // Reselected face _ImprintToChange.Face = faceRef; _ImprintToChange.Invalidate(); InteractiveContext.Current.UndoHandler.Commit(); } } } if (!finished) { selectAction.Reset(); } WorkspaceController.Invalidate(); }