Ejemplo n.º 1
0
        public static void Run()
        {
            //add database changes event handler
            DatabaseService.Changes += new DbChangesEventHandler(DatabaseService_Changes);

            //
            // Element Creation, Deletion, Re-order, Include, Copy
            //
            DbElement nozz1 = Example.Instance.mEqui.CreateFirst(DbElementTypeInstance.NOZZLE);

            Pdms.Utilities.CommandLine.Command.Update();

            DbElement nozz2 = Example.Instance.mEqui.CreateLast(DbElementTypeInstance.NOZZLE);

            Pdms.Utilities.CommandLine.Command.Update();

            nozz1.Copy(Example.Instance.mNozz1);                    // Copy element
            nozz1.SetAttribute(DbAttributeInstance.DESC, "nozzle"); // Change only one part
            Pdms.Utilities.CommandLine.Command.Update();            // Make sure these changes are ignored
            nozz1.Copy(Example.Instance.mNozz1);                    // Re-Copy element - should indicate only the description part has changed
            Pdms.Utilities.CommandLine.Command.Update();

            nozz1.InsertAfterLast(Example.Instance.mEqui);
            Pdms.Utilities.CommandLine.Command.Update();

            nozz1.Delete();
            Pdms.Utilities.CommandLine.Command.Update();
        }
Ejemplo n.º 2
0
        public void reculsive_copy_spec(DbElement owner, DbElement copy_from_element, string specname, List <int> diameters)
        {
            try {
                int           ddepth         = copy_from_element.GetInteger(DbAttributeInstance.DDEP);
                DbElementType copy_from_type = copy_from_element.GetElementType(DbAttributeInstance.TYPE);
                if (copy_from_type == DbElementTypeInstance.TEXT)
                {
                    return;
                }
                string copy_from_name = copy_from_element.GetAsString(DbAttributeInstance.NAME);
                string tanswer        = copy_from_element.GetAsString(DbAttributeInstance.TANS);


                //if (copy_from_type == DbElementTypeInstance.SPCOMPONENT)
                //return;
                //if (ddepth == 6)
                //    return;
                DbElement sel = null;
                if (ddepth == 3) //comp 타입 결정
                {
                    string type_name = "/" + specname + "." + tanswer;
                    try {
                        var selobj = owner.Members().Where(x => x.GetAsString(DbAttributeInstance.NAME) == type_name);

                        if (selobj.Count() == 0)
                        {
                            sel = owner.CreateLast(copy_from_type);
                            sel.SetAttribute(DbAttributeInstance.NAME, type_name);
                            sel.Copy(copy_from_element);
                        }
                        else
                        {
                            sel = selobj.First();
                        }
                        foreach (DbElement org in copy_from_element.Members())
                        {
                            reculsive_copy_spec(sel, org, specname, diameters);
                        }
                    }
                    catch (Exception ee)
                    {
                        Console.WriteLine("해당 Selec는 존재하기에 오류남");
                        Aveva.Pdms.Utilities.CommandLine.Command.CreateCommand(string.Format("$p |{0} Selec는 존재하기에 오류남222|", type_name)).RunInPdms();
                    }
                }

                else
                {
                    if (ddepth == 4)
                    {
                        int size = Convert.ToInt32(copy_from_element.GetAsString(DbAttributeInstance.ANSW).Replace("mm", ""));
                        if (!diameters.Contains(size))
                        {
                            return;
                        }
                        //if (size != 32)
                        Console.WriteLine("11");
                    }
                    //sel = owner.CreateLast(DbElementTypeInstance.SELEC);
                    if (tanswer.Contains("JOINT-MITRE") || tanswer.Contains("JOINT-THREAD"))
                    {
                        return;
                    }
                    if (copy_from_name == "/PPPG40S/HMDP_SPEC/PEPG409SS-25")
                    {
                        //return;
                        Console.WriteLine("11");
                    }
                    sel = owner.CreateLast(copy_from_type);
                    if (copy_from_type == DbElementTypeInstance.SPCOMPONENT)
                    {
                        //spco이름 세팅
                        try
                        {
                            sel.SetAttribute(DbAttributeInstance.NAME, "/" + specname + copy_from_element.GetAsString(DbAttributeInstance.CATR).Replace("-SCOM", ""));
                        }catch (Exception ee)
                        {
                        }

                        try
                        {
                            sel.SetAttribute(DbAttributeInstance.CMPR, copy_from_element.GetElement(DbAttributeInstance.CMPR));
                        }
                        catch (Exception ee) { }
                        try
                        {
                            sel.SetAttribute(DbAttributeInstance.CATR, copy_from_element.GetElement(DbAttributeInstance.CATR));
                        }
                        catch (Exception ee) { }
                        try
                        {
                            sel.SetAttribute(DbAttributeInstance.DETR, copy_from_element.GetElement(DbAttributeInstance.DETR));
                        }
                        catch (Aveva.Pdms.Utilities.Messaging.PdmsException ee) {
                        }
                        try
                        {
                            sel.SetAttribute(DbAttributeInstance.PRTREF, copy_from_element.GetElement(DbAttributeInstance.PRTREF));
                        }catch (Exception ee)
                        { }
                        try
                        {
                            sel.SetAttribute(DbAttributeInstance.TANS, copy_from_element.GetAsString(DbAttributeInstance.TANS));
                        }
                        catch (Exception ee) { }
                    }
                    else
                    {
                        sel.Copy(copy_from_element);
                    }

                    foreach (DbElement org in copy_from_element.Members())
                    {
                        reculsive_copy_spec(sel, org, specname, diameters);
                    }
                }
            }
            catch (Exception ee)
            {
                Aveva.Pdms.Utilities.CommandLine.Command.CreateCommand(string.Format("$p |{0} any is wrong|", "--")).RunInPdms();
            }


            //DbCopyOption op = new DbCopyOption();
            //sel.CopyHierarchy(copy_from_element, op);

            //reculsive_copy_spec()
        }
        public static void Run()
        {
            //Get element type
            int           hash = DbElementTypeInstance.EQUIPMENT.GetHashCode();
            DbElementType type = DbElementType.GetElementType(hash);

            // Get system attributes
            DbAttribute[] atts = DbElementTypeInstance.EQUIPMENT.SystemAttributes();
            int           size = atts.Length;

            //Construct equi1
            DbElement equi1 = DbElement.GetElement("/ExampleEqui");

            //Create equi2 after equi1
            DbElement equi2 = equi1.CreateAfter(DbElementTypeInstance.EQUIPMENT);

            //Copy equi1 to equi2
            equi2.Copy(equi1);

            //Copy hierarchy
            DbCopyOption options = new DbCopyOption();

            options.FromName = "ExampleEqui";
            options.ToName   = "equi2";
            options.Rename   = true;
            equi2.CopyHierarchy(equi1, options);
            DbElement first = equi2.FirstMember();

            //Copy after last
            equi1.InsertAfterLast(Example.Instance.mZone);

            //Branch to head tube
            DbElement headTube     = Example.Instance.mBran.FirstMember();
            string    headTubeName = headTube.GetString(DbAttributeInstance.NAME);

            //Next Prev
            DbElement nextElement = headTube.Next();
            DbElement prevElement = nextElement.Previous;

            //First Member of given type
            DbElement nozz1 = Example.Instance.mEqui.FirstMember(DbElementTypeInstance.NOZZLE);

            //Next element of given type
            DbElement nozz2 = nozz1.Next(DbElementTypeInstance.NOZZLE);

            //Get Members
            DbElement[] members = Example.Instance.mBran.Members();

            //Get Members of given type
            DbElement[] nozzles = Example.Instance.mEqui.Members(DbElementTypeInstance.NOZZLE);

            //Get nth Member
            DbElement mem = Example.Instance.mEqui.Member(2);

            //Expressions
            DbElement[] eles;
            eles  = Example.Instance.mEqui.GetElementArray(DbAttribute.GetDbAttribute("MEMB"), DbElementType.GetElementType("NOZZ"));
            nozz1 = eles[1];
            DbExpression    expr1 = DbExpression.Parse("HEIGHT OF PREV * 2");
            string          val   = expr1.ToString();
            double          dval;
            DbAttributeUnit units = DbAttributeUnit.DIST;

            dval = nozz1.EvaluateDouble(expr1, units);
            DbExpression expr2 = DbExpression.Parse("12");

            dval = nozz1.EvaluateDouble(expr2, units);

            //Rules
            DbExpression     expr   = DbExpression.Parse("HEIGHT * 2.0");
            DbRuleStatus     status = DbRuleStatus.DYNAMIC;
            DbExpressionType etype  = DbExpressionType.REAL;
            DbRule           rule   = DbRule.CreateDbRule(expr, status, etype);

            Example.Instance.mCyli.SetRule(DbAttribute.GetDbAttribute("DIAM"), rule);
            DbRule rule1 = Example.Instance.mCyli.GetRule(DbAttribute.GetDbAttribute("DIAM"));
            string text  = rule1.ToString();

            //Delete/Exists Rule
            Example.Instance.mCyli.DeleteRule(DbAttribute.GetDbAttribute("DIAM"));
            bool exists = Example.Instance.mCyli.ExistRule(DbAttribute.GetDbAttribute("DIAM"));

            Example.Instance.mCyli.SetRule(DbAttribute.GetDbAttribute("DIAM"), rule1);
            exists = Example.Instance.mCyli.ExistRule(DbAttribute.GetDbAttribute("DIAM"));

            //Change attribute
            Example.Instance.mCyli.SetAttribute(DbAttribute.GetDbAttribute("DIAM"), 1000.0F);
            double diam = Example.Instance.mCyli.GetDouble(DbAttribute.GetDbAttribute("DIAM"));

            //verify rule
            bool diff = Example.Instance.mCyli.VerifyRule(DbAttribute.GetDbAttribute("DIAM"));

            //execute rule
            Example.Instance.mCyli.ExecuteRule(DbAttribute.GetDbAttribute("DIAM"));
            diam = Example.Instance.mCyli.GetDouble(DbAttribute.GetDbAttribute("DIAM"));

            //verify rule again
            diff = Example.Instance.mCyli.VerifyRule(DbAttribute.GetDbAttribute("DIAM"));

            //change some attributes
            Example.Instance.mCyli.SetAttribute(DbAttribute.GetDbAttribute("DIAM"), 1000.0F);
            diam = Example.Instance.mCyli.GetDouble(DbAttribute.GetDbAttribute("DIAM"));

            //Now execute all rules under equi
            Example.Instance.mEqui.ExecuteAllRules();
            diam = Example.Instance.mCyli.GetDouble(DbAttribute.GetDbAttribute("DIAM"));

            //Propagate rules
            Example.Instance.mCyli.SetAttribute(DbAttribute.GetDbAttribute("DIAM"), 1000.0F);
            Example.Instance.mCyli.PropagateRules(DbAttribute.GetDbAttribute("DIAM"));

            //Claim/Release
            Example.Instance.mEqui.Claim();
            bool claimed = Example.Instance.mEqui.GetBool(DbAttribute.GetDbAttribute("LCLM"));

            //release equi
            MDB.CurrentMDB.SaveWork("Save Example");
            Example.Instance.mEqui.Release();
            claimed = Example.Instance.mEqui.GetBool(DbAttribute.GetDbAttribute("LCLM"));

            //Claim hierarchy
            try
            {
                Example.Instance.mEqui.ClaimHierarchy();
            }
            catch (PdmsException ex)
            {
            }
            claimed = Example.Instance.mEqui.GetBool(DbAttribute.GetDbAttribute("LCLMH"));

            //release all equi
            Example.Instance.mEqui.ReleaseHierarchy();
            claimed = Example.Instance.mEqui.GetBool(DbAttribute.GetDbAttribute("LCLM"));

            //change type
            string stype = Example.Instance.mTee.GetElementType().ToString();

            Example.Instance.mTee.ChangeType(DbElementType.GetElementType("OLET"));
            stype = Example.Instance.mTee.GetElementType().ToString();

            //UDA at default
            string      special = "Test UDA";
            DbAttribute uda     = DbAttribute.GetDbAttribute(":SPECIAL");

            if (uda != null)
            {
                Example.Instance.mElbo.SetAttribute(uda, special);
                special = Example.Instance.mElbo.GetString(uda);
                bool dflt = Example.Instance.mElbo.AtDefault(uda);

                //is one element above another in the hierarchy
                bool result = Example.Instance.mSite.IsDescendant(Example.Instance.mZone);
                result = Example.Instance.mZone.IsDescendant(Example.Instance.mSite);

                //Set uda to default
                Example.Instance.mElbo.SetAttributeDefault(uda);
                special = Example.Instance.mElbo.GetString(uda);
                dflt    = Example.Instance.mElbo.AtDefault(uda);
            }
        }