예제 #1
0
 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 SaveMajorationValues()
        {
            Dictionary <string, double> dictMajo = new Dictionary <string, double>();

            foreach (Control ctrl in Controls)
            {
                NumericUpDown nud = ctrl as NumericUpDown;
                if (null == nud)
                {
                    continue;
                }
                if (nud.Name.Contains("nud_m"))
                {
                    dictMajo.Add(nud.Name.Substring(4), Convert.ToDouble(nud.Value));
                }
            }
            Pic.DAL.SQLite.PPDataContext db   = new Pic.DAL.SQLite.PPDataContext();
            Pic.DAL.SQLite.Component     comp = Pic.DAL.SQLite.Component.GetById(db, _componentId);
            comp.UpdateMajorationSet(db, _profile, dictMajo);

            // notify listeners
            _profileLoader.NotifyModifications();
        }
예제 #3
0
        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());
            }
        }
        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();
        }