internal void Load(ISldWorks app, params Type[] cmdGroupTypes) { m_Kit = new ServicesManager(this.GetType().Assembly, new IntPtr(app.IFrameObject().GetHWnd()), typeof(EulaService), typeof(UpdatesService), typeof(OpenIdConnectorService), typeof(UserSettingsService), typeof(SystemEventLogService), typeof(AboutApplicationService)); m_Kit.HandleError += OnHandleError; m_Container = new UnityContainer(); m_Container.RegisterInstance(app); m_Container.RegisterInstance(app.IGetMathUtility() as IMathUtility); m_Container.RegisterInstance(app.IGetModeler() as IModeler); m_Container.RegisterInstance(m_Kit); m_Commands = new Dictionary <Enum, Type>(); foreach (var cmdGrpType in cmdGroupTypes) { foreach (var cmd in Enum.GetValues(cmdGrpType).Cast <Enum>()) { Type from; Type to; GetCommandHandler(cmd, out from, out to); m_Commands.Add(cmd, from); m_Container.RegisterType(from, to, new ContainerControlledLifetimeManager()); } } m_Kit.StartServices(); }
public OffsetBuilder(ISldWorks app, IModelDoc2 model) { m_App = app; m_Model = model; m_Modeler = app.IGetModeler(); m_MathUtils = m_App.IGetMathUtility(); }
internal MacroFeatureParametersParser(ISldWorks app) { MathUtils = app.IGetMathUtility(); //TODO: pass logger as parameter m_Logger = new TraceLogger("xCAD.MacroFeature"); }
protected override IBody2[] CreateGeometry(ISldWorks app, ExtrudeSurfaceCapDataModel parameters) { if (parameters.Profiles != null && parameters.Profiles.Any()) { var bodies = new List <IBody2>(); foreach (var profile in parameters.Profiles) { if (profile is IFeature) { var sketch = (profile as IFeature).GetSpecificFeature2() as ISketch; var sketchContours = sketch.GetSketchContours() as object[]; if (sketchContours != null) { foreach (ISketchContour skCont in sketchContours) { bodies.Add(CreateBodyFromSketchContour(app.IGetModeler(), app.IGetMathUtility(), skCont, parameters.Height, parameters.MidPlane)); } } } if (profile is ISketchContour) { bodies.Add(CreateBodyFromSketchContour(app.IGetModeler(), app.IGetMathUtility(), profile as ISketchContour, parameters.Height, parameters.MidPlane)); } } return(bodies.ToArray()); } else { throw new UserErrorException("Please select the profile for extrusion"); } }
public List <IBody2> CreateBodies(ISldWorks app, bool temp) { var resBodies = new List <IBody2>(); var modeler = app.GetModeler() as Modeler; var mathUtil = app.IGetMathUtility(); double[] vectorN = new double[] { 1, 0, 0 }; double[] pointN = new double[] { 0, 0, 0 }; if (helix == true) { for (int i = 0; i < 10; i++) { double Xstart = sizeX * i; resBodies.Add(modeler.CreateBodyFromBox3(new double[] { Xstart, 0d, 0d, 1d, 0d, 0d, sizeX, sizeY, sizeZ })); double Rotation = 36 * (i + 1); var vector = mathUtil.CreateVector(vectorN); var point = mathUtil.CreatePoint(pointN); MathTransform rotation = (MathTransform)mathUtil.CreateTransformRotateAxis(point, vector, Rotation); resBodies[i].ApplyTransform(rotation); } if (temp == true) { for (int i = 0; i < 10; i++) { resBodies[i].Display3(app.IActiveDoc2, 100, 1); } } else { for (int i = 0; i < 10; i++) { resBodies[i].CreateBaseFeature(resBodies[i]); } } } else { resBodies.Add(modeler.CreateBodyFromBox3(new double[] { 0d, 0d, 0d, 1d, 0d, 0d, sizeX, sizeY, sizeZ })); if (temp == true) { resBodies[0].Display3(app.IActiveDoc2, 100, 1); } else { resBodies[0].CreateBaseFeature(resBodies[0]); } } return(resBodies); }
protected override IBody2[] CreateGeometry(ISldWorks app, TrimSurfacesByRegionDataModel parameters) { if (parameters.TargetBodies == null || !parameters.TargetBodies.Any()) { throw new UserErrorException("Select target bodies to trim"); } if (parameters.TrimTools == null || !parameters.TrimTools.Any()) { throw new UserErrorException("Select trim tools (sketches or sketch regions)"); } var resBodies = new List <IBody2>(); var modeler = app.IGetModeler(); var mathUtils = app.IGetMathUtility(); var toolBodies = CreateToolBodies(modeler, mathUtils, parameters.TrimTools); if (!toolBodies.Any()) { throw new UserErrorException("No closed regions found in the selected trim tools"); } foreach (var surfBody in parameters.TargetBodies) { if (surfBody == null) { continue; //TODO: investigate why first body is null } foreach (var solidBody in toolBodies) { var targetBody = surfBody.ICopy(); var toolBody = solidBody.ICopy(); int err; object[] res = targetBody.Operations2((int)swBodyOperationType_e.SWBODYINTERSECT, toolBody, out err) as object[]; if (res != null) { foreach (IBody2 resBody in res) { resBodies.Add(resBody); } } } } return(resBodies.ToArray()); }
public ServicesContainer(ISldWorks app) { Instance = this; m_Container = new UnityContainer(); m_Container.RegisterType <RoundStockModel>( new ContainerControlledLifetimeManager()); m_Container.RegisterInstance(app); m_Container.RegisterInstance(app.IGetMathUtility() as IMathUtility); m_Container.RegisterType <IStockFitExtractor <CylinderParams>, CylindricalStockFitExtractor>( new ContainerControlledLifetimeManager()); m_Container.RegisterType <IVectorMathService, SwVectorMathService>( new ContainerControlledLifetimeManager()); m_Container.RegisterType <RoundStockController>( new ContainerControlledLifetimeManager()); m_Kit = new ServicesManager(this.GetType().Assembly, new IntPtr(app.IFrameObject().GetHWnd()), typeof(UpdatesService), typeof(UserSettingsService), typeof(SystemEventLogService), typeof(AboutApplicationService)); m_Kit.HandleError += OnHandleError; var syncContext = SynchronizationContext.Current; Task.Run(() => { SynchronizationContext.SetSynchronizationContext( syncContext); m_Kit.StartServicesAsync().Wait(); }); m_Container.RegisterInstance(m_Kit.GetService <ILogService>()); m_Container.RegisterInstance(m_Kit.GetService <IUserSettingsService>()); m_Container.RegisterInstance(m_Kit.GetService <IAboutApplicationService>()); }
public void Init(ISldWorks app, IModelDoc2 model) { m_MathUtils = app.IGetMathUtility(); m_View = model.IActiveView; if (m_View != null) { m_View.BufferSwapNotify += OnBufferSwapNotify; m_GLControl = new GLControl(); m_GLControl.Context.MakeCurrent(null); } else { throw new NullReferenceException("No active view"); } m_Model = model; }
public string CreateBlock(ISldWorks swApp, int type, out MathPoint instancePosition, double x = 0, double y = 0 ) { var objPoint1 = new double[3]; objPoint1[0] = 0; objPoint1[1] = 0; objPoint1[2] = 0; var swMathUtil1 = swApp.IGetMathUtility(); instancePosition = (MathPoint)swMathUtil1.CreatePoint(objPoint1); int i = 0; switch (type) { case 0: i = 4; break; case 1: i = 6; break; case 2: i = 2; break; case 3: i = 3; break; case 4: i = 6; break; } double blScale = 0.05; var swModel = (ModelDoc2)swApp.ActiveDoc; var swSkSeg = new ISketchSegment[i]; swModel.SetAddToDB(true); switch (type) { case 0: // 5 through swSkSeg[0] = (SketchSegment)swModel.CreateLine2(-0.04, 0.0, 0.0, 0.0, 0.04, 0.0); swSkSeg[1] = (SketchSegment)swModel.CreateLine2(0.0, 0.04, 0.0, 0.04, 0.0, 0.0); swSkSeg[2] = (SketchSegment)swModel.CreateLine2(0.04, 0.0, 0.0, 0.0, -0.04, 0.0); swSkSeg[3] = (SketchSegment)swModel.CreateLine2(0.0, -0.04, 0.0, -0.04, 0.0, 0.0); break; case 1: // 5 H 12 swSkSeg[0] = (SketchSegment)swModel.CreateCircle2(0.0, 0.0, 0.0, 0.003, 0.0, 0.0); swSkSeg[2] = (SketchSegment)swModel.CreateCircle2(0.0, 0.0, 0.0, 0.0045, 0.0, 0.0); swSkSeg[3] = (SketchSegment)swModel.CreateCircle2(0.0, 0.0, 0.0, 0.006, 0.0, 0.0); swSkSeg[4] = (SketchSegment)swModel.CreateCircle2(0.0, 0.0, 0.0, 0.0075, 0.0, 0.0); swSkSeg[5] = (SketchSegment)swModel.CreateCircle2(0.0, 0.0, 0.0, 0.009, 0.0, 0.0); blScale = 0.075; break; case 2: // 8 swSkSeg[0] = (SketchSegment)swModel.CreateLine2(-0.04, -0.04, 0.0, 0.04, 0.04, 0.0); swSkSeg[1] = (SketchSegment)swModel.CreateLine2(-0.04, 0.04, 0.0, 0.04, -0.04, 0.0); blScale = 0.06; break; case 3: //8 through swSkSeg[0] = (SketchSegment)swModel.CreateLine2(-0.04, -0.0293, 0.0, 0.0, 0.04, 0.0); swSkSeg[1] = (SketchSegment)swModel.CreateLine2(0.0, 0.04, 0.0, 0.04, -0.0293, 0.0); swSkSeg[2] = (SketchSegment)swModel.CreateLine2(0.04, -0.0293, 0.0, -0.04, -0.0293, 0.0); break; case 4: //811 swSkSeg[0] = (SketchSegment)swModel.CreateLine2(-0.04, -0.04, 0.0, -0.04, 0.04, 0.0); swSkSeg[1] = (SketchSegment)swModel.CreateLine2(-0.04, 0.04, 0.0, 0.04, 0.04, 0.0); swSkSeg[2] = (SketchSegment)swModel.CreateLine2(0.04, 0.04, 0.0, 0.04, -0.04, 0.0); swSkSeg[3] = (SketchSegment)swModel.CreateLine2(0.04, -0.04, 0.0, -0.04, -0.04, 0.0); swSkSeg[4] = (SketchSegment)swModel.CreateLine2(-0.04, -0.04, 0.0, 0.04, 0.04, 0.0); swSkSeg[5] = (SketchSegment)swModel.CreateLine2(-0.04, 0.04, 0.0, 0.04, -0.04, 0.0); blScale = 0.03; break; } object vSkSeg = swSkSeg; swModel.Extension.MultiSelect(vSkSeg, true, null); SketchBlockDefinition swSketchBlockDef = swModel.SketchManager.MakeSketchBlockFromSelected(null); var swInst = swSketchBlockDef.IGetInstances(1); swInst.Scale = blScale; if (x != 0 && y != 0) { var objPoint = new double[3]; objPoint[0] = x+0.01; objPoint[1] = y; objPoint[2] = 0; var swMathUtil = swApp.IGetMathUtility(); var swMathPoint = (MathPoint)swMathUtil.CreatePoint(objPoint); swInst.InstancePosition = swMathPoint; instancePosition = swMathPoint; } swModel.SetAddToDB(false); swModel.GraphicsRedraw2(); swModel.ClearSelection(); return swInst.Name; }
internal SwDocument3D(IModelDoc2 model, ISldWorks app, ILogger logger) : base(model, app, logger) { m_MathUtils = app.IGetMathUtility(); }
internal SwApplication(ISldWorks app, ILogger logger) { Application = app; SwDocuments = new SwDocumentCollection(app, logger); GeometryBuilder = new SwGeometryBuilder(app.IGetMathUtility(), app.IGetModeler()); }
internal MacroFeatureParametersParser(ISldWorks app) { MathUtils = app.IGetMathUtility(); }
protected override IBody2[] CreateGeometry(ISldWorks app, CropBodiesDataModel parameters) { return(CropGeometry(app.IGetModeler(), app.IGetMathUtility(), parameters.TargetBodies, parameters.TrimTools)); }