private void OnClearSelection(IXDocument doc) { if (doc == m_App.Documents.Active) { InvokeTrigger(Triggers_e.Selection, doc); } }
private void OnRebuild(IXDocument doc) { if (doc == m_App.Documents.Active) { InvokeTrigger(Triggers_e.Rebuild, doc); } }
private void OnNewSelection(IXDocument doc, IXSelObject selObject) { if (doc == m_App.Documents.Active) { InvokeTrigger(Triggers_e.Selection, doc); } }
private void OnDocumentActivated(IXDocument doc) { if (doc == m_Model) { ShowIssues?.Invoke(m_IssuesVm); } }
private void OnDocumentClosing(IXDocument doc, DocumentCloseType_e type) { if (doc == m_App.Documents.Active) { InvokeTrigger(Triggers_e.DocumentClose, doc); } if (type == DocumentCloseType_e.Destroy) { switch (doc) { case IXDocument3D doc3D: doc3D.Configurations.ConfigurationActivated -= OnConfigurationActivated; break; case IXDrawing draw: draw.Sheets.SheetActivated -= OnSheetActivated; break; } doc.Selections.NewSelection -= OnNewSelection; doc.Selections.ClearSelection -= OnClearSelection; doc.Saving -= OnSaving; doc.Rebuilt -= OnRebuild; doc.Closing -= OnDocumentClosing; } }
public Example2a_2(IXDocument iXDocument, string initialXmlString = null) { File.WriteAllText(SettingsFile, initialXmlString ?? @"<?xml version=""1.0"" encoding=""utf-8"" ?><root><someNodeName /></root>"); xDoc = iXDocument.LoadEx(SettingsFile); }
protected override void ExtractRawParameters(IXCustomFeature feat, IXDocument doc, out Dictionary <string, object> parameters, out IXDimension[] dimensions, out IXSelObject[] selection, out IXBody[] editBodies) { object retParamNames = null; object retParamValues = null; object paramTypes = null; object retSelObj; object selObjType; object selMarks; object selDrViews; object compXforms; var featData = ((SwMacroFeature)feat).FeatureData; featData.GetParameters(out retParamNames, out paramTypes, out retParamValues); featData.GetSelections3(out retSelObj, out selObjType, out selMarks, out selDrViews, out compXforms); dimensions = GetDimensions(feat); var editBodiesObj = featData.EditBodies as object[]; if (editBodiesObj != null) { editBodies = editBodiesObj.Cast <IBody2>() .Select(b => SwObject.FromDispatch <SwBody>(b, (SwDocument)doc)).ToArray(); } else { editBodies = null; } var paramNames = retParamNames as string[]; var paramValues = retParamValues as string[]; if (paramNames != null) { parameters = new Dictionary <string, object>(); for (int i = 0; i < paramNames.Length; i++) { parameters.Add(paramNames[i], paramValues[i]); } } else { parameters = null; } var selObjects = retSelObj as object[]; if (selObjects != null) { selection = selObjects.Select(s => SwObject.FromDispatch <SwSelObject>(s, (SwDocument)doc)).ToArray(); } else { selection = null; } }
private IDocumentHandler CreateHandler(IXDocument doc, Type type) { var handler = (IDocumentHandler)m_Handlers[type].DynamicInvoke(); handler.Init(m_App, doc); return(handler); }
private static IEnumerable <IXDocument3D> EnumerateDependencies(IXDocument doc, List <string> usedPaths) { IXDocument3D[] deps = null; try { deps = doc.Dependencies; } catch { } foreach (var dep in deps ?? new IXDocument3D[0]) { if (!usedPaths.Contains(dep.Path, StringComparer.CurrentCultureIgnoreCase)) { usedPaths.Add(dep.Path); yield return(dep); foreach (var childDep in EnumerateDependencies(dep, usedPaths)) { yield return(childDep); } } } }
public THandler GetHandler <THandler>(IXDocument doc) where THandler : IDocumentHandler, new() { var handlers = m_DocsMap[doc]; return((THandler)handlers.First(h => h.GetType() == typeof(THandler))); }
private void CreateHandler(IXDocument doc, DocumentHandlerInfo handlerInfo, List <IDocumentHandler> handlersList) { var createHandler = false; var docType = doc.GetType(); if (handlerInfo.DocumentTypeFilters == null) { createHandler = true; } else { createHandler = handlerInfo.DocumentTypeFilters.Any(t => t.IsAssignableFrom(docType)); } if (createHandler) { m_Logger.Log($"Creating document handler '{handlerInfo.HandlerType.FullName}' for document type: {docType}", LoggerMessageSeverity_e.Debug); var handler = (IDocumentHandler)handlerInfo.Factory.DynamicInvoke(); handler.Init(m_App, doc); handlersList.Add(handler); } else { m_Logger.Log($"Skipping creation of document handler '{handlerInfo.HandlerType.FullName}' for document type: {docType}", LoggerMessageSeverity_e.Debug); } }
public virtual void SetParameters(IXDocument model, IXCustomFeature feat, object parameters, out CustomFeatureOutdateState_e state) { CustomFeatureParameter[] param; IXSelObject[] selection; CustomFeatureDimensionType_e[] dimTypes; double[] dimValues; IXBody[] bodies; Parse(parameters, out param, out selection, out dimTypes, out dimValues, out bodies); var dispDims = GetDimensions(feat); var dimsVersion = GetDimensionsVersion(feat); ConvertParameters(parameters.GetType(), dimsVersion, conv => { dispDims = conv.ConvertDisplayDimensions(model, feat, dispDims); }); if (dispDims != null) { if (dispDims.Length != dimValues.Length) { throw new ParametersMismatchException("Dimensions mismatch"); } } state = GetState(feat, dispDims); SetParametersToFeature(feat, selection, bodies, dispDims, dimValues, param); }
private void TryRunMacro(JobItemMacro macro, IXDocument doc) { try { macro.ClearIssues(); macro.Status = JobItemStatus_e.InProgress; m_MacroRunner.RunMacro(m_App, macro.Macro.FilePath, null, XCad.Enums.MacroRunOptions_e.UnloadAfterRun, macro.Macro.Arguments, doc); macro.Status = JobItemStatus_e.Succeeded; } catch (Exception ex) { string errorDesc; if (ex is MacroRunFailedException) { errorDesc = (ex as MacroRunFailedException).Message; } else { errorDesc = ex.ParseUserError("Unknown error"); } LogMessage($"Failed to run macro '{macro.FilePath}': {errorDesc}"); macro.ReportError(ex); macro.Status = JobItemStatus_e.Failed; } }
private void OnDocumentLoaded(IXDocument doc) { var issuesDoc = m_Ext.Application.Documents.GetHandler <IssuesDocument>(doc); issuesDoc.Destroyed += OnIssuesDocDestroyed; issuesDoc.ShowIssues += OnShowIssues; }
public Example2a_2(IXDocument iXDocument, string initialXmlString = null) { File.WriteAllText(SettingsFile, initialXmlString ?? @"<?xml version=""1.0"" encoding=""utf-8"" ?><root><someNodeName /></root>"); xDoc = iXDocument.LoadEx(SettingsFile); }
private void OnStreamWriteAvailable(IXDocument doc) { if (m_HasChanges) { m_Logger.Log("Storing QR code data", LoggerMessageSeverity_e.Debug); try { using (var stream = m_Drawing.OpenStream(STREAM_NAME, AccessType_e.Write)) { using (var writer = new StreamWriter(stream)) { m_Serializer.StoreSettings(QrCodes, writer, new PictureValueSerializer(m_Logger, m_Drawing)); } } m_HasChanges = false; } catch (Exception ex) { m_Logger.Log(ex); } } }
public Example2a_2() { File.WriteAllText(SettingsFile, @"<?xml version=""1.0"" encoding=""utf-8"" ?><root><someNodeName /></root>"); xDoc = XDocumentExt.Load(SettingsFile); }
public void Init(IXApplication app, IXDocument model) { Document = (ISwDocument)model; Application = ((ISwApplication)app).Sw; OnInit((ISwApplication)app, Document); Model = Document.Model; switch (Model) { case PartDoc part: AttachPartEvents(part); break; case AssemblyDoc assm: AttachAssemblyEvents(assm); break; case DrawingDoc drw: AttachDrawingEvents(drw); break; default: throw new NotSupportedException("Not a SOLIDWORKS document"); } }
public Example2a_2() { File.WriteAllText(SettingsFile, @"<?xml version=""1.0"" encoding=""utf-8"" ?><root><someNodeName /></root>"); xDoc = XDocumentExt.Load(SettingsFile); }
private IDocumentHandler CreateHandler(IXDocument doc, Type type) { var handler = (IDocumentHandler)Activator.CreateInstance(type); handler.Init(m_App, doc); return(handler); }
private void OnSaving(IXDocument doc, DocumentSaveType_e type, DocumentSaveArgs args) { if (doc == m_App.Documents.Active) { InvokeTrigger(Triggers_e.DocumentSave, doc); } }
internal ViewFreeze(IXDocument doc) { m_Model = ((ISwDocument)doc).Model; m_Model.FeatureManager.EnableFeatureTree = false; m_Model.FeatureManager.EnableFeatureTreeWindow = false; m_Model.IActiveView.EnableGraphicsUpdate = false; }
public void Init(IXApplication app, IXDocument model) { m_App = app; m_Model = model; m_App.Documents.DocumentActivated += OnDocumentActivated; m_Model.StorageReadAvailable += OnStorageReadAvailable; m_Model.StorageWriteAvailable += OnStorageWriteAvailable; }
public override Dictionary <string, string> ConvertParameters(IXDocument model, IXCustomFeature feat, Dictionary <string, string> parameters) { var paramVal = parameters["Param1"]; parameters.Remove("Param1"); parameters.Add("Param1A", paramVal); //renaming parameter parameters.Add("Param3", "Default"); //adding new parameter with default value return(parameters); }
public void ReleaseHandlers(IXDocument doc) { foreach (var handler in m_DocsMap[doc]) { handler.Dispose(); } m_DocsMap[doc].Clear(); m_DocsMap.Remove(doc); }
public void Insert(IXDocument model) { m_CurData = new TPage(); CurModel = model; m_EditingFeature = null; m_PmPage.Show(m_CurData); }
/// <summary> /// Returns all dependencies including nested dependencies /// </summary> /// <param name="doc">Input document</param> /// <param name="topLevelOnly">True to only load top level references, false to recursively load all references</param> /// <param name="allowCommit">Allow commit documents if not commited</param> /// <param name="allowReadOnly">Allow commit documents in read-only state if allowCommit is true and source document is open with write access</param> /// <returns>All dependencies</returns> public static IEnumerable <IXDocument3D> IterateDependencies(this IXDocument doc, bool topLevelOnly = false, bool allowCommit = true, bool allowReadOnly = true) { if (doc == null) { throw new ArgumentNullException(nameof(doc)); } return(EnumerateDependencies(doc, !topLevelOnly, doc.State.HasFlag(DocumentState_e.ReadOnly), allowCommit, allowReadOnly, new List <string>())); }
public void RunMacro(IXApplication app, string macroPath, MacroEntryPoint entryPoint, MacroRunOptions_e opts, string args, IXDocument doc) { try { if (entryPoint == null) { var macro = app.OpenMacro(macroPath); entryPoint = macro.EntryPoints.First(); } if (!string.IsNullOrEmpty(args) || doc != null) { if (m_Runner != null) { var param = new MacroParameter(); if (doc != null) { param.Set("Model", GetDocumentDispatch(doc)); } if (!string.IsNullOrEmpty(args)) { param.Set("Args", ParseCommandLine(args)); } var res = m_Runner.Run(GetAppDispatch(app), macroPath, entryPoint.ModuleName, entryPoint.ProcedureName, (int)opts, param, true); if (!res.Result) { throw new MacroRunnerResultError(res.Message); } } else { throw new UserException("Macro runner is not installed. Cannot run the macro with arguments"); } } else { var macro = app.OpenMacro(macroPath); macro.Run(entryPoint, opts); } } catch (MacroUserInterruptException) //do not consider this as an error { } catch (MacroRunnerResultError resEx) { throw new MacroRunFailedException(macroPath, -1, resEx.Message); } }
public static IStorage TryOpenStorage(this IXDocument doc, string name, AccessType_e access) { try { return(doc.OpenStorage(name, access)); } catch { return(null); } }
public void Init(IXApplication app, IXDocument model) { m_HasChanges = false; if (model is IXDrawing) { m_Drawing = (IXDrawing)model; m_Drawing.StreamWriteAvailable += OnStreamWriteAvailable; m_QrCodesLazy = new Lazy <ObservableCollection <QrCodeInfo> >(ReadQrCodeData); } }
//--- //--- 3rdParty private void OnWriteToStream(IXDocument doc) { const string STREAM_NAME = "CodeStackStream"; using (var str = doc.OpenStream(STREAM_NAME, AccessType_e.Write)) { var xmlSer = new XmlSerializer(typeof(string[])); xmlSer.Serialize(str, new string[] { "A", "B" }); } }
public void Init(IXApplication app, IXDocument model) { m_App = app; m_Model = model; m_Model.StreamReadAvailable += LoadFromStream; m_Model.StreamWriteAvailable += SaveToStream; m_Model.StorageReadAvailable += LoadFromStorage; m_Model.StorageWriteAvailable += SaveToStorage; //m_App.ShowMessageBox($"Opened {model.Title}"); }
/// <summary> /// Initializes a new instance of the <see cref="IXDocument"/> class from an existing IXDocument object. /// </summary> /// <param name="other"> /// The <see cref="IXDocument"/> object that will be copied. /// </param> public IXDocument Create(IXDocument other) { return new XDocumentWrap(other.Document); }