Exemplo n.º 1
0
        public override void SetComponent(Pic.Plugin.Component comp)
        {
            if (null == comp)
            {
                return;
            }
            _dictMajoration = null;
            PPDataContext db = new PPDataContext();

            _comp = Pic.DAL.SQLite.Component.GetByGuid(db, comp.Guid);
        }
Exemplo n.º 2
0
        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();
        }
Exemplo n.º 3
0
 /// <summary>
 /// Instantiates the <see cref="Tools"/> class
 /// </summary>
 /// <param name="component">An instance of the <see cref="Component"/> class.</param>
 public Tools(Component component, IComponentSearchMethod searchMethod)
 {
     _component = component;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Instantiates the <see cref="Tools"/> class
 /// </summary>
 /// <param name="filepath">Component file path</param>
 public Tools(string filepath, IComponentSearchMethod searchMethod)
 {
     ComponentLoader loader = new ComponentLoader();
     loader.SearchMethod = searchMethod;
     _component = loader.LoadComponent(filepath);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Loads a plugin from a given file path
 /// </summary>
 /// <param name="filepath">Plugin file path</param>
 private void LoadPluginFromFile(string filepath)
 {
     ComponentLoader loader = new ComponentLoader();            
     _component = loader.LoadComponent(filepath);
 }
        public FormEditMajorations(int compId, Profile currentProfile, ProfileLoader profileLoader)
        {
            InitializeComponent();

            _componentId   = compId;
            _profileLoader = profileLoader;

            if (!DesignMode)
            {
                // plugin viewer
                _pluginViewCtrl          = new PluginViewCtrl();
                _pluginViewCtrl.Size     = _pb.Size;
                _pluginViewCtrl.Location = _pb.Location;
                _pluginViewCtrl.Visible  = true;
                this.Controls.Add(_pluginViewCtrl);
                // hide
                _pb.Visible = false;
            }

            // fill combo box
            FillProfileComboBox(currentProfile.ToString());

            // get parameter stack
            Pic.Plugin.ParameterStack stack = null;
            using (Pic.Plugin.ComponentLoader loader = new Pic.Plugin.ComponentLoader())
            {
                PPDataContext            db        = new PPDataContext();
                Pic.DAL.SQLite.Component comp      = Pic.DAL.SQLite.Component.GetById(db, _componentId);
                Pic.Plugin.Component     component = loader.LoadComponent(comp.Document.File.Path(db));
                stack = component.BuildParameterStack(null);
                // load component in pluginviewer
                _pluginViewCtrl.Component = component;
            }

            // insert majoration label and textbox controls
            int lblX = 20, lblY = 60;
            int offsetX = 110, offsetY = 29;
            int tabIndex = bnCancel.TabIndex;
            int iCount   = 0;

            foreach (Parameter param in stack.ParameterList)
            {
                // only shows majorations
                if (!param.IsMajoration)
                {
                    continue;
                }
                ParameterDouble paramDouble = param as ParameterDouble;
                // create Label control
                Label lbl = new Label();
                lbl.Name     = string.Format("lbl_{0}", param.Name);
                lbl.Text     = param.Name;
                lbl.Location = new Point(
                    lblX + (iCount / 5) * offsetX
                    , lblY + (iCount % 5) * offsetY);
                lbl.Size     = new Size(30, 13);
                lbl.TabIndex = ++tabIndex;
                this.Controls.Add(lbl);
                // create NumericUpDown control
                NumericUpDown nud = new NumericUpDown();
                nud.Name          = string.Format("nud_{0}", param.Name);
                nud.Increment     = 0.1M;
                nud.Minimum       = paramDouble.HasValueMin ? (decimal)paramDouble.ValueMin : -10000.0M;
                nud.Maximum       = paramDouble.HasValueMax ? (decimal)paramDouble.ValueMax : 10000.0M;
                nud.DecimalPlaces = 1;
                nud.Value         = (decimal)paramDouble.Value;
                nud.Location      = new Point(
                    lblX + (iCount / 5) * offsetX + lbl.Size.Width + 1
                    , lblY + (iCount % 5) * offsetY);
                nud.Size          = new Size(60, 20);
                nud.TabIndex      = ++tabIndex;
                nud.ValueChanged += new EventHandler(nudValueChanged);
                nud.GotFocus     += new EventHandler(nud_GotFocus);
                nud.Click        += new EventHandler(nud_GotFocus);
                this.Controls.Add(nud);

                ++iCount;
            }

            UpdateMajorationValues();
        }
        public bool LoadComponent(string filePath)
        {
            _filePath = filePath;
            if (DesignMode)
            {
                return(false);
            }
            try
            {
                // initialize control
                pluginViewCtrl.PluginPath = filePath;

                // load component
                Pic.Plugin.Component component = null;
                using (Pic.Plugin.ComponentLoader loader = new Pic.Plugin.ComponentLoader())
                {
                    loader.SearchMethod = new ComponentSearchMethodDB();
                    component           = loader.LoadComponent(filePath);
                }
                if (null == component)
                {
                    return(false);
                }
                _componentGuid = component.Guid;

                // get parameters
                Pic.Plugin.ParameterStack stack = null;
                stack = component.BuildParameterStack(null);
                // fill name/description if empty
                _componentName        = component.Name;
                _componentDescription = component.Description;
                // build dict of double parameters
                _dictParamDefaultValues.Clear();
                foreach (Parameter param in stack.ParameterList)
                {
                    ParameterDouble paramDouble = param as ParameterDouble;
                    if (null != paramDouble)
                    {
                        _dictParamDefaultValues[paramDouble.Name] = paramDouble.ValueDefault;
                    }
                }
                // insert majoration label and textbox controls
                const int lblX = 16, lblY = 51;
                const int offsetX = 100, offsetY = 29;
                const int lbSizeX = 34, lbSizeY = 14;
                int       tabIndex = comboBoxProfile.TabIndex;

                groupBoxMajorations.Controls.Clear();

                bool hasMajorations = stack.HasMajorations;
                if (hasMajorations)
                {
                    // add combo box / label again
                    groupBoxMajorations.Controls.Add(lblProfile);
                    groupBoxMajorations.Controls.Add(comboBoxProfile);

                    int iCount = 0;
                    foreach (Parameter param in stack)
                    {
                        if (!param.IsMajoration)
                        {
                            continue;
                        }
                        // label
                        Label lbl = new Label();
                        lbl.Name     = string.Format("lbl_{0}", param.Name);
                        lbl.Text     = param.Name;
                        lbl.Location = new Point(
                            lblX + (iCount / 4) * offsetX
                            , lblY + (iCount % 4) * offsetY);
                        lbl.Size     = new Size(lbSizeX, lbSizeY);
                        lbl.TabIndex = ++tabIndex;
                        groupBoxMajorations.Controls.Add(lbl);
                        // text box
                        TextBox tb = new TextBox();
                        tb.Name     = string.Format("tb_{0}", param.Name);
                        tb.Text     = string.Format("{0:0.##}", stack.GetDoubleParameterValue(param.Name));
                        tb.Location = new Point(
                            lblX + (iCount / 4) * offsetX + lbl.Size.Width + 1
                            , lblY + (iCount % 4) * offsetY);
                        tb.Size     = new Size(50, 20);
                        tb.TabIndex = ++tabIndex;
                        groupBoxMajorations.Controls.Add(tb);
                        // increment count
                        ++iCount;
                    }
                }
                groupBoxMajorations.Visible = hasMajorations;
                return(true);
            }
            catch (Exception ex)
            {
                _log.Error(ex.ToString());
                return(false);
            }
        }
Exemplo n.º 8
0
        public Component LoadComponent(string filePath)
        {
            FileInfo file = new FileInfo(filePath);

            // Preliminary check
            // must exist
            if (!file.Exists)
                throw new PluginException(string.Format("File {0} does not exist. Cannot load Component.", filePath));
            // must be a dll file
            if (!file.Extension.Equals(".dll"))
                throw new PluginException(string.Format("File {0} is not a dll file. Cannot load Component.", filePath));

            //Create a new assembly from the plugin file we're adding..
            Assembly pluginAssembly = Assembly.LoadFrom(filePath);
            Component component = null;
            //Next we'll loop through all the Types found in the assembly
            foreach (Type pluginType in pluginAssembly.GetTypes())
            {
                if (pluginType.IsPublic) //Only look at public types
                {
                    if (!pluginType.IsAbstract)  //Only look at non-abstract types
                    {
                        //Gets a type object of the interface we need the plugins to match
                        Type typeInterface = pluginType.GetInterface("Pic.Plugin.IPlugin", true);

                        //Make sure the interface we want to use actually exists
                        if (typeInterface != null)
                        {
                            //Create a new available plugin since the type implements the IPlugin interface
                            IPlugin plugin = (IPlugin)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
                            if (null != plugin)
                            {
                                component = new Component(plugin);

                                //Set the Plugin's host to this class which inherited IPluginHost
                                plugin.Host = this;

                                //Call the initialization sub of the plugin
                                plugin.Initialize();

                                //cleanup a bit
                                plugin = null;
                            }
                        }
                        typeInterface = null; //Mr. Clean			
                    }
                }
            }
            pluginAssembly = null; //more cleanup

            // check that a component was actually created
            if (null == component)
                throw new Pic.Plugin.PluginException(string.Format("Failed to load valid component from existing file {0}", filePath));

            // insert component in cache for fast retrieval
            ComponentLoader.InsertInCache(component);

            return component;
        }
Exemplo n.º 9
0
 private static void InsertInCache(Component comp)
 {
     // verify if not already available
     if (null != GetFromCache(comp.Guid))
         return;
     // actually insert component
     _componentCache.Insert(0, comp);
     // clear exceding components
     while (_componentCache.Count > _cacheSize)
     {
         _parameterStackCache.Remove(_componentCache[_componentCache.Count - 1].Guid);
         _componentCache.RemoveAt(_componentCache.Count - 1);
     }
 }
Exemplo n.º 10
0
        void textBox_TextChanged(object sender, EventArgs e)
        {
            string filePath           = fileSelectCtrl.FileName;
            string fileExt            = System.IO.Path.GetExtension(filePath);
            bool   successfullyLoaded = false;

            if (System.IO.File.Exists(filePath) && (fileExt == ".dll"))
            {
                // try and load plugin
                try
                {
                    // load component
                    Pic.Plugin.Component component = null;
                    using (Pic.Plugin.ComponentLoader loader = new ComponentLoader())
                    {
                        loader.SearchMethod = new ComponentSearchMethodDB();
                        component           = loader.LoadComponent(filePath);
                    }
                    if (null == component)
                    {
                        return;
                    }
                    _componentGuid = component.Guid;

                    // generate image
                    Image image;
                    using (Pic.Plugin.Tools pluginTools = new Pic.Plugin.Tools(component, new ComponentSearchMethodDB()))
                    {
                        pluginTools.ShowCotations = false;
                        pluginTools.GenerateImage(pictureBoxFileView.Size, out image);
                    }
                    pictureBoxFileView.Image = image;

                    // get parameters
                    Pic.Plugin.ParameterStack stack = null;
                    stack = component.Parameters;
                    // fill name/description if empty
                    if (textBoxName.Text.Length == 0)
                    {
                        textBoxName.Text = component.Name;
                    }
                    if (textBoxDescription.Text.Length == 0)
                    {
                        textBoxDescription.Text = component.Description;
                    }

                    // insert majoration label and textbox controls
                    int lblX = 16, lblY = 41;
                    int offsetX = 100, offsetY = 29;
                    int tabIndex = comboBoxProfile.TabIndex;
                    groupBoxMajorations.Controls.Clear();
                    int iCount = 0;
                    for (int i = 1; i < 16; ++i)
                    {
                        string paramName = string.Format("m{0}", i);
                        if (!stack.HasParameter(paramName))
                        {
                            continue;
                        }

                        Label lbl = new Label();
                        lbl.Name     = string.Format("lbl_m{0}", i);
                        lbl.Text     = string.Format("m{0}", i);
                        lbl.Location = new Point(
                            lblX + (iCount / 4) * offsetX
                            , lblY + (iCount % 4) * offsetY);
                        lbl.Size     = new Size(24, 13);
                        lbl.TabIndex = ++tabIndex;
                        groupBoxMajorations.Controls.Add(lbl);

                        TextBox tb = new TextBox();
                        tb.Name     = string.Format("tb_m{0}", i);
                        tb.Text     = string.Format("{0:0.##}", stack.GetDoubleParameterValue(paramName));
                        tb.Location = new Point(
                            lblX + (iCount / 4) * offsetX + lbl.Size.Width + 1
                            , lblY + (iCount % 4) * offsetY);
                        tb.Size     = new Size(50, 20);
                        tb.TabIndex = ++tabIndex;
                        groupBoxMajorations.Controls.Add(tb);

                        ++iCount;
                    }

                    // Ok button enabled!
                    successfullyLoaded = true;
                }
                catch (Exception ex)
                {
                    Logger.Write(ex.ToString(), Category.General, Priority.Highest);
                }
            }

            // enable Ok button
            bnOk.Enabled = (textBoxName.TextLength != 0 && textBoxDescription.TextLength != 0 && successfullyLoaded);
        }
Exemplo n.º 11
0
        public FormEditMajorations(Guid compGuid, Profile currentProfile, ProfileLoader profileLoader)
        {
            InitializeComponent();

            if (compGuid == Guid.Empty)
            {
                throw new Exception("Invalid component Guid");
            }

            _compGuid      = compGuid;
            _profileLoader = profileLoader;

            if (!DesignMode)
            {
                // plugin viewer
                _pluginViewCtrl          = new PluginViewCtrl();
                _pluginViewCtrl.Size     = _pb.Size;
                _pluginViewCtrl.Location = _pb.Location;
                _pluginViewCtrl.Visible  = true;
                this.Controls.Add(_pluginViewCtrl);
                // hide
                _pb.Visible = false;
            }

            // fill combo box
            FillProfileComboBox(currentProfile.ToString());

            // get parameter stack
            PLMPackServiceClient client = WCFClientSingleton.Instance.Client;

            Pic.Plugin.ParameterStack stack = null;
            using (Pic.Plugin.ComponentLoader loader = new Pic.Plugin.ComponentLoader())
            {
                DCComponent          comp      = client.GetComponentByGuid(_compGuid);
                Pic.Plugin.Component component = loader.LoadComponent(
                    treeDiM.FileTransfer.FileTransferUtility.DownloadFile(comp.File.Guid, comp.File.Extension));
                stack = component.BuildParameterStack(null);
                // load component in pluginviewer
                _pluginViewCtrl.Component = component;
            }

            // insert majoration label and textbox controls
            int lblX = 20, lblY = 60;
            int offsetX = 110, offsetY = 29;
            int tabIndex = bnCancel.TabIndex;
            int iCount   = 0;

            foreach (Parameter param in stack.ParameterList)
            {
                // only shows majorations
                if (!param.IsMajoration)
                {
                    continue;
                }
                ParameterDouble paramDouble = param as ParameterDouble;
                // create Label control
                Label lbl = new Label();
                lbl.Name     = string.Format("lbl_{0}", param.Name);
                lbl.Text     = param.Name;
                lbl.Location = new Point(
                    lblX + (iCount / 5) * offsetX
                    , lblY + (iCount % 5) * offsetY);
                lbl.Size     = new Size(30, 13);
                lbl.TabIndex = ++tabIndex;
                this.Controls.Add(lbl);
                // create NumericUpDown control
                NumericUpDown nud = new NumericUpDown();
                nud.Name          = string.Format("nud_{0}", param.Name);
                nud.Increment     = 0.1M;
                nud.Minimum       = paramDouble.HasValueMin ? (decimal)paramDouble.ValueMin : -10000.0M;
                nud.Maximum       = paramDouble.HasValueMax ? (decimal)paramDouble.ValueMax : 10000.0M;
                nud.DecimalPlaces = 1;
                nud.Value         = (decimal)paramDouble.Value;
                nud.Location      = new Point(
                    lblX + (iCount / 5) * offsetX + lbl.Size.Width + 1
                    , lblY + (iCount % 5) * offsetY);
                nud.Size          = new Size(60, 20);
                nud.TabIndex      = ++tabIndex;
                nud.ValueChanged += new EventHandler(nudValueChanged);
                nud.GotFocus     += new EventHandler(nud_GotFocus);
                nud.Click        += new EventHandler(nud_GotFocus);
                this.Controls.Add(nud);

                ++iCount;
            }

            UpdateMajorationValues();
        }
Exemplo n.º 12
0
        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));
                }
            }
        }