コード例 #1
0
        public void CopyPlacableContent(GeometricRelationship _original)
        {
            this.gr_ucs     = _original.gr_ucs;
            this.gr_trWC2LC = _original.gr_trWC2LC;
            this.gr_trLC2WC = _original.gr_trLC2WC;

            this.inst_path = new List <Point3D>(_original.InstPath);
        }
コード例 #2
0
        public static ComponentMessage AssembleComponentMessage(Component _comp, MessagePositionInSeq _pos, long _parent_id)
        {
            if (_comp == null)
            {
                return(null);
            }
            if (_comp.R2GInstances == null || _comp.R2GInstances.Count == 0)
            {
                return(null);
            }

            List <ComponentMessage> messages = new List <ComponentMessage>();

            // translate Pt.1
            // translate the geometry type(s)
            Relation2GeomType gr_type_main = Relation2GeomType.NONE;
            List <InterProcCommunication.Specific.GeometricRelationship> translated_geom_relationships = new List <InterProcCommunication.Specific.GeometricRelationship>();

            foreach (ParameterStructure.Geometry.GeometricRelationship gr in _comp.R2GInstances)
            {
                Relation2GeomType gr_type = InterProcCommunication.Specific.GeometryUtils.StringToRelationship2Geometry(ParameterStructure.Geometry.GeometryUtils.Relationship2GeometryToString(gr.State.Type));
                if (gr_type_main == Relation2GeomType.NONE)
                {
                    gr_type_main = gr_type;
                }
                Relation2GeomState gr_state = new Relation2GeomState {
                    Type = gr_type, IsRealized = gr.State.IsRealized
                };
                InterProcCommunication.Specific.GeometricRelationship gr_translated = new InterProcCommunication.Specific.GeometricRelationship(gr.ID, gr.Name, gr_state, gr.GeomIDs, gr.GeomCS, gr.TRm_WC2LC, gr.TRm_LC2WC,
                                                                                                                                                gr.InstanceSize, gr.InstanceNWElementID, gr.InstanceNWElementName, gr.InstancePath);
                translated_geom_relationships.Add(gr_translated);
            }

            // translate Pt.2
            // assemble the parameter dictionary according to geometry relationship type
            Dictionary <string, double> guide  = Comp2GeomCommunication.GetReservedParamDictionary(gr_type_main);
            Dictionary <string, double> p_dict = Comp2GeomCommunication.GetReservedParamDictionary(gr_type_main);

            foreach (var entry in guide)
            {
                Parameter p = _comp.ContainedParameters.Values.FirstOrDefault(x => x.Name == entry.Key);
                if (p != null)
                {
                    p_dict[entry.Key] = p.ValueCurrent;
                }
            }

            // done
            return(new ComponentMessage(_pos, _parent_id, _comp.ID, _comp.IsAutomaticallyGenerated, _comp.CurrentSlot + " " + _comp.Name + " " + _comp.Description,
                                        _comp.GetIdsOfAllReferencedComponents(), p_dict, translated_geom_relationships, -1L, -1L, MessageAction.NONE));
        }
コード例 #3
0
        public GeometricRelationship(GeometricRelationship _original)
        {
            this.gr_id    = _original.gr_id;
            this.gr_name  = _original.gr_name;
            this.gr_state = new Relation2GeomState {
                Type = _original.gr_state.Type, IsRealized = false
            };
            this.gr_ids     = _original.gr_ids;
            this.gr_ucs     = _original.gr_ucs;
            this.gr_trWC2LC = _original.gr_trWC2LC;
            this.gr_trLC2WC = _original.gr_trLC2WC;

            this.inst_size     = new List <double>(_original.InstSize);
            this.inst_nwe_id   = _original.InstNWeId;
            this.inst_nwe_name = _original.InstNWeName;
            this.inst_path     = new List <Point3D>(_original.InstPath);
        }
コード例 #4
0
        public static bool HaveListsWSameContent(List <GeometricRelationship> _lgr1, List <GeometricRelationship> _lgr2)
        {
            if (_lgr1 == null && _lgr2 != null)
            {
                return(false);
            }
            if (_lgr1 != null && _lgr2 == null)
            {
                return(false);
            }
            if (_lgr1 == null && _lgr2 == null)
            {
                return(true);
            }

            int nrL1 = _lgr1.Count;

            if (nrL1 != _lgr2.Count)
            {
                return(false);
            }

            GeometricRelationshipComparer comparer = new GeometricRelationshipComparer();

            List <GeometricRelationship> l1_sorted = new List <GeometricRelationship>(_lgr1);

            l1_sorted.Sort(comparer);
            List <GeometricRelationship> l2_sorted = new List <GeometricRelationship>(_lgr2);

            l2_sorted.Sort(comparer);

            bool same_lists = l1_sorted.Zip(l2_sorted, (x, y) => GeometricRelationship.HaveSameContent(x, y)).Aggregate(true, (a, x) => a && x);

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

            return(true);
        }
コード例 #5
0
        /// <summary>
        /// <para>This method compares two geometric relationships according to content, NOT id or name.</para>
        /// <para>The transformation matrices are not being compared for now...</para>
        /// </summary>
        /// <param name="_gr1"></param>
        /// <param name="_gr2"></param>
        /// <returns></returns>
        public static bool HaveSameContent(GeometricRelationship _gr1, GeometricRelationship _gr2)
        {
            if (_gr1 == null && _gr2 == null)
            {
                return(true);
            }
            if (_gr1 == null && _gr2 != null)
            {
                return(false);
            }
            if (_gr1 != null && _gr2 == null)
            {
                return(false);
            }

            if (_gr1.gr_state.Type != _gr2.gr_state.Type)
            {
                return(false);
            }
            if (_gr1.gr_state.IsRealized != _gr2.gr_state.IsRealized)
            {
                return(false);
            }

            if (_gr1.gr_ids.X != _gr2.gr_ids.X || _gr1.gr_ids.Y != _gr2.gr_ids.Y || _gr1.gr_ids.Z != _gr2.gr_ids.Z)
            {
                return(false);
            }

            // if (_gr1.gr_ucs != _gr2.gr_ucs) return false; // checks for EXACT equality -> NaN and rounding errors can lead to false negatives
            if (!GeometricTransformations.LogicalEquality(_gr1.gr_ucs, _gr2.gr_ucs))
            {
                return(false);
            }

            // skipping transformation matrices for now...

            if (_gr1.inst_size == null && _gr2.inst_size != null)
            {
                return(false);
            }
            if (_gr1.inst_size != null && _gr2.inst_size == null)
            {
                return(false);
            }
            if (_gr1.inst_size != null && _gr2.inst_size != null)
            {
                int nrSize = _gr1.inst_size.Count;
                if (nrSize != _gr2.inst_size.Count)
                {
                    return(false);
                }

                if (nrSize > 0)
                {
                    bool same_size = _gr1.inst_size.SequenceEqual(_gr2.inst_size);
                    if (!same_size)
                    {
                        return(false);
                    }
                }
            }

            if (_gr1.inst_nwe_id != _gr2.inst_nwe_id)
            {
                return(false);
            }
            if (_gr1.inst_nwe_name != _gr2.inst_nwe_name)
            {
                return(false);
            }

            if (_gr1.inst_path == null && _gr2.inst_path != null)
            {
                return(false);
            }
            if (_gr1.inst_path != null && _gr2.inst_path == null)
            {
                return(false);
            }
            if (_gr1.inst_path != null && _gr2.inst_path != null)
            {
                int nrPathP = _gr1.inst_path.Count;
                if (nrPathP != _gr2.inst_path.Count)
                {
                    return(false);
                }

                if (nrPathP > 0)
                {
                    bool same_path = _gr1.inst_path.Zip(_gr2.inst_path, (x, y) => GeometricTransformations.LogicalEquality(x, y)).Aggregate(true, (a, x) => a && x);
                    if (!same_path)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
コード例 #6
0
        /// <summary>
        /// <para>This method should be used to retrieve the id of an automatically generated component.</para>
        /// </summary>
        /// <param name="_cmsg_query"></param>
        /// <param name="_cmsg_test"></param>
        /// <returns></returns>
        public static bool HaveSameContent(ComponentMessage _cmsg_query, ComponentMessage _cmsg_test)
        {
            if (_cmsg_query == null && _cmsg_test == null)
            {
                return(true);
            }
            if (_cmsg_query != null && _cmsg_test == null)
            {
                return(false);
            }
            if (_cmsg_query == null && _cmsg_test != null)
            {
                return(false);
            }

            // component properties
            if (_cmsg_query.comp_automatically_generated != _cmsg_test.comp_automatically_generated)
            {
                return(false);
            }
            // if (_cmsg_query.comp_descr != _cmsg_test.comp_descr) return false; this cannot be checked

            if (_cmsg_query.comp_ref_ids != null && _cmsg_test.comp_ref_ids == null)
            {
                return(false);
            }
            if (_cmsg_query.comp_ref_ids == null && _cmsg_test.comp_ref_ids != null)
            {
                return(false);
            }
            if (_cmsg_query.comp_ref_ids != null && _cmsg_test.comp_ref_ids != null)
            {
                int nrRefs = _cmsg_query.comp_ref_ids.Count;
                if (_cmsg_test.comp_ref_ids.Count != nrRefs)
                {
                    return(false);
                }

                if (nrRefs > 0)
                {
                    bool same_comp_ref_ids = _cmsg_query.comp_ref_ids.Zip(_cmsg_test.comp_ref_ids, (x, y) => x == y).Aggregate(true, (a, x) => a && x);
                    if (!same_comp_ref_ids)
                    {
                        return(false);
                    }
                }
            }

            bool same_comp_params = ComponentMessage.LogicalEquality(_cmsg_query.comp_params, _cmsg_test.comp_params);

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

            // component geometric relationships
            bool same_gr = GeometricRelationship.HaveListsWSameContent(_cmsg_query.geom_relationships, _cmsg_test.geom_relationships);

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

            return(true);
        }
コード例 #7
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);
            }
        }
コード例 #8
0
        private void ParseComponentMessage()
        {
            switch (this.FCode)
            {
            case (int)MessageCode.ENTITY_START:
                // start of entity ... do nothing
                break;

            case (int)MessageCode.MSG_POSITION:
                this.p_msg_pos = ComponentMessage.StringToMessagePositionInSeq(this.FValue);
                break;

            case (int)MessageCode.MSG_COMP_PARENT_ID:
                this.p_comp_parent_id = this.LongValue();
                break;

            case (int)MessageCode.MSG_COMP_REPRESENTATION_ID:
                this.p_comp_repres_id = this.LongValue();
                break;

            case (int)MessageCode.MSG_COMP_REPRESENTATION_PARENT_ID:
                this.p_comp_repres_parent_id = this.LongValue();
                break;

            case (int)MessageCode.MSG_COMP_REF_IDS_SEQUENCE:
                this.nr_comp_ref_ids = this.IntValue();
                break;

            case (int)MessageCode.MSG_COMP_REF_ID:
                if (this.nr_comp_ref_ids > this.nr_comp_ref_ids_read)
                {
                    this.p_comp_ref_ids.Add(this.LongValue());
                    this.nr_comp_ref_ids_read++;
                }
                break;

            case (int)MessageCode.MSG_COMP_ACTION:
                this.p_msg_action_to_take = ComponentMessage.StringToMessageAction(this.FValue);
                break;

            case (int)MessageCode.COMP_ID:
                this.p_comp_id = this.LongValue();
                break;

            case (int)MessageCode.COMP_AUTOM_GEN:
                this.p_comp_autom_gen = (this.IntValue() == 1);
                break;

            case (int)MessageCode.COMP_DESCR:
                this.p_comp_descr = this.FValue;
                break;

            case (int)MessageCode.PARAM_SEQUENCE:
                this.nr_comp_params = this.IntValue();
                break;

            case (int)MessageCode.PARAM_NAME:
                this.param_name = this.FValue;
                break;

            case (int)MessageCode.PARAM_VALUE:
                if (!string.IsNullOrEmpty(this.param_name) && this.nr_comp_params > this.nr_comp_params_read)
                {
                    double param_value = this.DoubleValue();
                    this.p_comp_params.Add(this.param_name, param_value);
                    this.param_name = string.Empty;
                    this.nr_comp_params_read++;
                }
                break;

            case (int)MessageCode.GR_SEQUENCE:
                this.nr_geom_relationships = this.IntValue();
                break;

            case (int)MessageCode.GR_ID:
                this.p_gr_id = this.LongValue();
                break;

            case (int)MessageCode.GR_NAME:
                this.p_gr_name = this.FValue;
                break;

            case (int)MessageCode.GR_STATE_TYPE:
                this.p_gr_state_type = GeometryUtils.StringToRelationship2Geometry(this.FValue);
                break;

            case (int)MessageCode.GR_STATE_ISREALIZED:
                this.p_gr_state_isRealized = (this.IntValue() == 1);
                break;

            case (int)MessageCode.GR_GEOM_IDS_X:
                this.p_gr_ids.X = this.IntValue();
                break;

            case (int)MessageCode.GR_GEOM_IDS_Y:
                this.p_gr_ids.Y = this.IntValue();
                break;

            case (int)MessageCode.GR_GEOM_IDS_Z:
                this.p_gr_ids.Z = this.IntValue();
                break;

            case (int)MessageCode.GR_GEOM_IDS_W:
                this.p_gr_ids.W = this.IntValue();
                break;

            case (int)MessageCode.GR_GEOM_CS:
                this.p_gr_ucs = Matrix3D.Parse(this.FValue);
                break;

            // instance information
            case (int)MessageCode.GR_INST_SIZE:
                this.pp_gr_nr_inst_size = this.IntValue();
                break;

            case (int)MessageCode.GR_INST_NWE_ID:
                this.p_gr_inst_nwe_id = this.LongValue();
                break;

            case (int)MessageCode.GR_INST_NWE_NAME:
                this.p_gr_inst_nwe_name = this.FValue;
                break;

            case (int)MessageCode.GR_INST_PATH:
                this.pp_gr_nr_inst_path = this.IntValue();
                break;

            case (int)MessageCode.GR_INST_VAL_X:
                if (this.pp_gr_nr_inst_size > this.p_gr_inst_size.Count)
                {
                    this.p_gr_inst_size.Add(this.DoubleValue());
                }
                else if (this.pp_gr_nr_inst_path > this.p_gr_inst_path.Count)
                {
                    this.pp_gr_inst_path_current_vertex.X = this.DoubleValue();
                }
                break;

            case (int)MessageCode.GR_INST_VAL_Y:
                if (this.pp_gr_nr_inst_path > this.p_gr_inst_path.Count)
                {
                    this.pp_gr_inst_path_current_vertex.Y = this.DoubleValue();
                }
                break;

            case (int)MessageCode.GR_INST_VAL_Z:
                if (this.pp_gr_nr_inst_path > this.p_gr_inst_path.Count)
                {
                    this.pp_gr_inst_path_current_vertex.Z = this.DoubleValue();
                    this.p_gr_inst_path.Add(this.pp_gr_inst_path_current_vertex);
                    this.pp_gr_inst_path_current_vertex = new Point3D(0, 0, 0);
                }
                break;

            // transforms
            case (int)MessageCode.GR_TRANSF_WC2LC:
                this.p_gr_trWC2LC = Matrix3D.Parse(this.FValue);
                break;

            case (int)MessageCode.GR_TRANSF_LC2WC:
                // should come last for every GeometricRelationship
                this.p_gr_trLC2WC = Matrix3D.Parse(this.FValue);
                if (this.nr_geom_relationships > this.nr_geom_relationships_read)
                {
                    Relation2GeomState gr_state = new Relation2GeomState {
                        Type = this.p_gr_state_type, IsRealized = this.p_gr_state_isRealized
                    };
                    GeometricRelationship gr = new GeometricRelationship(this.p_gr_id, this.p_gr_name, gr_state, this.p_gr_ids,
                                                                         this.p_gr_ucs, this.p_gr_trWC2LC, this.p_gr_trLC2WC,
                                                                         this.p_gr_inst_size, this.p_gr_inst_nwe_id, this.p_gr_inst_nwe_name, this.p_gr_inst_path);
                    this.geom_relationships.Add(gr);
                    this.nr_geom_relationships_read++;
                    this.p_gr_inst_size = new List <double>();
                    this.p_gr_inst_path = new List <Point3D>();
                }
                break;
            }
        }