예제 #1
0
        public Tools(Guid compGuid, IComponentSearchMethod searchMethod)
        {
            ComponentLoader loader = new ComponentLoader();

            loader.SearchMethod = searchMethod;
            Component           = loader.LoadComponent(compGuid);
        }
예제 #2
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);
        }
예제 #3
0
        public Component GetComponentFromGuid(Guid guid)
        {
            ComponentLoader loader = new ComponentLoader();

            DirectoryInfo dirInfo = new DirectoryInfo(_directoryPath);
            foreach (FileInfo fileInfo in dirInfo.GetFiles())
            {
                Component component = loader.LoadComponent(fileInfo.FullName);
                if (guid == component.Guid)
                    return component;
            }
            throw new PluginException(string.Format("Failed to load Component with Guid = {0} in directory {1}", guid.ToString(), _directoryPath));
        }
예제 #4
0
        public static bool Regenerate(string inputPath, string outputPath, Guid guid, string name, string description)
        {
            // load existing component
            IComponentSearchMethod searchMethod    = null;
            ComponentLoader        componentLoader = new ComponentLoader
            {
                SearchMethod = searchMethod
            };
            Component comp = componentLoader.LoadComponent(inputPath);

            // instantiate PluginGenerator
            PluginGenerator generator = new PluginGenerator
            {
                AssemblyCompany     = comp.Author,
                AssemblyDescription = comp.Description,
                AssemblyVersion     = comp.Version,
                DrawingName         = string.IsNullOrEmpty(name) ? comp.Name : name,
                DrawingDescription  = string.IsNullOrEmpty(description) ? comp.Description : description,
                Guid        = guid != Guid.Empty ? guid : Guid.NewGuid(),
                DrawingCode = comp.SourceCode
            };

            if (comp.HasEmbeddedThumbnail)
            {
                // get thumbnail image
                Bitmap bmp = comp.Thumbnail;
                // save thumbnail image as bmp
                string bitmapPath = Path.ChangeExtension(Path.GetTempFileName(), "bmp");
                bmp.Save(bitmapPath, System.Drawing.Imaging.ImageFormat.Bmp);
                // set thumbnail path in generator
                generator.ThumbnailPath = bitmapPath;
            }
            generator.OutputDirectory = Path.GetTempPath();
            CompilerResults res = generator.Build();

            if (res.Errors.Count > 0)
            {
                return(false);
            }

            // copy compiler output to new path
            File.Copy(
                res.PathToAssembly
                , outputPath
                , true /*overwrite*/
                );

            return(true);
        }
예제 #5
0
        public Component GetComponentFromGuid(Guid guid)
        {
            ComponentLoader loader = new ComponentLoader();

            DirectoryInfo dirInfo = new DirectoryInfo(_directoryPath);

            foreach (FileInfo fileInfo in dirInfo.GetFiles())
            {
                Component component = loader.LoadComponent(fileInfo.FullName);
                if (guid == component.Guid)
                {
                    return(component);
                }
            }
            throw new PluginException(string.Format("Failed to load Component with Guid = {0} in directory {1}", guid.ToString(), _directoryPath));
        }
예제 #6
0
        public byte[] GetAssemblyBytesFromGuid(Guid g)
        {
            ComponentLoader loader = new ComponentLoader();

            DirectoryInfo dirInfo = new DirectoryInfo(DirectoryPath);

            foreach (FileInfo fileInfo in dirInfo.GetFiles())
            {
                Component component = loader.LoadComponent(fileInfo.FullName);
                if (g == component.Guid)
                {
                    return(File.ReadAllBytes(fileInfo.FullName));
                }
            }
            throw new PluginException($"Failed to load Component with Guid = {g.ToString()} in directory {DirectoryPath}");
        }
예제 #7
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);
        }
예제 #8
0
        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;
            }
        }
예제 #9
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();
        }
예제 #10
0
        static void Main(string[] args)
        {
            XmlConfigurator.Configure();

            try
            {
                // instantiate factory
                PicFactory factory = new PicFactory();
                
                // load plugins
                PluginPathData configData = ConfigurationManager.GetSection("PluginSettings") as PluginPathData;
                if (null == configData)
                    throw new Exception("Failed to load valid PluinPathData object!");
                if (!Directory.Exists(configData.Path))
                    throw new Exception(string.Format("Directory \"{0}\" does not exist.", configData.Path));

                ComponentLoader loader = new ComponentLoader();
                DirectoryInfo dir = new DirectoryInfo(configData.Path);
                foreach (FileInfo fileInfo in dir.GetFiles())
                {
					try
					{
                        Component component = loader.LoadComponent(fileInfo.FullName);
                        if (null == component)
                            continue;
                        System.Console.WriteLine("Name = " + component.Name);
                        System.Console.WriteLine("Description = " + component.Description);
                        System.Console.WriteLine("Author = " + component.Author);
                        System.Console.WriteLine("Source code = " + component.SourceCode);
                        System.Console.WriteLine("------------");
                        // get thumbnail
                        if (component.HasEmbeddedThumbnail)
                        {
                            string thumbPath = Path.Combine(Path.GetTempPath(), component.Name + "_thumbnail.bmp");
                            System.Drawing.Bitmap thumbnail = component.Thumbnail;
                            thumbnail.Save(thumbPath);
                            if (launchPaint)
                                System.Diagnostics.Process.Start(Path.Combine(Environment.SystemDirectory, "mspaint.exe"), "\"" + thumbPath + "\"");
                        }

                        // generate entities
                        ParameterStack stack = component.BuildParameterStack(null);
						factory.Clear();
						component.CreateFactoryEntities(factory, stack);

						// get bounding box
						PicVisitorBoundingBox visitor = new PicVisitorBoundingBox();
						factory.ProcessVisitor(visitor);

						// save
						string filePath = Path.Combine(Path.GetTempPath(), component.Name + ".jpeg");
						PicGraphicsImage picImage = new PicGraphicsImage();
						picImage.ImageSize = new System.Drawing.Size(512, 512);
						Box2D box = visitor.Box;
						box.AddMargin(5);
						picImage.DrawingBox = box;
						factory.Draw(picImage);
						picImage.SaveAs(filePath);

                        if (launchPaint)
						    System.Diagnostics.Process.Start(Path.Combine(Environment.SystemDirectory, "mspaint.exe"), "\"" + filePath + "\"");
					}
					catch (System.Exception ex)
					{
                        _log.Debug(ex.Message);
					}
                }
            }
            catch (System.Exception ex)
            {
                _log.Error(ex.ToString());
            }
        }
예제 #11
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);
        }
예제 #12
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);
 }
예제 #13
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();
        }
예제 #14
0
        public static bool Regenerate(string inputPath, string outputPath, Guid guid, string name, string description)
        {
            // load existing component
            Pic.Plugin.IComponentSearchMethod searchMethod = null;
            ComponentLoader componentLoader = new ComponentLoader();
            componentLoader.SearchMethod = searchMethod;
            Component comp = componentLoader.LoadComponent(inputPath);

            // instantiate PluginGenerator
            PluginGenerator generator = new PluginGenerator();
            generator.AssemblyCompany = comp.Author;
            generator.AssemblyDescription = comp.Description;
            generator.AssemblyVersion = comp.Version;
            generator.DrawingName = string.IsNullOrEmpty(name) ? comp.Name : name;
            generator.DrawingDescription = string.IsNullOrEmpty(description) ? comp.Description : description;
            generator.Guid = guid != Guid.Empty ? guid : Guid.NewGuid();
            generator.DrawingCode = comp.SourceCode;
            if (comp.HasEmbeddedThumbnail)
            {
                // get thumbnail image
                Bitmap bmp = comp.Thumbnail;
                // save thumbnail image as bmp
                string bitmapPath = Path.ChangeExtension(Path.GetTempFileName(), "bmp");
                bmp.Save(bitmapPath, System.Drawing.Imaging.ImageFormat.Bmp);
                // set thumbnail path in generator
                generator.ThumbnailPath = bitmapPath;
            }
            generator.OutputDirectory = Path.GetTempPath();
            CompilerResults res = generator.Build();
            if (res.Errors.Count > 0)
                return false;

            // copy compiler output to new path
            File.Copy(
                res.PathToAssembly
                , outputPath
                , true /*overwrite*/
                );

            return true;
        }
예제 #15
0
        private void bnComponentRef_Click(object sender, EventArgs e)
        {
            try
            {
                string libraryPath = Path.Combine(_localPluginDirectory, "Library");
                if (!Directory.Exists(libraryPath))
                {
                    MessageBox.Show( string.Format("Directory {0} does not exist...", libraryPath) );
                    return;
                }

                PluginLibraryBrowser form = new PluginLibraryBrowser(libraryPath);
                if (DialogResult.OK == form.ShowDialog())
                {
                    // tools
                    ComponentLoader loader = new ComponentLoader();
                    loader.SearchMethod = new ComponentSearchDirectory(libraryPath);
                    Component component = loader.LoadComponent(form._guid);

                    Pic.Plugin.Tools tools = new Pic.Plugin.Tools(component, new ComponentSearchDirectory(libraryPath));
                    // insert generated code
                    string sCode = codeEditorCtrl.Text;
                    int startIndex = sCode.IndexOf("factory.AddEntities(fTemp, transform);");
                    sCode = sCode.Insert(startIndex, tools.GetInsertionCode());
                    codeEditorCtrl.Text = sCode;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
예제 #16
0
        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);
            }
        }
예제 #18
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);
 }
        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();
        }