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()); } }
static void Main(string[] args) { string folderDlls = ConfigurationManager.AppSettings.Get("FolderComponentFiles"); string folderSources = ConfigurationManager.AppSettings.Get("FolderComponentSources"); IComponentSearchMethod sm = new ComponentSearchDirectory(folderDlls); foreach (string filePath in Directory.GetFiles(folderDlls, "*.dll", SearchOption.AllDirectories)) { var sw = File.CreateText( Path.Combine( folderSources, Path.GetFileName(Path.ChangeExtension(filePath, "cs"))) ); using (ComponentLoader cl = new ComponentLoader() { SearchMethod = sm }) { var component = cl.LoadComponent(filePath); sw.WriteLine("// GUID : " + component.Guid.ToString()); sw.WriteLine("// Name : " + component.Name); sw.WriteLine("// Description : " + component.Description); sw.WriteLine("// Author : " + component.Author); sw.WriteLine("// Version : " + component.Version); sw.WriteLine("// Thumbnail : " + (component.HasEmbeddedThumbnail ? "true" : "false")); sw.WriteLine("// Date : " + DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss")); sw.WriteLine("// ### "); sw.Write(component.SourceCode); if (component.HasEmbeddedThumbnail) { // get thumbnail image var bmp = component.Thumbnail; // save thumbnail image as bmp string bitmapPath = Path.Combine(folderSources, Path.GetFileName(Path.ChangeExtension(filePath, "bmp"))); bmp.Save(bitmapPath, System.Drawing.Imaging.ImageFormat.Bmp); } } sw.Close(); Console.Write("."); } Console.WriteLine(); }
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()); } }
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); }
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 (ComponentLoader loader = new ComponentLoader()) { loader.SearchMethod = new ComponentSearchMethodDB(); component = loader.LoadComponent(filePath); } if (null == component) { return(false); } _componentGuid = component.Guid; // get parameters ParameterStack stack = null; stack = component.BuildParameterStack(null); // fill name/description if empty ComponentName = component.Name; ComponentDescription = component.Description; // build dict of double parameters ParamDefaultValues.Clear(); foreach (Parameter param in stack.ParameterList) { ParameterDouble paramDouble = param as ParameterDouble; if (null != paramDouble) { ParamDefaultValues[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); } }