コード例 #1
0
        private void SetActiveContainer(IContainer component)
        {
            _activeContainer = component;
            _autoZoom        = true;

            panelPart.Visible = false;
            gridPcbLibPrimitives.Rows.Clear();
            gridSchLibPrimitives.Rows.Clear();

            if (_activeContainer != null)
            {
                LoadPrimitives(_activeContainer);

                if (_activeContainer is SchComponent schComponent)
                {
                    panelPart.Visible = schComponent.PartCount > 1;
                    if (panelPart.Visible)
                    {
                        editPart.Maximum    = schComponent.PartCount;
                        editPart.Value      = 1;
                        labelPartTotal.Text = $"of {editPart.Maximum}";
                    }
                }
            }
            else
            {
                SetActivePrimitives(null);
            }
            RequestRedraw(false);
        }
コード例 #2
0
        private void LoadPrimitives(IContainer component, bool activateFirst = false)
        {
            Primitive defaultPrimitive = null;

            if (component is PcbComponent pcbComponent)
            {
                var primitives = pcbComponent.Primitives;
                foreach (var primitive in primitives)
                {
                    var info = primitive.GetDisplayInfo();
                    var i    = gridPcbLibPrimitives.Rows.Add(primitive.ObjectId, info.Name, info.SizeX?.ToString(_displayUnit), info.SizeY?.ToString(_displayUnit), primitive.Layer.Name);
                    gridPcbLibPrimitives.Rows[i].Tag = primitive;
                }
                defaultPrimitive = pcbComponent.Primitives.FirstOrDefault();
            }
            else if (component is SchComponent schComponent)
            {
                var pins = schComponent.Primitives.OfType <PinRecord>();
                foreach (var pin in pins)
                {
                    var i = gridSchLibPrimitives.Rows.Add(pin.Designator, pin.Name, pin.Electrical.ToString());
                    gridSchLibPrimitives.Rows[i].Tag = pin;
                }
                defaultPrimitive = pins.FirstOrDefault();
            }
            SetActivePrimitives((activateFirst && defaultPrimitive != null) ? new[] { defaultPrimitive } : null);
        }
コード例 #3
0
ファイル: Main.cs プロジェクト: veselinbg/AltiumSharp
        private void SetActiveContainer(IContainer component, IEnumerable <Primitive> activePrimitives = null)
        {
            if (_activeContainer != component)
            {
                _activeContainer = component;
                _autoZoom        = true;

                panelPart.Visible = false;
                gridPcbLibPrimitives.Rows.Clear();
                gridSchLibPrimitives.Rows.Clear();
                treeViewStructure.Nodes.Clear();

                if (_activeContainer != null)
                {
                    LoadPrimitives(_activeContainer);
                    LoadTreeViewStructure(_activeContainer);
                }
            }
            else
            {
                gridPcbLibPrimitives.Invalidate();
                gridSchLibPrimitives.Invalidate();
                treeViewStructure.Invalidate();
            }

            if (_activeContainer is SchComponent schComponent)
            {
                panelPart.Visible = (schComponent.DisplayModeCount > 1) || (schComponent.PartCount > 1);
                if (panelPart.Visible)
                {
                    comboDisplayMode.Items.Clear();
                    comboDisplayMode.Items.Add(@"Normal");
                    for (var i = 1; i < schComponent.DisplayModeCount; ++i)
                    {
                        comboDisplayMode.Items.Add($@"Alternate {i}");
                    }

                    comboDisplayMode.SelectedIndex = schComponent.DisplayMode;

                    editPart.Maximum    = schComponent.PartCount;
                    labelPartTotal.Text = $@"of {editPart.Maximum}";
                    editPart.Value      = schComponent.CurrentPartId;
                }
            }

            SetActivePrimitives(activePrimitives);
            if (_activeContainer != null && activePrimitives == null)
            {
                _propertyViewer?.SetSelectedObjects(new[] { _activeContainer });
            }

            RequestRedraw(false);
        }
コード例 #4
0
ファイル: Main.cs プロジェクト: veselinbg/AltiumSharp
        private void LoadTreeViewStructure(IContainer container)
        {
            void processContainer(TreeNodeCollection tnc, IContainer c)
            {
                foreach (var primitive in c.GetPrimitivesOfType <Primitive>(false))
                {
                    var node = tnc.Add(primitive.ToString());
                    node.Tag = primitive;

                    if (primitive is IContainer c2)
                    {
                        processContainer(node.Nodes, c2);
                    }
                }
            }

            treeViewStructure.BeginUpdate();
            processContainer(treeViewStructure.Nodes, container);
            treeViewStructure.EndUpdate();
            treeViewStructure.Refresh();
        }
コード例 #5
0
ファイル: Main.cs プロジェクト: veselinbg/AltiumSharp
 private void LoadPrimitives(IContainer component)
 {
     if (component is PcbComponent pcbComponent)
     {
         var primitives = pcbComponent.Primitives;
         foreach (var primitive in primitives)
         {
             var info = primitive.GetDisplayInfo();
             var i    = gridPcbLibPrimitives.Rows.Add(primitive.ObjectId, info.Name, info.SizeX?.ToString(_displayUnit), info.SizeY?.ToString(_displayUnit), primitive.Layer.Name);
             gridPcbLibPrimitives.Rows[i].Tag = primitive;
         }
     }
     else if (component is SchComponent schComponent)
     {
         var pins = schComponent.GetPrimitivesOfType <SchPin>();
         foreach (var pin in pins)
         {
             var i = gridSchLibPrimitives.Rows.Add(pin.Designator, pin.Name, pin.Electrical.ToString());
             gridSchLibPrimitives.Rows[i].Tag = pin;
         }
     }
 }
コード例 #6
0
ファイル: Main.cs プロジェクト: veselinbg/AltiumSharp
        private void SetData(object fileData)
        {
            var saveLoading = _loading;

            _loading = true;
            try
            {
                SetActiveContainer(null);
                if (_propertyViewer != null)
                {
                    _propertyViewer.Close();
                    _propertyViewer = null;
                }

                IContainer container = null;

                gridPcbLibComponents.Rows.Clear();
                gridSchLibComponents.Rows.Clear();
                treeViewStructure.Nodes.Clear();
                Application.DoEvents();

                if (fileData is PcbLib pcbLib)
                {
                    tabComponents.SelectTab(tabPcbLib);

                    foreach (var component in pcbLib.Items)
                    {
                        var index = gridPcbLibComponents.Rows.Add(component.Pattern, component.Pads, component.Primitives.Count());
                        gridPcbLibComponents.Rows[index].Tag = component;
                    }

                    _displayUnit  = pcbLib.Header.DisplayUnit;
                    _snapGridSize = pcbLib.Header.SnapGridSize;
                    _renderer     = new PcbLibRenderer();
                    container     = pcbLib.Items.OfType <IContainer>().FirstOrDefault();
                }
                else if (fileData is SchLib schLib)
                {
                    tabComponents.SelectTab(tabSchLib);

                    foreach (var component in schLib.Items)
                    {
                        var index = gridSchLibComponents.Rows.Add(component.LibReference, component.ComponentDescription);
                        gridSchLibComponents.Rows[index].Tag = component;
                    }

                    _displayUnit  = schLib.Header.DisplayUnit;
                    _snapGridSize = schLib.Header.SnapGridSize;
                    _renderer     = new SchLibRenderer(schLib.Header, GetAssetsSchLib());
                    container     = schLib.Items.OfType <IContainer>().FirstOrDefault();
                }
                else if (fileData is SchDoc schDoc)
                {
                    tabComponents.SelectTab(tabSchLib);

                    var index = gridSchLibComponents.Rows.Add("SchDoc");
                    gridSchLibComponents.Rows[index].Tag = schDoc.Header;
                    foreach (var component in schDoc.Header.GetPrimitivesOfType <SchComponent>())
                    {
                        index = gridSchLibComponents.Rows.Add(component.LibReference, component.ComponentDescription);
                        gridSchLibComponents.Rows[index].Tag = component;
                    }

                    var sheet = schDoc.Header;
                    _displayUnit  = sheet.DisplayUnit;
                    _snapGridSize = sheet.SnapGridSize;
                    _renderer     = new SchLibRenderer(schDoc.Header, GetAssetsSchLib());
                    container     = schDoc.Items.OfType <IContainer>().FirstOrDefault();
                }

                _fileData = fileData;
                SetActiveContainer(container);
            }
            finally
            {
                _loading = saveLoading;
            }
        }