public CompCompareWindow OpenCompareComponentsWindow(ComponentManagerType _user)
        {
            this.compComp_win = new CompCompareWindow(_user);
            this.compComp_win.Show();

            return(this.compComp_win);
        }
 public CompCompareWindow(ComponentManagerType _user)
 {
     this.user = _user;
     InitializeComponent();
     this.InitControls();
     this.Closed += CompCompareWindow_Closed;
 }
        public bool AddGeometricRelationship(GeometricRelationship _gr, ComponentManagerType _user)
        {
            // check if the user has writing access
            bool success = this.RecordWritingAccess(_user);

            if (!success)
            {
                return(false);
            }

            // perform the operation
            if (_gr == null)
            {
                return(false);
            }
            if (this.R2GInstances == null)
            {
                return(false);
            }

            foreach (GeometricRelationship instance in this.R2GInstances)
            {
                if (GeometricRelationship.ReferenceSameGeometry(instance, _gr))
                {
                    return(false);
                }
            }

            this.R2GInstances.Add(_gr);
            return(true);
        }
        /// <summary>
        /// Recursive removal of automatically created components.
        /// </summary>
        /// <param name="_user"></param>
        /// <returns></returns>
        internal bool RemoveAutomaticallyGeneratedSubComponents(ComponentManagerType _user)
        {
            if (this.ContainedComponents == null)
            {
                return(true);
            }

            bool success = true;

            foreach (var entry in this.ContainedComponents)
            {
                Component sComp = entry.Value;
                if (sComp == null)
                {
                    continue;
                }

                if (sComp.IsAutomaticallyGenerated)
                {
                    success &= this.RemoveSubComponent_Level0(sComp, true, _user);
                }
                else
                {
                    success &= sComp.RemoveAutomaticallyGeneratedSubComponents(_user);
                }
            }

            return(success);
        }
        private void manager_Click(object sender, RoutedEventArgs e)
        {
            ToggleButton tbtn = sender as ToggleButton;

            if (tbtn == null)
            {
                return;
            }
            if (tbtn.Tag == null)
            {
                return;
            }
            if (!(tbtn.Tag is ComponentManagerType))
            {
                return;
            }

            ComponentManagerType marked = (ComponentManagerType)tbtn.Tag;

            if (this.marked_users.Contains(marked))
            {
                this.marked_users.Remove(marked);
            }
            else
            {
                this.marked_users.Add(marked);
            }
        }
        internal void RemoveInstance(FlNetElement _container)
        {
            if (_container == null)
            {
                return;
            }

            // check for the proper type of geometric relationship
            if (this.R2GMainState.Type != Relation2GeomType.CONTAINED_IN && this.R2GMainState.Type != Relation2GeomType.CONNECTS)
            {
                return;
            }

            // check if the user has writing access
            ComponentManagerType user = ComponentManagerType.ADMINISTRATOR;

            if (this.Factory != null)
            {
                bool success = this.RecordWritingAccess(this.Factory.Caller);
                user = this.Factory.Caller;
                if (!success)
                {
                    return;
                }
            }
            else
            {
                return;
            }

            // if there is only one geometric relationship -> reset it
            if (this.R2GInstances.Count == 1 && this.R2GInstances[0].InstanceNWElementID == _container.ID)
            {
                this.R2GInstances[0].Reset();
                return;
            }

            // otherwise, just remove
            List <bool> to_retain = new List <bool>();

            for (int i = 0; i < this.R2GInstances.Count; i++)
            {
                if (this.R2GInstances[i].InstanceNWElementID == _container.ID)
                {
                    to_retain.Add(false);
                    this.RemovePlacementBasedReferencesToInstanceFromOtherComponents(this.R2GInstances[i]);
                }
                else
                {
                    to_retain.Add(true);
                }
            }

            // includes handling the case of the first (main) relationship being removed
            this.UpdateGeometricRelationships(to_retain, null, user);
            // re-calculate the cumulative values
            this.UpdateCumulativeValuesFromInstances();
        }
 private void SetFileManagementContent(string _file_name, ComponentManagerType _user)
 {
     this.current_file_record = null;
     this.loaded_file_records = new List <PartialFileRecord>();
     this.SummaryFileName     = _file_name;
     this.SingleFileNames     = new List <string>();
     this.manager             = _user;
     this.FileRecordsOpen     = false;
     this.write_in_progress   = false;
 }
        public DXFDistributedDecoder(MultiValueFactory _mv_factory, ParameterFactory _p_factory, ComponentFactory _comp_factory,
                                     string _file_name, ComponentManagerType _user)
        {
            this.MV_Factory   = _mv_factory;
            this.P_Factory    = _p_factory;
            this.COMP_Factory = _comp_factory;

            this.SetFileManagementContent(_file_name, _user);
            this.nr_locks_record = new List <int>(ComponentUtils.MANAGER_TYPE_OPENING_SIGNATURE_NONE);
        }
        // added 07.02.2017
        private bool DeleteSingleFile(string _filename_wo_ext, ComponentManagerType _user)
        {
            string filename_part = _filename_wo_ext + "_" +
                                   ComponentUtils.ComponentManagerTypeToAbbrevEN(_user) + "." +
                                   ParamStructFileExtensions.FILE_EXT_COMPONENTS;

            try
            {
                if (File.Exists(filename_part))
                {
                    File.Delete(filename_part);
                }
                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error deleting partial file: " + filename_part,
                                MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
        }
 private static bool HasEditingRights(ComponentManagerType _user, ComponentManagerType _file_manager)
 {
     return(_file_manager == ComponentManagerType.GUEST ||
            _user == ComponentManagerType.ADMINISTRATOR ||
            _file_manager == _user);
 }
        /// <summary>
        /// Attempts to merge two summary files. It compares the file records they contain by NAME only.
        /// Assumes that if a file is in RECORD 1 (own) but not in the RECORD 2 (from other source) and its manager is the current user of RECORD 1, it should be kept.
        /// If a file is in RECORD 1 (own) but not in the RECORD 2 (from other source) and its manager is NOT the current user of RECORD 1, the file should be deleted. This means
        /// that references or mappings to components in it made from components in other files will be lost.
        /// </summary>
        /// <param name="_dec_1_to_override"></param>
        /// <param name="_dec_2"></param>
        /// <returns></returns>
        public static ProjectMergeResult MergeSummaryFiles(DXFDistributedDecoder _dec_1_to_override, DXFDistributedDecoder _dec_2)
        {
            if (_dec_1_to_override == null || _dec_2 == null)
            {
                return(ProjectMergeResult.NULL_INPUT_ERROR);
            }

            bool ok_1 = _dec_1_to_override.LoadSummaryFileOnly();
            bool ok_2 = _dec_2.LoadSummaryFileOnly();

            if (!ok_1 || !ok_2)
            {
                return(ProjectMergeResult.IO_ERROR);
            }

            if (!(Utils.StringUtils.UnQualifiedFileNamesEqual(_dec_1_to_override.SummaryFileName, _dec_2.SummaryFileName)))
            {
                return(ProjectMergeResult.PROJECT_FILE_NAME_MISMATCH);
            }

            // sort the file records
            SortedDictionary <ComponentManagerType, PartialFileRecord> sorted_records_1 = new SortedDictionary <ComponentManagerType, PartialFileRecord>();

            foreach (PartialFileRecord pfr in _dec_1_to_override.loaded_file_records)
            {
                sorted_records_1.Add(pfr.Manager, pfr);
            }

            SortedDictionary <ComponentManagerType, PartialFileRecord> sorted_records_2 = new SortedDictionary <ComponentManagerType, PartialFileRecord>();

            foreach (PartialFileRecord pfr in _dec_2.loaded_file_records)
            {
                sorted_records_2.Add(pfr.Manager, pfr);
            }

            // compare the file records
            List <PartialFileRecord> merged_records = new List <PartialFileRecord>();

            for (int i = 0; i < Enum.GetNames(typeof(ComponentManagerType)).Length; i++)
            {
                ComponentManagerType m = (ComponentManagerType)i;
                if (sorted_records_1.ContainsKey(m) && !sorted_records_2.ContainsKey(m))
                {
                    if (m != _dec_1_to_override.manager)
                    {
                        // someone else deleted this record -> so skip it
                    }
                    else
                    {
                        // possibly I created this record -> so keep it
                        merged_records.Add(sorted_records_1[m]);
                    }
                }
                else if (!sorted_records_1.ContainsKey(m) && sorted_records_2.ContainsKey(m))
                {
                    if (m != _dec_1_to_override.manager)
                    {
                        // someone else created this record -> so KEEP it
                        merged_records.Add(sorted_records_2[m]);
                    }
                    else
                    {
                        // possibly I deleted this record -> so SKIP it
                    }
                }
                else if (sorted_records_1.ContainsKey(m) && sorted_records_2.ContainsKey(m))
                {
                    if (!(Utils.StringUtils.UnQualifiedFileNamesEqual(sorted_records_1[m].FileName, sorted_records_2[m].FileName)))
                    {
                        return(ProjectMergeResult.SINGLE_FILE_NAME_MISMATCH);
                    }
                    // take own record
                    merged_records.Add(sorted_records_1[m]);
                }
            }

            // re-write the summary file
            _dec_1_to_override.loaded_file_records = merged_records;
            StringBuilder sb_new = new StringBuilder();

            foreach (PartialFileRecord fr in _dec_1_to_override.loaded_file_records)
            {
                // fr.NrLocks = (DXFDistributedDecoder.HasEditingRights(_dec_1_to_override.manager, fr.Manager)) ? 1 : 0;
                fr.NrLocks = 0;
                fr.AddToExport(ref sb_new);
            }
            _dec_1_to_override.WriteSummaryFile(_dec_1_to_override.SummaryFileName, ref sb_new);

            return(ProjectMergeResult.OK);
        }
        private PartialFileRecord WriteSingleFile(string _filename_wo_ext, int _nr_locks, ComponentManagerType _user, StringBuilder _sb)
        {
            string content       = _sb.ToString();
            string filename_part = _filename_wo_ext + "_" +
                                   ComponentUtils.ComponentManagerTypeToAbbrevEN(_user) + "." +
                                   ParamStructFileExtensions.FILE_EXT_COMPONENTS;

            try
            {
                using (FileStream fs = File.Create(filename_part))
                {
                    byte[] content_B = System.Text.Encoding.UTF8.GetBytes(content);
                    fs.Write(content_B, 0, content_B.Length);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error saving partial file: " + filename_part,
                                MessageBoxButton.OK, MessageBoxImage.Error);
            }

            PartialFileRecord record = new PartialFileRecord()
            {
                FileName     = filename_part,
                Manager      = _user,
                LastModified = DateTime.Now,
                NrLocks      = _nr_locks
            };

            return(record);
        }
Beispiel #13
0
        private void ChangeAccessRecordFor(ComponentManagerType _type)
        {
            if (this.ComponentToDisplay == null)
            {
                return;
            }

            foreach (var child in this.Children)
            {
                StackPanel sp = child as StackPanel;
                if (sp == null)
                {
                    continue;
                }
                if (sp.Tag == null)
                {
                    continue;
                }
                if (!(sp.Tag is ComponentManagerType))
                {
                    continue;
                }

                ComponentManagerType sp_type = (ComponentManagerType)sp.Tag;
                if (sp_type != _type)
                {
                    continue;
                }

                string     access             = ComponentUtils.COMP_ACCESS_NONE;
                char[]     access_chars       = access.ToCharArray();
                DateTime[] access_time_stamps = new DateTime[4];

                foreach (var sp_child in sp.Children)
                {
                    TextBlockDoubleText sp_tb = sp_child as TextBlockDoubleText;
                    if (sp_tb == null)
                    {
                        continue;
                    }
                    if (sp_tb.Tag == null)
                    {
                        continue;
                    }
                    if (!(sp_tb.Tag is ComponentManagerAndAccessFlagDateTimeTriple))
                    {
                        continue;
                    }

                    ComponentManagerAndAccessFlagDateTimeTriple info = (ComponentManagerAndAccessFlagDateTimeTriple)sp_tb.Tag;
                    access_chars[info.AccessFlagIndex]       = sp_tb.Text.ToCharArray()[0];
                    access_time_stamps[info.AccessFlagIndex] = info.AccessTimeStamp_Current;
                }
                // set the ACCESS TYPE
                access = new string(access_chars);
                ComponentAccessType access_type = ComponentUtils.StringToComponentAccessType(access);

                ComponentAccessTracker tracker = this.ComponentToDisplay.AccessLocal[sp_type];
                tracker.AccessTypeFlags = access_type;
                // set the TIME STAMPS
                for (int t = 0; t < 4; t++)
                {
                    tracker.SetTimeStamp(t, access_time_stamps[t]);
                }
                this.ComponentToDisplay.AccessLocal[sp_type] = tracker;

                break;
            }
        }
Beispiel #14
0
        private void ChangeAccessFor(ComponentManagerType _type)
        {
            if (this.ComponentToDisplay == null)
            {
                return;
            }

            foreach (var child in this.Children)
            {
                StackPanel sp = child as StackPanel;
                if (sp == null)
                {
                    continue;
                }
                if (sp.Tag == null)
                {
                    continue;
                }
                if (!(sp.Tag is ComponentManagerType))
                {
                    continue;
                }

                ComponentManagerType sp_type = (ComponentManagerType)sp.Tag;
                if (sp_type != _type)
                {
                    continue;
                }

                string access       = ComponentUtils.COMP_ACCESS_NONE;
                char[] access_chars = access.ToCharArray();

                foreach (var sp_child in sp.Children)
                {
                    TextBlockDoubleText sp_tb = sp_child as TextBlockDoubleText;
                    if (sp_tb == null)
                    {
                        continue;
                    }
                    if (sp_tb.Tag == null)
                    {
                        continue;
                    }
                    if (!(sp_tb.Tag is ComponentManagerAndAccessFlagDateTimeTriple))
                    {
                        continue;
                    }

                    ComponentManagerAndAccessFlagDateTimeTriple MAtp = (ComponentManagerAndAccessFlagDateTimeTriple)sp_tb.Tag;
                    access_chars[MAtp.AccessFlagIndex] = sp_tb.Text.ToCharArray()[0];
                }
                access = new string(access_chars);
                ComponentAccessType access_type = ComponentUtils.StringToComponentAccessType(access);

                ComponentAccessTracker tracker = this.ComponentToDisplay.AccessLocal[sp_type];
                tracker.AccessTypeFlags = access_type;
                this.ComponentToDisplay.AccessLocal[sp_type] = tracker;

                break;
            }
        }
Beispiel #15
0
        public static void UpdateComponentFromMessage(Component _comp, ComponentMessage _cmsg,
                                                      ComponentManagerType _user, bool _add_missing_params)
        {
            if (_comp == null || _cmsg == null)
            {
                return;
            }
            if (_cmsg.CompID > -1 && _comp.ID != _cmsg.CompID)
            {
                return;
            }

            // 1. TRANSFER THE GEOMETRIC RELATIONSHIPS
            // extract the main geometric relationship type (even for multiple relationships, there should only be ONE type)
            List <InterProcCommunication.Specific.GeometricRelationship> geom_rels = new List <InterProcCommunication.Specific.GeometricRelationship>(_cmsg.GeomRelationships);

            if (geom_rels.Count == 0)
            {
                // ... Houston, we have a problem!!!
                // This should not happen!
            }
            else
            {
                // combine the incoming relationships with processing info
                Dictionary <InterProcCommunication.Specific.GeometricRelationship, bool> geom_rels_processing = new Dictionary <GeometricRelationship, bool>();
                foreach (InterProcCommunication.Specific.GeometricRelationship gr in geom_rels)
                {
                    geom_rels_processing.Add(gr, false);
                }
                // combine the old relationships with updating info (is used to remove obsolete relationships)
                List <bool> old_geom_rels_updating = Enumerable.Repeat(false, _comp.R2GInstances.Count).ToList();

                // update the existing geometric relationship(s)
                for (int i = 0; i < _comp.R2GInstances.Count; i++)
                {
                    InterProcCommunication.Specific.GeometricRelationship gr_corresponding = geom_rels.FirstOrDefault(x => x.GrID == _comp.R2GInstances[i].ID);
                    if (gr_corresponding != null)
                    {
                        ParameterStructure.Geometry.Relation2GeomType gr_type = ParameterStructure.Geometry.GeometryUtils.StringToRelationship2Geometry(InterProcCommunication.Specific.GeometryUtils.Relationship2GeometryToString(gr_corresponding.GrState.Type));
                        _comp.R2GInstances[i].Name  = gr_corresponding.GrName;
                        _comp.R2GInstances[i].State = new ParameterStructure.Geometry.Relation2GeomState {
                            IsRealized = gr_corresponding.GrState.IsRealized, Type = gr_type
                        };
                        _comp.R2GInstances[i].GeomIDs   = gr_corresponding.GrIds;
                        _comp.R2GInstances[i].GeomCS    = gr_corresponding.GrUCS;
                        _comp.R2GInstances[i].TRm_WC2LC = gr_corresponding.GrTrWC2LC;
                        _comp.R2GInstances[i].TRm_LC2WC = gr_corresponding.GrTrLC2WC;

                        // instance info cannot change, except for the path
                        _comp.R2GInstances[i].InstancePath = new List <System.Windows.Media.Media3D.Point3D>(gr_corresponding.InstPath);

                        geom_rels_processing[gr_corresponding] = true;
                        old_geom_rels_updating[i] = true;
                    }
                }

                // add new relationships
                List <ParameterStructure.Geometry.GeometricRelationship> to_be_added = new List <ParameterStructure.Geometry.GeometricRelationship>();
                foreach (var entry in geom_rels_processing)
                {
                    if (entry.Value)
                    {
                        continue; // skip processed
                    }
                    ParameterStructure.Geometry.Relation2GeomType  type  = ParameterStructure.Geometry.GeometryUtils.StringToRelationship2Geometry(InterProcCommunication.Specific.GeometryUtils.Relationship2GeometryToString(entry.Key.GrState.Type));
                    ParameterStructure.Geometry.Relation2GeomState state = new ParameterStructure.Geometry.Relation2GeomState {
                        Type = type, IsRealized = entry.Key.GrState.IsRealized
                    };
                    ParameterStructure.Geometry.GeometricRelationship new_gr = new ParameterStructure.Geometry.GeometricRelationship(entry.Key.GrName, state,
                                                                                                                                     entry.Key.GrIds, entry.Key.GrUCS, entry.Key.GrTrWC2LC, entry.Key.GrTrLC2WC);
                    new_gr.InstancePath = new List <System.Windows.Media.Media3D.Point3D>(entry.Key.InstPath); // added 06.09.2017
                    to_be_added.Add(new_gr);
                }

                // communicate to component (performs the deleletion of the relationships that were not updated)
                _comp.UpdateGeometricRelationships(old_geom_rels_updating, to_be_added, _user);
            }

            // 2. TRANSFER THE PARAMETERS
            Dictionary <string, double> p_dict = Comp2GeomCommunication.GetReservedParamDictionary(geom_rels[0].GrState.Type);

            foreach (var entry in p_dict)
            {
                // retrieve value
                double val = _cmsg[entry.Key];
                if (double.IsNaN(val))
                {
                    continue;
                }

                // transfer to component
                _comp.SetParameterValue(entry.Key, val, _user, _add_missing_params);
            }
        }
        public void UpdateGeometricRelationships(List <bool> _to_retain, List <GeometricRelationship> _to_add, ComponentManagerType _user)
        {
            // check if the user has writing access
            bool success = this.RecordWritingAccess(_user);

            if (!success)
            {
                return;
            }

            // 1.mark obsolete relationships for removal
            if (_to_retain == null || _to_retain.Count != this.R2GInstances.Count)
            {
                return;
            }

            for (int i = 0; i < this.R2GInstances.Count; i++)
            {
                if (_to_retain[i])
                {
                    continue;
                }

                this.R2GInstances[i].UpdateState = GeometricRelationshipUpdateState.TO_BE_DELETED;
            }

            // 2. add new relationships and mark them
            if (_to_add != null)
            {
                foreach (GeometricRelationship gr in _to_add)
                {
                    gr.UpdateState = GeometricRelationshipUpdateState.NEW;
                    this.R2GInstances.Add(gr);
                }
            }

            // 3. perform the removal
            List <GeometricRelationship> grs_new = new List <GeometricRelationship>();

            foreach (GeometricRelationship gr_old in this.R2GInstances)
            {
                if (gr_old.UpdateState != GeometricRelationshipUpdateState.TO_BE_DELETED)
                {
                    gr_old.UpdateState = GeometricRelationshipUpdateState.NEUTRAL;
                    grs_new.Add(gr_old);
                }
            }

            // mark the new representative relationship
            if (grs_new[0].ID != this.R2GInstances[0].ID)
            {
                grs_new[0].PropertyChanged += main_r2g_PropertyChanged;
            }

            // switch
            this.R2GInstances = new List <GeometricRelationship>(grs_new);
            this.R2GMainState = this.R2GInstances[0].State;
        }