Пример #1
0
 private void btDelete_Click(object sender, EventArgs e)
 {
     try
     {
         if (listViewProfile.SelectedIndices.Count > 0)
         {
             Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext();
             // delete selected cardboard profile
             int iSel = this.listViewProfile.SelectedIndices[0];
             Pic.DAL.SQLite.CardboardProfile[] cardboardProfiles = Pic.DAL.SQLite.CardboardProfile.GetAll(db);
             cardboardProfiles[iSel].Delete(db);
             // fill list view again
             FillListView();
             // select first item
             if (listViewProfile.Items.Count > 0)
             {
                 listViewProfile.Items[0].Selected = true;
             }
         }
     }
     catch (Exception ex)
     {
         Debug.Fail(ex.ToString());
         _log.Debug(ex.ToString());
     }
 }
Пример #2
0
 void bnModify_Click(object sender, System.EventArgs e)
 {
     try
     {
         if (this.listViewProfile.SelectedIndices.Count > 0)
         {
             int iSel = this.listViewProfile.SelectedIndices[0];
             Pic.DAL.SQLite.PPDataContext      db = new Pic.DAL.SQLite.PPDataContext();
             Pic.DAL.SQLite.CardboardProfile[] cardboardProfiles       = Pic.DAL.SQLite.CardboardProfile.GetAll(db);
             Pic.DAL.SQLite.CardboardProfile   currentCardboardProfile = cardboardProfiles[iSel];
             FormCreateCardboardProfile        dlg = new FormCreateCardboardProfile();
             dlg.ProfileName = currentCardboardProfile.Name;
             dlg.Code        = currentCardboardProfile.Code;
             dlg.Thickness   = currentCardboardProfile.Thickness;
             if (DialogResult.OK == dlg.ShowDialog())
             {
                 // set new values
                 currentCardboardProfile.Name      = dlg.ProfileName;
                 currentCardboardProfile.Code      = dlg.Code;
                 currentCardboardProfile.Thickness = dlg.Thickness;
                 // update database
                 currentCardboardProfile.Update(db);
                 // refill list view
                 FillListView();
                 // select current item
                 listViewProfile.Items[iSel].Selected = true;
             }
         }
     }
     catch (Exception ex)
     {
         Debug.Fail(ex.ToString());
         _log.Debug(ex.ToString());
     }
 }
Пример #3
0
 public static bool BackupBranch(List<string> nodePath, string zipFilePath, IProcessingCallback callback)
 {
     // remove zip path if it already exists
     if (System.IO.File.Exists(zipFilePath))
         System.IO.File.Delete(zipFilePath);
     // build destination database path
     DBDescriptor dbDescTo = DBDescriptor.CreateTemp();
     {
         // build data contexts
         PPDataContext dbFrom = new PPDataContext();
         using (PPDataContext dbTo = new PPDataContext(dbDescTo))
         {
             // copy format table
             CopyCardboardFormats(dbFrom, dbTo);
             // copy cardboard profiles
             CopyCardboardProfiles(dbFrom, dbTo);
             // copy document types
             CopyDocumentTypes(dbFrom, dbTo);
             // copy branch nodes recursively
             TreeNode nodeFrom = TreeNode.GetNodeByPath(dbFrom, null, nodePath, 0);
             TreeNode nodeTo = TreeNode.GetNodeByPath(dbTo, null, nodePath, 0); ;
             CopyTreeNodesRecursively(dbFrom, dbTo, nodeFrom, nodeTo, callback);
         }
         GC.Collect();
     }
     Thread.Sleep(1000);
     // archive temp database
     dbDescTo.Archive(zipFilePath, callback);
     return true;
 }
Пример #4
0
        public void BuildTree(TreeInterface treeImplementation)
        {
            // set up a simple configuration that logs on the console.
            XmlConfigurator.Configure();
            // initialize
            treeImplementation.Initialize();

            // check database file
            if (!System.IO.File.Exists(Pic.DAL.ApplicationConfiguration.CustomSection.DatabasePath))
                _log.Error(string.Format("Failed to load database with path {0}", Pic.DAL.ApplicationConfiguration.CustomSection.DatabasePath));
            else
                _log.Info(string.Format("Database found:{0}", Pic.DAL.ApplicationConfiguration.CustomSection.DatabasePath)); 

            // root nodes
            PPDataContext db = new PPDataContext();
            List<TreeNode> rootNodes = TreeNode.GetRootNodes(db);
            if (0 == rootNodes.Count)
            {
                treeImplementation.AskRootNode();
                rootNodes = TreeNode.GetRootNodes(db);
            }
            foreach (TreeNode node in rootNodes)
            {
                Object parentNodeObject = treeImplementation.InsertTreeNode(null, node);
                treeImplementation.InsertDummyNode(parentNodeObject);
            }
    
            db.Dispose();
            // finalize
            treeImplementation.Finish();
        }
        private void FillListView()
        {
            try
            {
                // clear all existing items
                listViewCardboardFormats.Items.Clear();

                Pic.DAL.SQLite.PPDataContext     db = new Pic.DAL.SQLite.PPDataContext();
                Pic.DAL.SQLite.CardboardFormat[] cardboardFormats = Pic.DAL.SQLite.CardboardFormat.GetAll(db);
                foreach (Pic.DAL.SQLite.CardboardFormat format in cardboardFormats)
                {
                    ListViewItem item = new ListViewItem();
                    item.Text = format.Name;
                    item.SubItems.Add(format.Description);
                    item.SubItems.Add(string.Format("{0}", format.Length));
                    item.SubItems.Add(string.Format("{0}", format.Width));
                    listViewCardboardFormats.Items.Add(item);
                }
            }
            catch (Exception ex)
            {
                Debug.Fail(ex.ToString());
                _log.Debug(ex.ToString());
            }
        }
        private void FillListView()
        {
            try
            {
                // clear all existing items
                listViewCardboardFormats.Items.Clear();

                Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext();
                Pic.DAL.SQLite.CardboardFormat[] cardboardFormats = Pic.DAL.SQLite.CardboardFormat.GetAll(db);
                foreach (Pic.DAL.SQLite.CardboardFormat format in cardboardFormats)
                {
                    ListViewItem item = new ListViewItem();
                    item.Text = format.Name;
                    item.SubItems.Add(format.Description);
                    item.SubItems.Add(string.Format("{0}", format.Length));
                    item.SubItems.Add(string.Format("{0}", format.Width));
                    listViewCardboardFormats.Items.Add(item);
                }
            }
            catch (Exception ex)
            {
                Debug.Fail(ex.ToString());
                _log.Debug(ex.ToString());
            }
        }
Пример #7
0
         public override void BuildCardboardProfile()
        {
            PPDataContext db = new PPDataContext();
            CardboardProfile[] profiles = CardboardProfile.GetAll(db);
            _cardboardProfiles.Clear();
            foreach (CardboardProfile dbProfile in profiles)
                _cardboardProfiles.Add(dbProfile.Name, dbProfile);

            _majorationList = null;
        }
Пример #8
0
        public static List<SearchResult> SearchTreeNodes(string searchText, bool searchNamesOnly)
        {
            List<SearchResult> results = new List<SearchResult>();

            Pic.DAL.SQLite.PPDataContext db = new SQLite.PPDataContext();
            List<Pic.DAL.SQLite.TreeNode> treeNodes = Pic.DAL.SQLite.TreeNode.SearchTreeNodeNames(db, searchText, searchNamesOnly, true);
            foreach (Pic.DAL.SQLite.TreeNode tn in treeNodes)
                results.Add(new SearchResult(tn.ID, tn.Name, tn.Description, tn.IsDocument));
            return results;
        }
Пример #9
0
 protected override Profile[] LoadProfiles()
 {
     PPDataContext db = new PPDataContext();
     CardboardProfile[] profiles = CardboardProfile.GetAll(db);
     List<Profile> listProfile = new List<Profile>();
     foreach (CardboardProfile dbProfile in profiles)
         listProfile.Add(new Profile(dbProfile.Name));
     if (listProfile.Count > 0)
         Selected = listProfile[0];
     return listProfile.ToArray();
 }
Пример #10
0
 public void ProcessVisitor(TreeNodeVisitor visitor)
 {
     // get data context
     PPDataContext db = new PPDataContext();
     // initialize
     visitor.Initialize(db);
     // get root node
     List<TreeNode> rootNodes = TreeNode.GetRootNodes(db);
     foreach (TreeNode tn in rootNodes)
         if (!tn.ProcessVisitor(db, visitor))
             break;
     // finilize
     visitor.Finalize(db);
 }
        public override bool Process(Pic.DAL.SQLite.PPDataContext db, TreeNode tn)
        {
            if (!tn.IsComponent)
            {
                return(true);
            }
            try
            {
                string filePath           = tn.Documents(db)[0].File.Path(db);
                Pic.Plugin.Component comp = _compLoader.LoadComponent(filePath);
                if (null != _callback && null != comp)
                {
                    _callback.Info(string.Format("Successfully loaded component {0}", tn.Name));
                }
                else
                {
                    _callback.Error(string.Format("Failed to load component {0}", tn.Name));
                }

                Pic.Plugin.ParameterStack stack = comp.BuildParameterStack(null);
                foreach (Pic.Plugin.Parameter param in stack)
                {
                    if (param.IsMajoration)
                    {
                        continue;
                    }
                    // only add parameter description
                    TryAndAddString(param.Description);
                    // ParameterMulti ?
                    Pic.Plugin.ParameterMulti paramMulti = param as Pic.Plugin.ParameterMulti;
                    if (null != paramMulti)
                    {
                        foreach (string sText in paramMulti.DisplayList)
                        {
                            TryAndAddString(sText);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (null != _callback)
                {
                    _callback.Error(ex.Message);
                }
            }
            return(true);
        }
        public static void ClearDatabase(IProcessingCallback callback)
        {
            string databaseFile = ApplicationConfiguration.CustomSection.DatabasePath;

            // other files
            Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext();
            // get root node
            List <TreeNode> rootNodes = TreeNode.GetRootNodes(db);
            TreeNode        rootNode  = rootNodes[0];

            // delete all childs of root node
            foreach (Pic.DAL.SQLite.TreeNode tn in rootNode.Childrens(db))
            {
                tn.Delete(db, true, callback);
            }
            db.SubmitChanges();
        }
Пример #13
0
 protected override Dictionary<string, double> LoadMajorationList()
 {
     if (null == Selected || null == _comp)
         return new Dictionary<string, double>();
     if (null == _majorationList)
     {
         PPDataContext db = new PPDataContext();
         _majorationList = Pic.DAL.SQLite.Component.GetDefaultMajorations(
             db,
             _comp.ID,
             _cardboardProfiles[Selected.ToString()]
             // rounding to be applied while building majoration dictionary
             , Pic.DAL.SQLite.Component.IntToMajoRounding(Properties.Settings.Default.MajorationRounding)
             );
     }
     return _majorationList;
 }
 private void btCreate_Click(object sender, EventArgs e)
 {
     try
     {
         FormCreateCardboardFormat form = new FormCreateCardboardFormat();
         if (DialogResult.OK == form.ShowDialog())
         {
             Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext();
             Pic.DAL.SQLite.CardboardFormat.CreateNew(db, form.FormatName, form.Description, form.FormatWidth, form.FormatHeight);
             FillListView();
         }
     }
     catch (Exception ex)
     {
         Debug.Fail(ex.ToString());
         _log.Debug(ex.ToString());
     }
 }
Пример #15
0
 private void listViewProfile_SelectedIndexChanged(object sender, System.EventArgs e)
 {
     try
     {
         if (this.listViewProfile.SelectedIndices.Count > 0)
         {
             int iSel = this.listViewProfile.SelectedIndices[0];
             PPDataContext db = new PPDataContext();
             CardboardProfile[] cardboardProfiles = CardboardProfile.GetAll(db);
             this.btDelete.Enabled = !cardboardProfiles[iSel].HasMajorationSets;
         }
     }
     catch (Exception ex)
     {
         Debug.Fail(ex.ToString());
         _log.Debug(ex.ToString());
     }
 }
Пример #16
0
 private void btCreate_Click(object sender, EventArgs e)
 {
     try
     {
         FormCreateCardboardProfile dlg = new FormCreateCardboardProfile();
         if (DialogResult.OK == dlg.ShowDialog())
         {
             Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext();
             Pic.DAL.SQLite.CardboardProfile.CreateNew(db, dlg.ProfileName, dlg.Code, dlg.Thickness);
             FillListView();
         }
     }
     catch (Exception ex)
     {
         Debug.Fail(ex.ToString());
         _log.Debug(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();
        }
Пример #18
0
        private void FillListView()
        {
            try
            {
                // clear all existing items
                listViewProfile.Items.Clear();

                PPDataContext db = new PPDataContext();
                CardboardProfile[] cardboardProfiles = CardboardProfile.GetAll(db);
                foreach (Pic.DAL.SQLite.CardboardProfile profile in cardboardProfiles)
                {
                    ListViewItem item = new ListViewItem();
                    item.Text = profile.Name;
                    item.SubItems.Add(profile.Code);
                    item.SubItems.Add(string.Format("{0}",profile.Thickness));
                    listViewProfile.Items.Add(item);
                }
            }
            catch (Exception ex)
            {
                Debug.Fail(ex.ToString());
                _log.Debug(ex.ToString());
            }
        }
Пример #19
0
 public ComponentLoaderControl()
 {
     InitializeComponent();
     if (this.DesignMode)  return;   // exit when in design mode 
     try
     {
         // initialize profile combo box
         comboBoxProfile.Items.Clear();
         PPDataContext db = new PPDataContext();
         List<CardboardProfile> listProfile = new List<CardboardProfile>(CardboardProfile.GetAll(db));
         foreach (CardboardProfile profile in listProfile)
             comboBoxProfile.Items.Add(profile);
         if (comboBoxProfile.Items.Count > 0)
             comboBoxProfile.SelectedIndex = 0;
         // ComponentSearchMethodDB
         pluginViewCtrl.SearchMethod = new ComponentSearchMethodDB();
         // Localizer
         pluginViewCtrl.Localizer = LocalizerImpl.Instance;
     }
     catch (Exception ex)
     {
         _log.Error(string.Format("Exception: {0}", ex.ToString()));
     }
 }
Пример #20
0
        private void OnSelectionChanged(object sender, NodeEventArgs e, string name)
        {

            // changed caption
            Text = Application.ProductName + " - " + name;
            UpdateTextPosition(null, null);

            // show/hide controls
            _startPageCtrl.Visible = false;
            _downloadPageCtrl.Visible = false;
            _branchViewCtrl.Visible = (NodeTag.NodeType.NT_TREENODE == e.Type);
            _pluginViewCtrl.Visible = false;
            _factoryViewCtrl.Visible = false;
            _webBrowser4PDF.Visible = false;
            if (NodeTag.NodeType.NT_DOCUMENT == e.Type)
            {
                PPDataContext db = new PPDataContext();
                Pic.DAL.SQLite.TreeNode treeNode = Pic.DAL.SQLite.TreeNode.GetById(db, e.Node);
                Document doc = treeNode.Documents(db)[0];

                DocumentName = doc.Name;

                // select document handler depending on document type
                string docTypeName = doc.DocumentType.Name;
                string filePath = doc.File.Path(db);

                DocumentPath = filePath;

                if (string.Equals("Parametric Component", docTypeName, StringComparison.CurrentCultureIgnoreCase))
                {
                    if (doc.Components.Count > 0)
                        _profileLoaderImpl.Component = doc.Components[0];
                    LoadParametricComponent(filePath);
                }
                else if (string.Equals("treeDim des", docTypeName, StringComparison.CurrentCultureIgnoreCase))
                    LoadPicadorFile(filePath, "des");
                else if (string.Equals("autodesk dxf", docTypeName, StringComparison.CurrentCultureIgnoreCase))
                    LoadPicadorFile(filePath, "dxf");
                else if (string.Equals("Adobe Acrobat", docTypeName, StringComparison.CurrentCultureIgnoreCase))
                    LoadPdfWithActiveX(filePath);
                else if (string.Equals("raster image", docTypeName, StringComparison.CurrentCultureIgnoreCase))
                    LoadImageFile(filePath);
                else
                    LoadUnknownFileFormat(filePath);
            }
            // update toolbar
            UpdateToolCommands();
            // select treeview control
            _treeViewCtrl.Select();
        }
Пример #21
0
        public static void ClearExistingDocumentsRecursively(PPDataContext dbFrom, TreeNode nodeFrom, TreeNode nodeTo, IProcessingCallback callback)
        {
            if (null != callback && !nodeFrom.IsDocument)
                callback.Info(string.Format("Processing branch {0}", nodeFrom.Name));

            // get thumbnail path of node to insert
            string thumbnailPath = nodeFrom.Thumbnail.File.Path(dbFrom);

            // handle childrens
            foreach (TreeNode childFrom in nodeFrom.Childrens(dbFrom))
            {
                // get thumbnail of node to insert
                thumbnailPath = childFrom.Thumbnail.File.Path(dbFrom);

                if (childFrom.IsDocument)
                {
                    Document docFrom = childFrom.Documents(dbFrom)[0];
                    string docTypeName = docFrom.DocumentType.Name;

                    // delete existing document
                    // will be using new data context each time a tree node is deleted
                    // in order to avoid exceptions claiming that there is a foreign key violation
                    using (PPDataContext dbTo0 = new PPDataContext())
                    {
                        if (nodeTo.HasChild(dbTo0, childFrom.Name))
                        {
                            string documentName = childFrom.Name;
                            TreeNode childTo = nodeTo.GetChild(dbTo0, documentName);
                            if (null != childTo && childTo.IsDocument)
                            {
                                try
                                {
                                    if (null != callback) callback.Info(string.Format("Deleting tree node {0} ...", childTo.Name));
                                    childTo.Delete(dbTo0, true, callback);
                                    dbTo0.SubmitChanges();
                                }
                                catch (Exception ex)
                                {
                                    callback.Error(string.Format("Deleting document {0} failed with exception {1}", documentName, ex.Message));
                                }
                            }
                        }
                    }
                }
                else // childFrom.IsDocument
                {
                    using (PPDataContext dbTo2 = new PPDataContext())
                    {
                        TreeNode childTo = null;
                        if (nodeTo.HasChild(dbTo2, childFrom.Name))
                        {
                            if (null != callback) callback.Info(string.Format("Branch {0} already exists.Skipping...", childFrom.Name));
                            childTo = nodeTo.GetChild(dbTo2, childFrom.Name);
                            ClearExistingDocumentsRecursively(dbFrom, childFrom, childTo, callback);
                        }
                    }
                }
            }
        }
Пример #22
0
 /// <summary>
 /// restores a backup database : callback version
 /// </summary>
 public static bool Restore(string zipFilePath, IProcessingCallback callback)
 {
     try
     {
         // clear existing directories
         DBDescriptor dbDescTo = DBDescriptor.Current;
         if (!dbDescTo.Clear())
         {
             if (null != callback)
                 callback.Error("Failed to clear current database!");
             return false;
         }
         // extract new database
         DBDescriptor dbDescFrom = DBDescriptor.CreateTempFromArchive(zipFilePath, callback);
         // build data contexts
         PPDataContext dbFrom = new PPDataContext(dbDescFrom);
         PPDataContext dbTo = new PPDataContext(dbDescTo);
         // copy format table
         CopyCardboardFormats(dbFrom, dbTo);
         // copy cardboard profiles
         CopyCardboardProfiles(dbFrom, dbTo);
         // copy document types
         CopyDocumentTypes(dbFrom, dbTo);
         // copy branch nodes recursively
         TreeNode nodeFrom = TreeNode.GetRootNodes(dbFrom)[0];
         TreeNode nodeTo = TreeNode.GetRootNodes(dbTo)[0]; ;
         CopyTreeNodesRecursively(dbFrom, dbTo, nodeFrom, nodeTo, callback);
         GC.Collect();
     }
     catch (Exception ex)
     {
         if (null != callback)
             callback.Error(ex.Message);
         _log.Error(ex.ToString());
         return false;
     }
     return true;
 }
 public override void Initialize(PPDataContext db)
 {
 }
Пример #24
0
        static void Main(string[] args)
        {
            // set up a simple configuration that logs on the console.
            XmlConfigurator.Configure();

            bool deleteAll = true;
            try
            {
                // ================================ CardboardFormat
                try
                {
                    PPDataContext db = new PPDataContext();
                    CardboardFormat cbf1 = CardboardFormat.CreateNew(db, "F1", "Format 1", 1000.0f, 1000.0f);
                    _log.Info(string.Format("Created new cardboard format with Id = {0}", cbf1.ID));
                    CardboardFormat cbf2 = CardboardFormat.CreateNew(db, "F2", "Format 2", 2000.0f, 2000.0f);
                    _log.Info(string.Format("Created new cardboard format with Id = {0}", cbf2.ID));
                    CardboardFormat cbf3 = CardboardFormat.CreateNew(db, "F3", "Format 3", 3000.0f, 3000.0f);
                    _log.Info(string.Format("Created new cardboard format with Id = {0}", cbf3.ID));

                    foreach (CardboardFormat cbf in CardboardFormat.GetAll(db))
                        _log.Info(cbf.ToString());
                }
                catch (System.Exception ex) { _log.Error(ex.Message); }
                // ================================
                // ================================ CardboardProfile
                // get list of existing cardboards
                try
                {
                    PPDataContext db = new PPDataContext();
                    IEnumerable<CardboardProfile> profiles = from cp in db.CardboardProfiles select cp;
                    foreach (CardboardProfile cbp in profiles)
                        _log.Info(cbp.ToString());
                    db.Dispose();
                }
                catch (System.Exception ex) { _log.Error(ex.Message); }
                // add first CardboardProfile ->expected to throw exception if already exists
                try
                {
                    PPDataContext db = new PPDataContext();
                    CardboardProfile cbprofile1 = CardboardProfile.CreateNew(db, "Profile1", "P1", 0.1f);
                    _log.Info(string.Format("created cardboard profile with Id = {0}", cbprofile1.ID));
                    db.Dispose();
                }
                catch (ExceptionDAL ex) { _log.Debug(ex.Message); }
                catch (Exception ex) { _log.Error(ex.Message); }
                // add second CardboardProfile
                try
                {
                    PPDataContext db = new PPDataContext();
                    CardboardProfile cbprofile2 = CardboardProfile.CreateNew(db, "Profile2", "P2", 0.2f);
                    _log.Info(string.Format("created cardboard profile with Id = {0}", cbprofile2.ID));
                    db.Dispose();
                }
                catch (ExceptionDAL ex) { _log.Debug(ex.Message); }
                catch (Exception ex) { _log.Error(ex.Message); }
                // delete CardboardProfile
                {
                    PPDataContext db = new PPDataContext();
                    CardboardProfile profile = db.CardboardProfiles.Single<CardboardProfile>(cp => cp.Code == "P2");
                    db.CardboardProfiles.DeleteOnSubmit(profile);
                    db.SubmitChanges();
                }
                // ================================ 
                // ================================ DocumentType
                // add new DocumentType
                try
                {
                    PPDataContext db = new PPDataContext();
                    DocumentType docType = DocumentType.CreateNew(db, "Parametric component", "Parametric component to be used in PicParam", "PicParam");
                    _log.Info(string.Format("created document type with Id = {0}", docType.ID));
                    db.Dispose();
                }
                catch (ExceptionDAL ex) { _log.Debug(ex.Message); }
                catch (Exception ex) { _log.Error(ex.Message); }

                // ================================
                // ================================ TreeNode
                // create new rootNodes
                string imageFilePath = string.Empty;
                try
                {
                    PPDataContext db = new PPDataContext();
                    TreeNode rootNode1 = TreeNode.CreateNew(db, "Parametric components", "Parametric component to be used in PicParam", imageFilePath);
                    db.Dispose();
                }
                catch (ExceptionDAL ex) { _log.Debug(ex.Message); }
                catch (Exception ex) { _log.Error(ex.Message); }

                try
                {
                    PPDataContext db = new PPDataContext();
                    TreeNode rootNode2 = TreeNode.CreateNew(db, "Drawing files", "Either PicGEOM or Autocad dxf files", imageFilePath);
                }
                catch (ExceptionDAL ex) { _log.Debug(ex.Message); }
                catch (Exception ex) { _log.Error(ex.Message); }

                // create new child treenode
                try
                {
                    PPDataContext db = new PPDataContext();
                    TreeNode parentNode = TreeNode.GetRootNodes(db)[0];
                    TreeNode childNode1 = parentNode.CreateChild(db, "Node1", "Node1", imageFilePath);
                    db.Dispose();
                }
                catch (ExceptionDAL ex) { _log.Debug(ex.Message); }
                catch (Exception ex) { _log.Error(ex.Message); }

                Guid guidComponent = Guid.Empty;

                // ================================
                // ================================ Component
                // create new child node + component
                try
                {
                    PPDataContext db = new PPDataContext();
                    TreeNode parentNode = TreeNode.GetRootNodes(db)[0];
                    TreeNode childNode1 = parentNode.Childrens(db)[0];
                    TreeNode childNode2 = null;
                    try
                    {
                        childNode2 = childNode1.CreateChild(db, "Node2", "Node2", imageFilePath);
                        _log.Info(string.Format("successfully created Node with ID = {0}", childNode2.ID));
                    }
                    catch (ExceptionDAL ex) { _log.Debug(ex.Message); }
                    if (null == childNode2)
                        childNode2 = childNode1.Childrens(db)[0];
                    // insert component
                    string filePath = @"K:\Codesion\PicSharp\Pic.Plugin.SimpleRectangle\bin\Release\Pic.Plugin.SimpleRectangle.dll";
                    Component component = childNode2.InsertComponent(db, filePath, Guid.NewGuid(), "Rounded rectangle", "Rounded rectangle", "");
                    guidComponent = component.Guid;
                    // set majorations
                    Dictionary<string, double> majorations = new Dictionary<string, double>();
                    majorations.Add("m1", 1.0);
                    majorations.Add("m2", 2.0);
                    component.InsertNewMajorationSet(db, "Profile1", majorations);
                    db.Dispose();
                }
                catch (ExceptionDAL ex) { _log.Debug(ex.Message); }
                catch (Exception ex) { _log.Error(ex.Message); }
                // ================================
                // ================================ Document
                // create documents
                try
                {
                    PPDataContext db = new PPDataContext();
                    TreeNode parentNode = TreeNode.GetRootNodes(db)[0];
                    string filePath = @"K:\SVN Projects\PicSharp\Pic.Plugin.SimpleRectangle\bin\Release\Pic.Plugin.SimpleRectangle.dll";
                    parentNode.InsertDocument(db, filePath, "Rounded rectangle", "Rounded Rectangle", "Parametric component", "");
                    db.Dispose();
                }
                catch (ExceptionDAL ex) { _log.Debug(ex.Message); }
                catch (Exception ex) { _log.Error(ex.Message); }

                // ================================
                // ================================ TreeBuilder
                // show document tree
                TreeBuilder builder = new TreeBuilder();
                TreeConsole treeConsole = new TreeConsole();
                builder.BuildTree(treeConsole);
                // ================================
                // ================================
                try
                {
                    // retrieve component
                    PPDataContext db = new PPDataContext();
                    Component component = Component.GetByGuid(db, guidComponent);
                    if (null == component)
                        throw new ExceptionDAL(string.Format("No component with Guid = {0}", guidComponent));

                    CardboardProfile profile3 = CardboardProfile.GetByName(db, "P3");
                    if (null == profile3)
                        profile3 = CardboardProfile.CreateNew(db, "P3", "P3", 3.0f);
                    Dictionary<string, double> defaultMajorations = Component.GetDefaultMajorations(db, component.ID, profile3, Component.MajoRounding.ROUDING_FIRSTDECIMALNEAREST);
                    component.InsertNewMajorationSet(db, profile3.Name, defaultMajorations);
                    defaultMajorations["m1"] = 100.0;
                    defaultMajorations["m2"] = 100.0;
                    component.UpdateMajorationSet(db, profile3, defaultMajorations);
                    db.Dispose();
                }
                catch (ExceptionDAL ex) { _log.Debug(ex.Message); }
                catch (Exception ex) { _log.Error(ex.Message); }
                // ================================
                // ================================ TreeBuilder
                // show document tree
                builder.BuildTree(treeConsole);
                // ================================
                // ================================ Delete components / documents
                try
                {
                    if (deleteAll)
                    {
                        PPDataContext db = new PPDataContext();
                        Component.DeleteAll(db);
                        _log.Info("Successfully deleted Components...");
                        Document.DeleteAll(db);
                        _log.Info("Successfully deleted Documents...");
                        DocumentType.DeleteAll(db);
                        _log.Info("Successfully deleted DocumentTypes...");
                        TreeNode.DeleteAll(db);
                        _log.Info("Successfully deleted TreeNodes...");
                        CardboardProfile.DeleteAll(db);
                        _log.Info("Successfully deleted CardboardProfile...");
                        CardboardFormat.DeleteAll(db);
                        _log.Info("Successfully deleted Cardboard formats...");
                        db.Dispose();
                    }
                }
                catch (ExceptionDAL ex) { _log.Debug(ex.Message); }
                catch (System.Exception ex) { _log.Error(ex.Message); }
                // ================================
                // ================================ TreeBuilder
                // show document tree
                builder.BuildTree(treeConsole);
                // ================================
            }
            catch (System.Exception ex)
            {
                _log.Error(ex.ToString());
            }
        }
 public override void Finalize(PPDataContext db)
 {
     // force saving file 
     // (the file might be opened just after collecting parameter strings)
     LocalizerImpl.Instance.Save();
 }
Пример #26
0
 private void btCreate_Click(object sender, EventArgs e)
 {
     try
     {
         FormCreateCardboardProfile dlg = new FormCreateCardboardProfile();
         if (DialogResult.OK == dlg.ShowDialog())
         {
             Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext();
             Pic.DAL.SQLite.CardboardProfile.CreateNew(db, dlg.ProfileName, dlg.Code, dlg.Thickness);
             FillListView();
         }
     }
     catch (Exception ex)
     {
         Debug.Fail(ex.ToString());
         _log.Debug(ex.ToString());
     }
 }
Пример #27
0
 void bnModify_Click(object sender, System.EventArgs e)
 {
     try
     {
         if (this.listViewProfile.SelectedIndices.Count > 0)
         {
             int iSel = this.listViewProfile.SelectedIndices[0];
             Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext();
             Pic.DAL.SQLite.CardboardProfile[] cardboardProfiles = Pic.DAL.SQLite.CardboardProfile.GetAll(db);
             Pic.DAL.SQLite.CardboardProfile currentCardboardProfile = cardboardProfiles[iSel];
             FormCreateCardboardProfile dlg = new FormCreateCardboardProfile();
             dlg.ProfileName = currentCardboardProfile.Name;
             dlg.Code = currentCardboardProfile.Code;
             dlg.Thickness = currentCardboardProfile.Thickness;
             if (DialogResult.OK == dlg.ShowDialog())
             {
                 // set new values
                 currentCardboardProfile.Name = dlg.ProfileName;
                 currentCardboardProfile.Code = dlg.Code;
                 currentCardboardProfile.Thickness = dlg.Thickness;
                 // update database
                 currentCardboardProfile.Update(db);
                 // refill list view
                 FillListView();
                 // select current item
                 listViewProfile.Items[iSel].Selected = true;
             }
         }
     }
     catch (Exception ex)
     {
         Debug.Fail(ex.ToString());
         _log.Debug(ex.ToString());
     }
 }
Пример #28
0
 private void toolStripEditComponentCode_Click(object sender, EventArgs e)
 {
     try
     {
         NodeTag nodeTag = _treeViewCtrl.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);
         if (null == treeNode) return;
         Pic.DAL.SQLite.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());
     }
 }
Пример #29
0
 private void btCreate_Click(object sender, EventArgs e)
 {
     try
     {
         FormCreateCardboardFormat form = new FormCreateCardboardFormat();
         if (DialogResult.OK == form.ShowDialog())
         {
             Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext();
             Pic.DAL.SQLite.CardboardFormat.CreateNew(db, form.FormatName, form.Description, form.FormatWidth, form.FormatHeight);
             FillListView();
         }
     }
     catch (Exception ex)
     {
         Debug.Fail(ex.ToString());
         _log.Debug(ex.ToString());
     }
 }
Пример #30
0
 private void FillProfileComboBox(string selectedProfileName)
 {
     // initialize profile combo box
     comboBoxProfile.Items.Clear();
     PPDataContext db = new PPDataContext();
     CardboardProfile[] profiles = CardboardProfile.GetAll(db);
     foreach (CardboardProfile profile in profiles)
     {
         comboBoxProfile.Items.Add(profile);
         if (profile.Name == selectedProfileName)
             comboBoxProfile.SelectedItem = profile;
     }
     _profile = comboBoxProfile.SelectedItem as CardboardProfile;
 }
Пример #31
0
        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();
        }
Пример #32
0
        private void UpdateMajorationValues()
        {
            // retrieve majoration from database
            PPDataContext db = new PPDataContext();
            Dictionary<string, double> dictMajo = Pic.DAL.SQLite.Component.GetDefaultMajorations(
                db
                , _componentId
                , _profile
                // rounding to be applied while building majoration dictionary
                , Pic.DAL.SQLite.Component.IntToMajoRounding(Properties.Settings.Default.MajorationRounding)
                );
            // update nud control values
            foreach (Control ctrl in Controls)
            {
                NumericUpDown nud = ctrl as NumericUpDown;
                if ( null == nud || !nud.Name.StartsWith("nud_"))
                    continue;
                if (dictMajo.ContainsKey(nud.Name.Substring(4)))
                {
                    decimal v = (decimal)dictMajo[nud.Name.Substring(4)];
                    if (nud.Minimum < v && v < nud.Maximum)     
                        nud.Value = v;
                }

                nud.MouseEnter += new EventHandler(nud_MouseEnter);
                nud.ValueChanged += new EventHandler(nud_ValueChanged);
            }
            _dirty = false;
        }
Пример #33
0
        Pic.DAL.SQLite.Document GetSelectedDocument()
        {
            NodeTag nodeTag = _treeViewCtrl.SelectedNode.Tag as NodeTag;
            if (null == nodeTag)
                return null;

            PPDataContext db = new PPDataContext();
            Pic.DAL.SQLite.TreeNode treeNode = Pic.DAL.SQLite.TreeNode.GetById(db, nodeTag.TreeNode);
            if (null == treeNode)
                return null;    // failed to retrieve valid document
            if (!treeNode.IsDocument)
                return null;    // not a document
            return treeNode.Documents(db)[0];
        }
Пример #34
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();
        }
Пример #35
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 = _treeViewCtrl.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; }
            List<string> filePathes = new List<string>();
            foreach (Document d in des3Docs)
                filePathes.Add(d.File.Path(db));

            SaveFileDialog fd = new SaveFileDialog();
            fd.Filter = "pdf files (*.pdf)|*.pdf|All files (*.*)|*.*";
            fd.FilterIndex = 0;
            fd.DefaultExt = "pdf";
            fd.FileName = treeNode.Name + ".pdf";

            if (DialogResult.OK == fd.ShowDialog())
            {
                string pdfFile = fd.FileName;
                string desFile = Path.ChangeExtension(pdfFile, "des");
                string des3File = Path.ChangeExtension(pdfFile, "des3");
                string xmlFile = Path.ChangeExtension(pdfFile, "xml");
                string u3dFile = Path.ChangeExtension(pdfFile, "u3d");
                string currentDir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                string defaultPdfTemplate = Path.Combine(currentDir, "DefaultTemplate.pdf");

                // 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 = defaultPdfTemplate, type = Pic3DExporter.pathType.FILE });
                    job.Pathes.Add(new Pic3DExporter.PathItem() { pathID = "FID-2", path = desFile, type = Pic3DExporter.pathType.FILE });
                    job.Pathes.Add(new Pic3DExporter.PathItem() { pathID = "FID-3", path = des3File, type = Pic3DExporter.pathType.FILE });
                    job.Pathes.Add(new Pic3DExporter.PathItem() { pathID = "FID-4", path = u3dFile, type = Pic3DExporter.pathType.FILE });
                    job.Pathes.Add(new Pic3DExporter.PathItem() { pathID = "FID-5", path = pdfFile, type = Pic3DExporter.pathType.FILE });

                    int fid = 5;
                    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-2", role = "input des", deleteAfterUsing = false });
                    task_2D_to_DES3.Outputs.Add(new Pic3DExporter.PathRef() { pathID = "FID-3", 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 = 5;
                    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);
                    // DES3 -> U3D
                    Pic3DExporter.task_DES3_TO_U3D task_DES3_to_U3D = new Pic3DExporter.task_DES3_TO_U3D() { id = "TID-2" };
                    task_DES3_to_U3D.Dependencies = "TID-1";
                    task_DES3_to_U3D.Inputs.Add(new Pic3DExporter.PathRef() { pathID = "FID-3", role = "input des3", deleteAfterUsing = false });
                    task_DES3_to_U3D.Outputs.Add(new Pic3DExporter.PathRef() { pathID = "FID-4", role = "output u3d", deleteAfterUsing = false });
                    task_DES3_to_U3D.Parameters.Material.opacitySpecified = true;
                    task_DES3_to_U3D.Parameters.Material.opacity = 1.0F;
                    task_DES3_to_U3D.Parameters.Material.reflectivitySpecified = true;
                    task_DES3_to_U3D.Parameters.Material.reflectivity = 0.0F;
                    task_DES3_to_U3D.Parameters.Qualities.meshDefaultSpecified = true;
                    task_DES3_to_U3D.Parameters.Qualities.meshDefault = 1000;
                    task_DES3_to_U3D.Parameters.Qualities.meshPositionSpecified = true;
                    task_DES3_to_U3D.Parameters.Qualities.meshPosition = 1000;
                    task_DES3_to_U3D.Parameters.Qualities.shaderQualitySpecified = true;
                    task_DES3_to_U3D.Parameters.Qualities.shaderQuality = 1000;
                    job.Tasks.Add(task_DES3_to_U3D);
                    // U3D -> PDF
                    float[] mat = { -0.768655F, -0.632503F, 0.0954455F, -0.220844F, 0.402444F, 0.888407F, -0.600332F, 0.661799F, -0.449025F, 1805.8F, -1990.7F, 1350.67F };
                    List<float> viewMatrix = new List<float>(mat);
                    float[] bColor = { 1.0f, 1.0f, 1.0f };
                    List<float> backColor = new List<float>(bColor);

                    Pic3DExporter.task_U3D_TO_PDF task_U3D_to_PDF = new Pic3DExporter.task_U3D_TO_PDF() { id = "TID-3" };
                    task_U3D_to_PDF.Dependencies = "TID-2";
                    task_U3D_to_PDF.Inputs.Add(new Pic3DExporter.PathRef() { pathID = "FID-4", role = "input u3d", deleteAfterUsing = false });
                    task_U3D_to_PDF.Inputs.Add(new Pic3DExporter.PathRef() { pathID = "FID-1", role = "pdf template", deleteAfterUsing = false });
                    task_U3D_to_PDF.Outputs.Add(new Pic3DExporter.PathRef() { pathID = "FID-5", role = "output pdf", deleteAfterUsing = false });
                    task_U3D_to_PDF.pdfAnnotation.PageLayout.buttonPositionsSpecified = true;
                    task_U3D_to_PDF.pdfAnnotation.PageLayout.buttonPositions = Pic3DExporter.RelativePosition.LEFT;
                    task_U3D_to_PDF.pdfAnnotation.PageLayout.pageNumberSpecified = true;
                    task_U3D_to_PDF.pdfAnnotation.PageLayout.pageNumber = 1;
                    task_U3D_to_PDF.pdfAnnotation.PageLayout.position.Add(40);
                    task_U3D_to_PDF.pdfAnnotation.PageLayout.position.Add(40);
                    task_U3D_to_PDF.pdfAnnotation.PageLayout.dimensions.Add(760);
                    task_U3D_to_PDF.pdfAnnotation.PageLayout.dimensions.Add(500);
                    task_U3D_to_PDF.pdfAnnotation.ViewNodes.Add(new Pic3DExporter.viewNode() { name = "View_Step0", matrix = viewMatrix, backgroundColor = backColor, COSpecified = true, CO = 3000.0f, lightingScheme = "CAD" });
                    job.Tasks.Add(task_U3D_to_PDF);
                    // 
                    // open PDF
                    Pic3DExporter.task_OPEN_PDF_ADOBEREADER task_OpenPDF = new Pic3DExporter.task_OPEN_PDF_ADOBEREADER() { id = "TID-4" };
                    task_OpenPDF.Dependencies = "TID-3";
                    task_OpenPDF.Inputs.Add(new Pic3DExporter.PathRef() { pathID = "FID-5", role = "input pdf", deleteAfterUsing = false });
                    job.Tasks.Add(task_OpenPDF);
                    // **** TASKS END ****
                    job.SaveToFile(xmlFile);

                    // #### execute Pic3DExporter
                    string exePath = Path.Combine(currentDir, "Pic3DExporter.exe");
                    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 (!Properties.Settings.Default.DebugMode)
                            System.IO.File.Delete(xmlFile); 
                    }
                    catch (Exception) { }
                }
            }
        }
Пример #36
0
        private void toolStripButtonDES3_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 = _treeViewCtrl.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; }
            List<string> filePathes = new List<string>();
            foreach (Document d in des3Docs)
                filePathes.Add(d.File.Path(db));

            SaveFileDialog fd = new SaveFileDialog();
            fd.Filter = "Picador 3D files (*.des3)|*.des3|All files (*.*)|*.*";
            fd.FilterIndex = 0;
            fd.DefaultExt = "des3";
            fd.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 = Path.Combine(currentDir, "Pic3DExporter.exe");
                    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 (!Properties.Settings.Default.DebugMode)
                            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));
                }
            }
        }
Пример #37
0
        private void bnOk_Click(object sender, EventArgs e)
        {
            try
            {
                string filePath = fileSelectCtrl.FileName;
                string fileExt = System.IO.Path.GetExtension(filePath).ToLower();
                fileExt = fileExt.Substring(1);
                if (!System.IO.File.Exists(filePath))
                    return;

                // get tree node for document insertion
                Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext();
                if (null == _nodeTag || _nodeTag.IsDocument)
                    throw new Exception("Invalid TreeNode tag");
                Pic.DAL.SQLite.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 == Pic.DAL.SQLite.DocumentType.GetByName(db, "Parametric component"))
                        Pic.DAL.SQLite.DocumentType.CreateNew(db, "Parametric component", "Parametric component", "PicParam");

                    // create new document
                    Pic.DAL.SQLite.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 Pic.DAL.SQLite.ExceptionDAL(string.Format("No valid format handler from file extension: {0}", fileExt) );
                    // get document type
                    Pic.DAL.SQLite.DocumentType docType = Pic.DAL.SQLite.DocumentType.GetByName(db, fHandler.Name);
                    if (null == docType)
                        docType = Pic.DAL.SQLite.DocumentType.CreateNew(db, fHandler.Name, fHandler.Description, fHandler.Application);
                    // insert document in database
                    Pic.DAL.SQLite.Document document = treeNode.InsertDocument(
                        db
                        , filePath
                        , DocumentName
                        , DocumentDescription
                        , docType.Name
                        , ThumbnailPath);
                    // save document ID
                    _documentId = document.ID;
                    _openInsertedDocument = fHandler.OpenInPLMPackLib;
                }                
            }
            catch (Pic.DAL.SQLite.ExceptionDAL ex)
            {
                MessageBox.Show(
                    ex.Message
                    , Application.ProductName
                    , MessageBoxButtons.OK
                    , MessageBoxIcon.Error);
                _log.Error(ex.ToString());
            }
            catch (Exception ex)
            {
                _log.Error(ex.ToString());
            }
        }
Пример #38
0
 private void bnDelete_Click(object sender, EventArgs e)
 {
     try
     {
         if (listViewCardboardFormats.SelectedIndices.Count > 0)
         {
             Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext();
             // delete selected cardboard profile
             int iSel = this.listViewCardboardFormats.SelectedIndices[0];
             Pic.DAL.SQLite.CardboardFormat[] formats = Pic.DAL.SQLite.CardboardFormat.GetAll(db);
             formats[iSel].Delete(db);
             // fill list view again
             FillListView();
             // select first item
             if (listViewCardboardFormats.Items.Count > 0)
                 listViewCardboardFormats.Items[0].Selected = true;
         }
     }
     catch (Exception ex)
     {
         Debug.Fail(ex.ToString());
         _log.Debug(ex.ToString());
     }
 }
Пример #39
0
        private void bnOk_Click(object sender, EventArgs e)
        {
            try
            {
                string filePath = fileSelectCtrl.FileName;
                string fileExt  = System.IO.Path.GetExtension(filePath).ToLower();
                fileExt = fileExt.Substring(1);
                if (!System.IO.File.Exists(filePath))
                {
                    return;
                }

                // get tree node for document insertion
                Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext();
                if (null == _nodeTag || _nodeTag.IsDocument)
                {
                    throw new Exception("Invalid TreeNode tag");
                }
                Pic.DAL.SQLite.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 == Pic.DAL.SQLite.DocumentType.GetByName(db, "Parametric component"))
                    {
                        Pic.DAL.SQLite.DocumentType.CreateNew(db, "Parametric component", "Parametric component", "PicParam");
                    }

                    // create new document
                    Pic.DAL.SQLite.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 Pic.DAL.SQLite.ExceptionDAL(string.Format("No valid format handler from file extension: {0}", fileExt));
                    }
                    // get document type
                    Pic.DAL.SQLite.DocumentType docType = Pic.DAL.SQLite.DocumentType.GetByName(db, fHandler.Name);
                    if (null == docType)
                    {
                        docType = Pic.DAL.SQLite.DocumentType.CreateNew(db, fHandler.Name, fHandler.Description, fHandler.Application);
                    }
                    // insert document in database
                    Pic.DAL.SQLite.Document document = treeNode.InsertDocument(
                        db
                        , filePath
                        , DocumentName
                        , DocumentDescription
                        , docType.Name
                        , ThumbnailPath);
                    // save document ID
                    _documentId           = document.ID;
                    _openInsertedDocument = fHandler.OpenInPLMPackLib;
                }
            }
            catch (Pic.DAL.SQLite.ExceptionDAL ex)
            {
                MessageBox.Show(
                    ex.Message
                    , Application.ProductName
                    , MessageBoxButtons.OK
                    , MessageBoxIcon.Error);
                _log.Error(ex.ToString());
            }
            catch (Exception ex)
            {
                _log.Error(ex.ToString());
            }
        }