示例#1
0
    //------------------------------------------------------------------------------
    //Callback Name: update_cb
    //------------------------------------------------------------------------------
    public int update_cb(NXOpen.BlockStyler.UIBlock block)
    {
        try
        {
            if (block == GraphTypeSelect)
            {
            }
            else if (block == PointSelector)
            {
                AllPoints.Clear();
                int        counter   = 0;
                var        Selection = PointSelector.GetSelectedObjects();
                var        Sect      = Selection[0] as Section;
                NXObject[] Data;
                Sect.EvaluateAndAskOutputEntities(out Data);
                foreach (NXObject obj in Data)
                {
                    Point3d   coords = ((Point)obj).Coordinates;
                    NodePoint iNode  = new NodePoint("Point_" + counter++, coords);
                    if (!AllPoints.Any(p => Math.Round(p.X, 3) == Math.Round(coords.X, 3) && Math.Round(p.Y, 3) == Math.Round(coords.Y, 3) && Math.Round(p.Z, 3) == Math.Round(coords.Z, 3)))
                    {
                        AllPoints.Add(iNode); // Собираем список всех точек в NodeList
                    }
                }
                if (AllPoints.Count != 0)
                {
                    ExportButton.Enable = true;
                }
                else
                {
                    ExportButton.Enable = false;
                }
            }

            else if (block == ExportButton)
            {
                var type    = GraphTypeSelect.ValueAsString;
                var part    = theSession.Parts.Work;
                var Tags    = new List <Tag>();
                var tag     = new Tag();
                int counter = 0;
                switch (type)
                {
                case "Gap or Size":
                    #region Gap Calculation

                    foreach (NodePoint Vstart in AllPoints)
                    {
                        foreach (NodePoint Vend in AllPoints)
                        {
                            if (Vstart.Name != Vend.Name)
                            {
                                Vstart.DistanceTo.Add(Vend, getDistance(Vstart, Vend));
                            }
                        }
                    }
                    Graph.Clear();
                    NodePoint thisNode = AllPoints[0];
                    NodePoint nextNode = null;
                    counter       = 0;
                    thisNode.Name = "A" + counter++;
                    Graph.AddLast(thisNode);
                    while (Graph.Count < AllPoints.Count)
                    {
                        nextNode = thisNode.getClosestNode();
                        while (Graph.Contains(nextNode))
                        {
                            thisNode.DistanceTo.Remove(nextNode);
                            nextNode = thisNode.getClosestNode();
                        }
                        thisNode      = nextNode;
                        thisNode.Name = "A" + counter++;
                        Graph.AddLast(thisNode);
                    }

                    for (LinkedListNode <NodePoint> node = Graph.First; node != null; node = node.Next)
                    {
                        var newpoint = new Point3d(node.Value.X, node.Value.Y, node.Value.Z);
                        var p        = part.Points.CreatePoint(newpoint);
                        p.SetName(node.Value.Name);
                        PointFeatureBuilder p_feature;
                        p_feature       = part.BaseFeatures.CreatePointFeatureBuilder(null);
                        p_feature.Point = p;
                        p_feature.Commit();
                        p_feature.GetFeature().SetName(node.Value.Name);
                        Tags.Add(p_feature.GetFeature().Tag);
                        p.SetVisibility(SmartObject.VisibilityOption.Visible);
                    }
                    theUFSession.Modl.CreateSetOfFeature("Contour Points", Tags.ToArray(), Tags.Count, 1, out tag);

                    break;

                    #endregion
                case "Curvature":
                    #region Curvature Calculation
                    var Zsort = new SortByZ();
                    AllPoints.Sort(Zsort);
                    foreach (NodePoint node in AllPoints)
                    {
                        var newpoint = new Point3d(node.X, node.Y, node.Z);
                        var p        = part.Points.CreatePoint(newpoint);
                        node.Name = "A" + counter++;
                        p.SetName(node.Name);
                        PointFeatureBuilder p_feature;
                        p_feature       = part.BaseFeatures.CreatePointFeatureBuilder(null);
                        p_feature.Point = p;
                        p_feature.Commit();
                        p_feature.GetFeature().SetName(node.Name);
                        Tags.Add(p_feature.GetFeature().Tag);
                        p.SetVisibility(SmartObject.VisibilityOption.Visible);
                    }
                    theUFSession.Modl.CreateSetOfFeature("Curvature", Tags.ToArray(), Tags.Count, 1, out tag);
                    break;

                    #endregion
                case "Random Points":
                    #region Random Calculation
                    foreach (NodePoint node in AllPoints)
                    {
                        var newpoint = new Point3d(node.X, node.Y, node.Z);
                        var p        = part.Points.CreatePoint(newpoint);
                        node.Name = "A" + counter++;
                        p.SetName(node.Name);
                        PointFeatureBuilder p_feature;
                        p_feature       = part.BaseFeatures.CreatePointFeatureBuilder(null);
                        p_feature.Point = p;
                        p_feature.Commit();
                        p_feature.GetFeature().SetName(node.Name);
                        Tags.Add(p_feature.GetFeature().Tag);
                        p.SetVisibility(SmartObject.VisibilityOption.Visible);
                    }
                    theUFSession.Modl.CreateSetOfFeature("Points", Tags.ToArray(), Tags.Count, 1, out tag);
                    break;
                    #endregion
                }

                ComposeXLSX();
            }
            else if (block == ImportButton)
            {
                OpenFileDialog myDialog = new OpenFileDialog();
                string         FileName = "";
                myDialog.Filter = "Документы Excel (*.xlsx)|**.XLSX";
                if (myDialog.ShowDialog() == DialogResult.OK)
                {
                    FileName = myDialog.FileName;
                    var inputFile = new FileStream(FileName, FileMode.Open, FileAccess.Read);
                    if (FileName.ToLower().EndsWith(".xlsx"))
                    {
                        XSSFWorkbook inbook = OpenFileXLSX(FileName);
                        DrawPoints(inbook);
                    }
                    if (FileName.ToLower().EndsWith(".xls"))
                    {
                        HSSFWorkbook inbook = OpenFileXLS(FileName);
                        DrawPoints(inbook);
                    }
                }
            }
        }
        catch (Exception ex)
        {
            //---- Enter your exception handling code here -----
            theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
        }
        return(0);
    }
示例#2
0
        private void ExportWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            AllPoints.Clear();
            CATIA = (INFITF.Application)Marshal.GetActiveObject("Catia.Application");
            Selection sel = CATIA.ActiveDocument.Selection;

            sel.Search("((((((CATStFreeStyleSearch.Point + CAT2DLSearch.2DPoint) + CATSketchSearch.2DPoint) + CATDrwSearch.2DPoint) + CATPrtSearch.Point) + CATGmoSearch.Point) + CATSpdSearch.Point),sel");
            //sel.Search("CATPrtsearch.point, sel");
            object[] coords  = new object[3];
            int      counter = 0;

            if (sel.Count != 0)
            {
                for (int i = 1; i <= sel.Count2; i++)
                {
                    var item = sel.Item2(i).Value as HybridShapeTypeLib.Point;
                    item.GetCoordinates(coords);
                    double X    = Convert.ToDouble(coords[0]);
                    double Y    = Convert.ToDouble(coords[1]);
                    double Z    = Convert.ToDouble(coords[2]);
                    string name = "";
                    if (item.get_Name().Contains("Точка.") || item.get_Name().Contains("Point."))
                    {
                        name = "Point_" + counter++;
                    }
                    else
                    {
                        name = item.get_Name();
                    }
                    NodePoint iNode = new NodePoint(name, X, Y, Z, item);
                    if (!AllPoints.Any(p => Math.Round(p.X, 3) == Math.Round(X, 3) && Math.Round(p.Y, 3) == Math.Round(Y, 3) && Math.Round(p.Z, 3) == Math.Round(Z, 3)))
                    {
                        AllPoints.Add(iNode); // Собираем список всех точек в NodeList
                    }
                }
                /////

                if (AllPoints.All(x => x.Name.Contains("Point_"))) //Если у все хточек нет нормальных названий
                {
                    var type = GraphTypeCombo.SelectedValue.ToString();
                    //var type = "Random Points";
                    counter = 0;
                    switch (type)
                    {
                    case "Gap or Size":
                        #region Gap Calculation
                        foreach (NodePoint Vstart in AllPoints)
                        {
                            foreach (NodePoint Vend in AllPoints)
                            {
                                if (Vstart.Name != Vend.Name)
                                {
                                    Vstart.DistanceTo.Add(Vend, getDistance(Vstart, Vend));
                                }
                            }
                        }
                        Graph.Clear();
                        NodePoint thisNode = AllPoints[0];
                        NodePoint nextNode = null;
                        counter       = 0;
                        thisNode.Name = "A" + counter++;
                        Graph.AddLast(thisNode);
                        while (Graph.Count < AllPoints.Count)
                        {
                            nextNode = thisNode.getClosestNode();
                            while (Graph.Contains(nextNode))
                            {
                                thisNode.DistanceTo.Remove(nextNode);
                                nextNode = thisNode.getClosestNode();
                            }
                            thisNode      = nextNode;
                            thisNode.Name = "A" + counter++;
                            Graph.AddLast(thisNode);
                        }

                        for (LinkedListNode <NodePoint> node = Graph.First; node != null; node = node.Next)
                        {
                            node.Value.link.set_Name(node.Value.Name);
                        }
                        break;

                        #endregion
                    case "Curvature":
                        #region Curvature Calculation
                        var Zsort = new SortByZ();
                        AllPoints.Sort(Zsort);
                        foreach (NodePoint node in AllPoints)
                        {
                            node.Name = "A" + counter++;
                            node.link.set_Name(node.Name);
                        }
                        break;

                        #endregion
                    case "Random Points":
                        #region Random Calculation
                        foreach (NodePoint node in AllPoints)
                        {
                            node.Name = "A" + counter++;
                            node.link.set_Name(node.Name);
                        }
                        break;
                        #endregion
                    }
                }
                else
                {
                    var Dsort = new SortByNameDigit();
                    AllPoints.Sort(Dsort);
                }
                //
                ComposeXLSX();
                var result =
                    e.Result = "ok";
            }
            else
            {
                e.Result = "no points";
            }
        }
示例#3
0
    public static int NotMain(string[] args)
    {
        theSession = Session.GetSession();
        uf         = UFSession.GetUFSession();
        theUI      = UI.GetUI();
        var Zsort     = new SortByZ();
        var part      = theSession.Parts.Work;
        var AllPoints = new List <NodePoint>();
        int counter   = 0;

        for (int i = 0; i < theUI.SelectionManager.GetNumSelectedObjects(); i++)
        {
            TaggedObject obj = theUI.SelectionManager.GetSelectedTaggedObject(i);
            if (obj is Point)
            {
                Point3d   coords = ((Point)obj).Coordinates;
                NodePoint iNode  = new NodePoint("Point_" + counter++, coords);
                AllPoints.Add(iNode); // Собираем список всех точек
            }
        }

        var Tags = new List <Tag>();
        var tag  = new Tag();

        /* // Curvature = OK
         * AllPoints.Sort(Zsort);
         * foreach (NodePoint node in AllPoints)
         * {
         *  var newpoint = new Point3d(node.X, node.Y, node.Z);
         *  var p = part.Points.CreatePoint(newpoint);
         *  node.Name = "A" + counter++;
         *  p.SetName(node.Name);
         *  PointFeatureBuilder p_feature;
         *  p_feature = part.BaseFeatures.CreatePointFeatureBuilder(null);
         *  p_feature.Point = p;
         *  p_feature.Commit();
         *  p_feature.GetFeature().SetName(node.Name);
         *  Tags.Add(p_feature.GetFeature().Tag);
         *  p.SetVisibility(SmartObject.VisibilityOption.Visible);
         * }
         * uf.Modl.CreateSetOfFeature("Curvature", Tags.ToArray(), Tags.Count, 1, out tag);
         */


        /*
         * foreach (NodePoint Vstart in AllPoints)
         * {
         *  foreach (NodePoint Vend in AllPoints)
         *  {
         *      if (Vstart.Name != Vend.Name)
         *      {
         *          Vstart.DistanceTo.Add(Vend, getDistance(Vstart, Vend));
         *      }
         *  }
         * }
         *
         *
         * NodePoint thisNode = AllPoints[0];
         * NodePoint nextNode = null;
         * counter = 0;
         * thisNode.Name = "A" + counter++;
         * Graph.AddLast(thisNode);
         *
         * while (Graph.Count < AllPoints.Count)
         * {
         *  nextNode = thisNode.getClosestNode();
         *  while (Graph.Contains(nextNode))
         *  {
         *      thisNode.DistanceTo.Remove(nextNode);
         *      nextNode = thisNode.getClosestNode();
         *  }
         *  thisNode = nextNode;
         *  thisNode.Name = "A" + counter++;
         *  Graph.AddLast(thisNode);
         * }
         *
         * for (LinkedListNode<NodePoint> node = Graph.First; node != null; node = node.Next)
         * {
         *  var newpoint = new Point3d(node.Value.X, node.Value.Y, node.Value.Z);
         *  var p = part.Points.CreatePoint(newpoint);
         *  p.SetName(node.Value.Name);
         *  PointFeatureBuilder p_feature;
         *  p_feature = part.BaseFeatures.CreatePointFeatureBuilder(null);
         *  p_feature.Point = p;
         *  p_feature.Commit();
         *  p_feature.GetFeature().SetName(node.Value.Name);
         *  Tags.Add(p_feature.GetFeature().Tag);
         *  p.SetVisibility(SmartObject.VisibilityOption.Visible);
         * }
         *
         *
         * uf.Modl.CreateSetOfFeature("Curvature", Tags.ToArray(), Tags.Count, 1, out tag);
         */
        return(0);
    }