public object InsertTreeNode(object parentNode, TreeNode node) { string slineFrom = parentNode as string; Console.WriteLine(slineFrom + string.Format("Node : {0}({1})", node.Name, node.Description)); string slineTo = slineFrom + " "; return (object)(slineTo); }
public override bool Process(Pic.DAL.SQLite.PPDataContext db, TreeNode tn) { if (!tn.IsComponent) return true; try { string filePath = tn.Documents(db)[0].File.Path(db); Pic.Plugin.Component comp = _compLoader.LoadComponent(filePath); if (null != _callback && null != comp) _callback.Info(string.Format("Successfully loaded component {0}", tn.Name)); else _callback.Error(string.Format("Failed to load component {0}", tn.Name)); Pic.Plugin.ParameterStack stack = comp.BuildParameterStack(null); foreach (Pic.Plugin.Parameter param in stack) { if (param.IsMajoration) continue; // only add parameter description TryAndAddString( param.Description ); // ParameterMulti ? Pic.Plugin.ParameterMulti paramMulti = param as Pic.Plugin.ParameterMulti; if (null != paramMulti) { foreach (string sText in paramMulti.DisplayList) TryAndAddString(sText); } } } catch (Exception ex) { if (null != _callback) _callback.Error(ex.Message); } return true; }
private void ToolStripButtonPDF3D_Click(object sender, EventArgs e) { Pic.Plugin.Component comp = pluginViewCtrl.Component; if (!pluginViewCtrl.Visible || null == comp || !comp.IsSupportingAutomaticFolding) { return; } // get documents at the same lavel NodeTag nodeTag = treeView.SelectedNode.Tag as NodeTag; if (null == nodeTag) { return; } PPDataContext db = new PPDataContext(); Pic.DAL.SQLite.TreeNode treeNode = Pic.DAL.SQLite.TreeNode.GetById(db, nodeTag.TreeNode); List <Document> des3Docs = treeNode.GetBrothersWithExtension(db, "des3"); if (0 == des3Docs.Count) { MessageBox.Show("Missing des3 for sample pattern files"); return; } // get default thickness Sharp3D.Math.Core.Vector2D refPoint = Sharp3D.Math.Core.Vector2D.Zero; double thickness = 0.0; if (!pluginViewCtrl.GetReferencePointAndThickness(ref refPoint, ref thickness)) { MessageBox.Show("Failed to retrieve reference point and thickness"); return; } // allow if (!System.IO.File.Exists(Pic3DExporterPath)) { MessageBox.Show(string.Format("File {0} could not be found!", Pic3DExporterPath)); return; } // show form and generate PDF 3D FormGeneratePDF3D form = new FormGeneratePDF3D(this) { OutputFilePath = Path.ChangeExtension(Path.Combine(Path.GetTempPath(), treeNode.Name), "pdf"), thickness = thickness, v = refPoint }; foreach (Document d in des3Docs) { form.filePathes.Add(d.File.Path(db)); } form.ShowDialog(); }
public void OnToolStripEditComponentCode(object sender, EventArgs e) { try { if (!(treeView.SelectedNode.Tag is NodeTag nodeTag)) { return; } PPDataContext db = new PPDataContext(); Pic.DAL.SQLite.TreeNode treeNode = Pic.DAL.SQLite.TreeNode.GetById(db, nodeTag.TreeNode); if (null == treeNode) { return; } Document doc = treeNode.Documents(db)[0]; if (null == doc) { return; } Pic.DAL.SQLite.Component comp = doc.Components[0]; if (null == comp) { return; } // output Guid / path Guid outputGuid = Guid.NewGuid(); string outputPath = Pic.DAL.SQLite.File.GuidToPath(db, outputGuid, "dll"); // form plugin editor FormPluginEditor editorForm = new FormPluginEditor(); editorForm.PluginPath = doc.File.Path(db); editorForm.OutputPath = outputPath; if (DialogResult.OK == editorForm.ShowDialog()) { _log.Info("Component successfully modified!"); doc.File.Guid = outputGuid; db.SubmitChanges(); // clear component cache in plugin viewer ComponentLoader.ClearCache(); // update pluginviewer pluginViewCtrl.PluginPath = outputPath; } } catch (Exception ex) { _log.Error(ex.ToString()); } }
private void OnBnOkClicked(object sender, EventArgs e) { try { string filePath = fileSelectCtrl.FileName; string fileExt = Path.GetExtension(filePath).ToLower(); fileExt = fileExt.Substring(1); if (!File.Exists(filePath)) { return; } // get tree node for document insertion PPDataContext db = new PPDataContext(); if (null == _nodeTag || _nodeTag.IsDocument) { throw new Exception("Invalid TreeNode tag"); } TreeNode treeNode = Pic.DAL.SQLite.TreeNode.GetById(db, _nodeTag.TreeNode); if (string.Equals("dll", fileExt, StringComparison.CurrentCultureIgnoreCase)) { // make sure "Parametric Component" document type exist if (null == DocumentType.GetByName(db, "Parametric component")) { DocumentType.CreateNew(db, "Parametric component", "Parametric component", "PicParam"); } // create new document Component component = treeNode.InsertComponent( db , filePath , componentLoaderControl.ComponentGuid , DocumentName , DocumentDescription , ThumbnailPath); // create associated majorations if any if (componentLoaderControl.HasMajorations) { component.InsertNewMajorationSet(db, componentLoaderControl.Profile, componentLoaderControl.Majorations); } // create associated default param values if (chkDefaultParameters.Checked) { component.InsertNewParamDefaultValues(db, componentLoaderControl.ParamDefaultValues); } // save document ID to be used later // -> to retrieve document tree node DocumentID = component.DocumentID; OpenInsertedDocument = true; } else { // get a format handler FormatHandler fHandler = FFormatManager.GetFormatHandlerFromFileExt(fileExt); if (null == fHandler) { throw new ExceptionDAL(string.Format("No valid format handler from file extension: {0}", fileExt)); } // get document type DocumentType docType = DocumentType.GetByName(db, fHandler.Name); if (null == docType) { docType = DocumentType.CreateNew(db, fHandler.Name, fHandler.Description, fHandler.Application); } // insert document in database Document document = treeNode.InsertDocument( db , filePath , DocumentName , DocumentDescription , docType.Name , ThumbnailPath); // save document ID DocumentID = document.ID; OpenInsertedDocument = fHandler.OpenInPLMPackLib; } } catch (ExceptionDAL ex) { MessageBox.Show( ex.Message , Application.ProductName , MessageBoxButtons.OK , MessageBoxIcon.Error); _log.Error(ex.ToString()); } catch (Exception ex) { _log.Error(ex.ToString()); } }
private void TreeNodes_Detach(TreeNode entity) { this.SendPropertyChanging(); entity.ParentNodeIDTreeNode = null; }
private void TreeNodes_Detach(TreeNode entity) { this.SendPropertyChanging(); entity.Thumbnail = null; }
// process methods to be implemented public abstract bool Process(Pic.DAL.SQLite.PPDataContext db, TreeNode tn);
private void OnGeneratePic3D(object sender, EventArgs e) { Pic.Plugin.Component comp = pluginViewCtrl.Component; if (!pluginViewCtrl.Visible || null == comp || !comp.IsSupportingAutomaticFolding) { return; } // get documents at the same lavel if (!(treeView.SelectedNode.Tag is NodeTag nodeTag)) { return; } PPDataContext db = new PPDataContext(); Pic.DAL.SQLite.TreeNode treeNode = Pic.DAL.SQLite.TreeNode.GetById(db, nodeTag.TreeNode); List <Document> des3Docs = treeNode.GetBrothersWithExtension(db, "des3"); if (0 == des3Docs.Count) { MessageBox.Show("Missing des3 for sample pattern files"); return; } List <string> filePathes = new List <string>(); foreach (Document d in des3Docs) { filePathes.Add(d.File.Path(db)); } SaveFileDialog fd = new SaveFileDialog { Filter = "Picador 3D files (*.des3)|*.des3|All files (*.*)|*.*", FilterIndex = 0, DefaultExt = "des3", FileName = treeNode.Name + ".des3" }; if (DialogResult.OK == fd.ShowDialog()) { string des3File = fd.FileName; string desFile = Path.ChangeExtension(des3File, "des"); string xmlFile = Path.ChangeExtension(des3File, "xml"); string currentDir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); // generate des file Export(desFile); // reference point double thickness = 0.0; Sharp3D.Math.Core.Vector2D v = Sharp3D.Math.Core.Vector2D.Zero; if (pluginViewCtrl.GetReferencePointAndThickness(ref v, ref thickness)) { // #### job file Pic3DExporter.Job job = new Pic3DExporter.Job(); // **** FILES BEGIN **** job.Pathes.Add(new Pic3DExporter.PathItem() { pathID = "FID-1", path = desFile, type = Pic3DExporter.pathType.FILE }); job.Pathes.Add(new Pic3DExporter.PathItem() { pathID = "FID-2", path = des3File, type = Pic3DExporter.pathType.FILE }); int fid = 2; foreach (string filePath in filePathes) { job.Pathes.Add(new Pic3DExporter.PathItem() { pathID = string.Format("FID-{0}", ++fid), path = filePath, type = Pic3DExporter.pathType.FILE }); } // **** FILES END **** // **** TASKS BEGIN **** // DES -> DES3 Pic3DExporter.task_2D_TO_DES3 task_2D_to_DES3 = new Pic3DExporter.task_2D_TO_DES3() { id = "TID-1" }; task_2D_to_DES3.Inputs.Add(new Pic3DExporter.PathRef() { pathID = "FID-1", role = "input des", deleteAfterUsing = false }); task_2D_to_DES3.Outputs.Add(new Pic3DExporter.PathRef() { pathID = "FID-2", role = "output des3", deleteAfterUsing = false }); task_2D_to_DES3.autoparameters.thicknessSpecified = true; task_2D_to_DES3.autoparameters.thickness = (float)thickness; task_2D_to_DES3.autoparameters.foldPositionSpecified = true; task_2D_to_DES3.autoparameters.foldPosition = (float)0.5; task_2D_to_DES3.autoparameters.pointRef.Add((float)v.X); task_2D_to_DES3.autoparameters.pointRef.Add((float)v.Y); fid = 2; foreach (string filePath in filePathes) { task_2D_to_DES3.autoparameters.modelFiles.Add( new Pic3DExporter.PathRef() { pathID = string.Format("FID-{0}", ++fid), role = "model files", deleteAfterUsing = false }); } job.Tasks.Add(task_2D_to_DES3); // **** TASKS END **** job.SaveToFile(xmlFile); // #### execute Pic3DExporter string exePath = Pic3DExporterPath; if (!System.IO.File.Exists(exePath)) { MessageBox.Show(string.Format("File {0} could not be found!", exePath)); return; } var procExporter = new Process { StartInfo = new ProcessStartInfo { FileName = exePath, Arguments = string.Format(" -t \"{0}\"", xmlFile), UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = false, RedirectStandardError = false } }; procExporter.Start(); procExporter.WaitForExit(); Thread.Sleep(1000); // delete xml task file try { if (!Settings.Default.ShowLogConsole) { System.IO.File.Delete(xmlFile); } } catch (Exception) { } } if (System.IO.File.Exists(des3File)) { if (ApplicationAvailabilityChecker.IsAvailable("Picador3D")) { var procPic3D = new Process { StartInfo = new ProcessStartInfo { FileName = des3File, UseShellExecute = true, CreateNoWindow = false, Verb = "open", WindowStyle = ProcessWindowStyle.Normal } }; procPic3D.Start(); } } else { MessageBox.Show(string.Format("Failed to generate {0}", des3File)); } } }
private void OnSelectionChanged(object sender, NodeEventArgs e, string name) { try { // storing current tag TagCurrent = e.NodeTag; // change view name (seen in tab) Text = TagCurrent.Name; // show / hide browsing controls branchViewCtrl.Visible = IsBranch; pluginViewCtrl.Visible = false; factoryViewCtrl.Visible = false; webBrowser4PDF.Visible = false; unknownFormatViewCtrl.Visible = false; if (IsDocument) { PPDataContext db = new PPDataContext(); Pic.DAL.SQLite.TreeNode treeNode = Pic.DAL.SQLite.TreeNode.GetById(db, e.NodeTag.TreeNode); Document doc = treeNode.Documents(db)[0]; // select document handler depending on document type string docTypeName = doc.DocumentType.Name; string filePath = doc.File.Path(db); string fileExt = Path.GetExtension(filePath).Trim('.').ToLower(); log4net.Config.XmlConfigurator.Configure(); if (!System.IO.File.Exists(filePath)) { MessageBox.Show($"File {filePath} not found!"); } else { _log.Info($"Loading file {filePath}..."); } switch (fileExt) { case "dll": LoadComponent(filePath); break; case "des": case "dxf": case "cf2": case "cff2": LoadDrawing(filePath, fileExt); break; case "pdf": LoadPdf(filePath); break; case "png": case "bmp": case "jpg": case "jpeg": LoadImageFile(filePath); break; case "des3": case "doc": case "xls": case "dwg": case "ai": case "sxw": case "stw": case "sxc": case "stc": case "ard": default: LoadUnknownFileFormat(filePath, TagCurrent.Name); break; } } // update other branch/tree view control if (sender != branchViewCtrl) { branchViewCtrl.ShowBranch(TagCurrent); } if (sender != treeView) { treeView.SelectNode(TagCurrent); } } catch (ParameterNotFound ex) { _log.Error(ex.Message); } catch (Exception ex) { _log.Error(ex.ToString()); } SelectionChanged?.Invoke(this); }
public static void ClearExistingDocumentsRecursively(PPDataContext dbFrom, TreeNode nodeFrom, TreeNode nodeTo, IProcessingCallback callback) { if (null != callback && !nodeFrom.IsDocument) callback.Info(string.Format("Processing branch {0}", nodeFrom.Name)); // get thumbnail path of node to insert string thumbnailPath = nodeFrom.Thumbnail.File.Path(dbFrom); // handle childrens foreach (TreeNode childFrom in nodeFrom.Childrens(dbFrom)) { // get thumbnail of node to insert thumbnailPath = childFrom.Thumbnail.File.Path(dbFrom); if (childFrom.IsDocument) { Document docFrom = childFrom.Documents(dbFrom)[0]; string docTypeName = docFrom.DocumentType.Name; // delete existing document // will be using new data context each time a tree node is deleted // in order to avoid exceptions claiming that there is a foreign key violation using (PPDataContext dbTo0 = new PPDataContext()) { if (nodeTo.HasChild(dbTo0, childFrom.Name)) { string documentName = childFrom.Name; TreeNode childTo = nodeTo.GetChild(dbTo0, documentName); if (null != childTo && childTo.IsDocument) { try { if (null != callback) callback.Info(string.Format("Deleting tree node {0} ...", childTo.Name)); childTo.Delete(dbTo0, true, callback); dbTo0.SubmitChanges(); } catch (Exception ex) { callback.Error(string.Format("Deleting document {0} failed with exception {1}", documentName, ex.Message)); } } } } } else // childFrom.IsDocument { using (PPDataContext dbTo2 = new PPDataContext()) { TreeNode childTo = null; if (nodeTo.HasChild(dbTo2, childFrom.Name)) { if (null != callback) callback.Info(string.Format("Branch {0} already exists.Skipping...", childFrom.Name)); childTo = nodeTo.GetChild(dbTo2, childFrom.Name); ClearExistingDocumentsRecursively(dbFrom, childFrom, childTo, callback); } } } } }
public static void MergeTreeNodesRecursively(PPDataContext dbFrom, PPDataContext dbTo, TreeNode nodeFrom, TreeNode nodeTo, IProcessingCallback callback) { if (null != callback && !nodeFrom.IsDocument) callback.Info(string.Format("Processing branch {0}", nodeFrom.Name)); // get thumbnail path of node to insert string thumbnailPath = nodeFrom.Thumbnail.File.Path(dbFrom); // handle childrens foreach (TreeNode childFrom in nodeFrom.Childrens(dbFrom)) { // get thumbnail of node to insert thumbnailPath = childFrom.Thumbnail.File.Path(dbFrom); if (childFrom.IsDocument) { Document docFrom = childFrom.Documents(dbFrom)[0]; string docTypeName = docFrom.DocumentType.Name; if (nodeTo.HasChild(dbTo, childFrom.Name)) { if (null != callback) callback.Info(string.Format("Document {0} already exists...", childFrom.Name)); } else { if (string.Equals("Parametric component", docTypeName, StringComparison.CurrentCultureIgnoreCase)) { if (null != callback) callback.Info(string.Format("Parametric component {0} already exists...", childFrom.Name)); // insert as component Component compFrom = docFrom.Components[0]; Component compTo = Component.GetByGuid(dbTo, compFrom.Guid); if (null == compTo) { if (null != callback) callback.Info(string.Format("Inserting component {0}...", childFrom.Name)); compTo = nodeTo.InsertComponent(dbTo, docFrom.File.Path(dbFrom), compFrom.Guid, childFrom.Name, childFrom.Description, thumbnailPath); // parameter default values Dictionary<string, double> dictNameValues = compFrom.GetParamDefaultValues(); if (dictNameValues.Count > 0) { if (null != callback) { string sParameters = string.Empty; foreach (string defParamName in dictNameValues.Keys) { StringBuilder sb = new StringBuilder(); sb.Append(defParamName); sb.Append("="); sb.Append(dictNameValues[defParamName]); sb.Append(", "); sParameters += sb.ToString(); } sParameters.Trim(); sParameters.Trim(','); callback.Info(string.Format("Default parameter values : {0}", sParameters)); } compTo.InsertNewParamDefaultValues(dbTo, dictNameValues); } // majorations foreach (MajorationSet mjset in compFrom.MajorationSets) { // retrieve profile string profileName = mjset.CardboardProfile.Name; CardboardProfile profileTo = CardboardProfile.GetByName(dbTo, profileName); if (null == profileTo) { if (null != callback) callback.Error(string.Format("Failed to retrieve profile {0}", mjset.CardboardProfile.Name)); continue; } // get majorations Dictionary<string, double> majorations = new Dictionary<string, double>(); string sMajo = string.Format("prof = {0} -> ", profileName); foreach (Majoration mj in mjset.Majorations) { majorations.Add(mj.Name, mj.Value); sMajo += string.Format("{0}={1}, ", mj.Name, mj.Value); } // insert if (null != callback) callback.Info(sMajo); compTo.InsertNewMajorationSet(dbTo, profileTo.Name, majorations); } } else { if (null != callback) callback.Info(string.Format("Component with GUID {0} already exists...", compFrom.Guid)); } } else { if (null != callback) callback.Info(string.Format("Inserting document {0}...", childFrom.Name)); // insert as document nodeTo.InsertDocument(dbTo, docFrom.File.Path(dbFrom), childFrom.Name, childFrom.Description, docTypeName, thumbnailPath); } } } else { TreeNode childTo = null; if (nodeTo.HasChild(dbTo, childFrom.Name)) { if (null != callback) callback.Info(string.Format("Branch {0} already exists.Skipping...", childFrom.Name)); childTo = nodeTo.GetChild(dbTo, childFrom.Name); } else { if (null != callback) callback.Info(string.Format("Inserting branch {0}...", childFrom.Name)); childTo = nodeTo.CreateChild(dbTo, childFrom.Name, childFrom.Description, thumbnailPath); } MergeTreeNodesRecursively(dbFrom, dbTo, childFrom, childTo, callback); } } }
private void InsertChildNodes(PPDataContext db, TreeInterface treeImplementation, object parentNode, TreeNode node) { // node itself Object object1 = treeImplementation.InsertTreeNode(parentNode, node); // child nodes List<TreeNode> childNodes = node.Childrens(db); foreach (TreeNode tn in childNodes) InsertChildNodes(db, treeImplementation, object1, tn); }