Ejemplo n.º 1
0
 private void OnClearSelection(IXDocument doc)
 {
     if (doc == m_App.Documents.Active)
     {
         InvokeTrigger(Triggers_e.Selection, doc);
     }
 }
Ejemplo n.º 2
0
 private void OnRebuild(IXDocument doc)
 {
     if (doc == m_App.Documents.Active)
     {
         InvokeTrigger(Triggers_e.Rebuild, doc);
     }
 }
Ejemplo n.º 3
0
 private void OnNewSelection(IXDocument doc, IXSelObject selObject)
 {
     if (doc == m_App.Documents.Active)
     {
         InvokeTrigger(Triggers_e.Selection, doc);
     }
 }
Ejemplo n.º 4
0
 private void OnDocumentActivated(IXDocument doc)
 {
     if (doc == m_Model)
     {
         ShowIssues?.Invoke(m_IssuesVm);
     }
 }
Ejemplo n.º 5
0
        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;
            }
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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;
            }
        }
Ejemplo n.º 8
0
        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);
                    }
                }
            }
        }
Ejemplo n.º 10
0
        public THandler GetHandler <THandler>(IXDocument doc)
            where THandler : IDocumentHandler, new()
        {
            var handlers = m_DocsMap[doc];

            return((THandler)handlers.First(h => h.GetType() == typeof(THandler)));
        }
Ejemplo n.º 11
0
        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);
            }
        }
Ejemplo n.º 12
0
        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);
        }
Ejemplo n.º 13
0
        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;
            }
        }
Ejemplo n.º 14
0
        private void OnDocumentLoaded(IXDocument doc)
        {
            var issuesDoc = m_Ext.Application.Documents.GetHandler <IssuesDocument>(doc);

            issuesDoc.Destroyed  += OnIssuesDocDestroyed;
            issuesDoc.ShowIssues += OnShowIssues;
        }
Ejemplo n.º 15
0
        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);
        }
Ejemplo n.º 16
0
        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);
                }
            }
        }
Ejemplo n.º 17
0
        public Example2a_2()
        {
            File.WriteAllText(SettingsFile,
                              @"<?xml version=""1.0"" encoding=""utf-8"" ?><root><someNodeName /></root>");

            xDoc = XDocumentExt.Load(SettingsFile);
        }
Ejemplo n.º 18
0
        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");
            }
        }
Ejemplo n.º 19
0
        public Example2a_2()
        {
            File.WriteAllText(SettingsFile,
                @"<?xml version=""1.0"" encoding=""utf-8"" ?><root><someNodeName /></root>");

            xDoc = XDocumentExt.Load(SettingsFile);
        }
Ejemplo n.º 20
0
        private IDocumentHandler CreateHandler(IXDocument doc, Type type)
        {
            var handler = (IDocumentHandler)Activator.CreateInstance(type);

            handler.Init(m_App, doc);
            return(handler);
        }
Ejemplo n.º 21
0
 private void OnSaving(IXDocument doc, DocumentSaveType_e type,
                       DocumentSaveArgs args)
 {
     if (doc == m_App.Documents.Active)
     {
         InvokeTrigger(Triggers_e.DocumentSave, doc);
     }
 }
Ejemplo n.º 22
0
            internal ViewFreeze(IXDocument doc)
            {
                m_Model = ((ISwDocument)doc).Model;

                m_Model.FeatureManager.EnableFeatureTree       = false;
                m_Model.FeatureManager.EnableFeatureTreeWindow = false;
                m_Model.IActiveView.EnableGraphicsUpdate       = false;
            }
Ejemplo n.º 23
0
        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;
        }
Ejemplo n.º 24
0
            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);
            }
Ejemplo n.º 25
0
        public void ReleaseHandlers(IXDocument doc)
        {
            foreach (var handler in m_DocsMap[doc])
            {
                handler.Dispose();
            }

            m_DocsMap[doc].Clear();
            m_DocsMap.Remove(doc);
        }
Ejemplo n.º 26
0
        public void Insert(IXDocument model)
        {
            m_CurData = new TPage();

            CurModel = model;

            m_EditingFeature = null;

            m_PmPage.Show(m_CurData);
        }
Ejemplo n.º 27
0
        /// <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>()));
        }
Ejemplo n.º 28
0
        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);
            }
        }
Ejemplo n.º 29
0
 public static IStorage TryOpenStorage(this IXDocument doc, string name, AccessType_e access)
 {
     try
     {
         return(doc.OpenStorage(name, access));
     }
     catch
     {
         return(null);
     }
 }
Ejemplo n.º 30
0
        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);
            }
        }
Ejemplo n.º 31
0
        //---
        //--- 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" });
            }
        }
Ejemplo n.º 32
0
        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);
 }