/// <summary>
        /// Generate an image from plugin with default parameters
        /// </summary>
        /// <param name="size"></param>
        /// <param name="filter"></param>
        /// <param name="bmp"></param>
        public void GenerateImage(Size size, out Image bmp)
        {
            // check if plugin was instantiated
            if (null == Component)
            {
                throw new Exception("No valid plugin instance loaded!");
            }

            // instantiate factory
            PicFactory factory = new PicFactory();
            // generate entities
            ParameterStack stack = Component.BuildParameterStack(null);

            Component.CreateFactoryEntities(factory, stack);
            // apply any needed transformation
            if (ReflexionX)
            {
                factory.ProcessVisitor(new PicVisitorTransform(Transform2D.ReflectionX));
            }
            if (ReflexionY)
            {
                factory.ProcessVisitor(new PicVisitorTransform(Transform2D.ReflectionY));
            }
            // draw image
            PicGraphicsImage picImage = new PicGraphicsImage(size, Factory2D.Tools.BoundingBox(factory, 0.05));

            factory.Draw(picImage, ShowCotations ? PicFilter.FilterNone : !PicFilter.FilterCotation);
            bmp = picImage.Bitmap;
        }
        /// <summary>
        /// Generate an image from plugin with default parameters
        /// </summary>
        /// <param name="size"></param>
        /// <param name="filter"></param>
        /// <param name="bmp"></param>
        public void GenerateImage(Size size, out Image bmp)
        {
            // check if plugin was instantiated
            if (null == _component)
            {
                throw new Exception("No valid plugin instance loaded!");
            }

            // instantiate factory
            PicFactory factory = new PicFactory();
            // generate entities
            ParameterStack stack = _component.BuildParameterStack(null);

            _component.CreateFactoryEntities(factory, stack);
            // apply any needed transformation
            if (_reflexionX)
            {
                factory.ProcessVisitor(new PicVisitorTransform(Transform2D.ReflectionX));
            }
            if (_reflexionY)
            {
                factory.ProcessVisitor(new PicVisitorTransform(Transform2D.ReflectionY));
            }
            // get bounding box
            PicVisitorBoundingBox visitor = new PicVisitorBoundingBox();

            factory.ProcessVisitor(visitor);
            Box2D box = visitor.Box;

            box.AddMarginRatio(0.05);
            // draw image
            PicGraphicsImage picImage = new PicGraphicsImage(size, box);

            factory.Draw(picImage, _showCotations ? PicFilter.FilterNone : PicFilter.FilterCotation);

            bmp = picImage.Bitmap;
        }
        public string GetInsertionCode()
        {
            ParameterStack stackIn = Component.BuildParameterStack(null);
            string         csCode  = string.Empty;

            csCode += "\n";
            csCode += "\t\t{ // " + Component.Name + "\n";
            csCode += "\t\t\tIPlugin pluginIn = Host.GetPluginByGuid(\"" + Component.Guid.ToString() + "\");\n";
            csCode += "\t\t\tParameterStack stackIn = Host.GetInitializedParameterStack(pluginIn);\n";
            foreach (Parameter param in stackIn)
            {
                // double
                if (param is ParameterDouble paramDouble)
                {
                    csCode += "\t\t\tstackIn.SetDoubleParameter(\"" + paramDouble.Name + "\"," + paramDouble.ValueDefault.ToString() + ");\t\t// " + paramDouble.Description + "\n";
                }

                // bool
                if (param is ParameterBool paramBool)
                {
                    csCode += "\t\t\tstackIn.SetBoolParameter(\"" + paramBool.Name + "\"," + (paramBool.ValueDefault ? "true" : "false") + ");\t\t// " + paramBool.Description + "\n";
                }

                // int
                if (param is ParameterInt paramInt)
                {
                    csCode += "\t\t\tstackIn.SetIntParameter(\"" + paramInt.Name + "\"," + paramInt.ValueDefault.ToString() + ");\t\t// " + paramInt.Description + "\n";
                }

                // multi
                if (param is ParameterMulti paramMulti)
                {
                    csCode += "\t\t\tstackIn.SetMultiParameter(\"" + paramMulti.Name + "\"," + paramMulti.Value.ToString() + ");\t\t// " + paramMulti.Description + "\n";
                }
            }
            csCode += "\t\t\tbool reflectionX = false, reflectionY = false;\n";
            csCode += "\t\t\tTransform2D transfReflect = (reflectionY ? Transform2D.ReflectionY : Transform2D.Identity) * (reflectionX ? Transform2D.ReflectionX : Transform2D.Identity);\n";
            csCode += "\t\t\tpluginIn.CreateFactoryEntities(fTemp, stackIn,\n";
            csCode += "\t\t\t\t Transform2D.Translation(new Vector2D(0.0, 0.0))\n";
            csCode += "\t\t\t\t *Transform2D.Rotation(0.0)\n";
            csCode += "\t\t\t\t *transfReflect);\n";
            csCode += "\t\t}\n";
            return(csCode);
        }
        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);
            }
        }
Exemple #6
0
        public int GetMultiParameterDefaultValue(Guid guid, string name)
        {
            Component comp = GetComponentFromGuid(guid);

            return(comp.BuildParameterStack(null).GetMultiParameterValue(name));
        }
        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();
        }
Exemple #8
0
        public int GetIntParameterDefaultValue(string grpId, Guid g, string name)
        {
            Component comp = GetComponentFromGuid(g);

            return(comp.BuildParameterStack(null).GetIntParameterValue(name));
        }