public ComponentMessage(MessagePositionInSeq _pos, long _comp_parent_id, long _comp_id, bool _comp_ag, string _comp_descr,
                                List <long> _ref_ids, Dictionary <string, double> _comp_params, List <GeometricRelationship> _geom_rel,
                                long _comp_rep_id, long _comp_rep_parent_id, MessageAction _action_to_take)
        {
            // structural info
            this.msg_pos            = _pos;
            this.comp_parent_id     = _comp_parent_id;
            this.comp_rep_id        = _comp_rep_id;
            this.comp_rep_parent_id = _comp_rep_parent_id;
            this.action_to_take     = _action_to_take;

            // component info
            this.comp_id = _comp_id;
            this.comp_automatically_generated = _comp_ag;
            this.comp_descr   = _comp_descr;
            this.comp_ref_ids = _ref_ids;

            this.comp_params = _comp_params;

            this.geom_relationships = new List <GeometricRelationship>();
            if (_geom_rel != null && _geom_rel.Count > 0)
            {
                this.geom_relationships = new List <GeometricRelationship>(_geom_rel);
            }
        }
 public static ComponentMessage GetDummyMessage(MessagePositionInSeq _pos)
 {
     return(new ComponentMessage(_pos, -1L, -1L, true, "Dummy Message", new List <long>(), new Dictionary <string, double>(),
                                 new List <GeometricRelationship> {
         new GeometricRelationship(-1L, "Dummy", new Relation2GeomState {
             Type = Relation2GeomType.NONE, IsRealized = false
         },
                                   new Point4D(-1, -1, -1, -1), Matrix3D.Identity, Matrix3D.Identity, Matrix3D.Identity)
     }, -1L, -1L, MessageAction.NONE));
 }
Beispiel #3
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));
        }
Beispiel #4
0
        public List <ComponentMessage> ExtractMessagesFrom(CompRep _cr)
        {
            List <ComponentMessage> extracted = new List <ComponentMessage>();

            if (_cr == null)
            {
                return(extracted);
            }

            CompRepInfo cri = _cr as CompRepInfo;

            if (cri == null)
            {
                return(extracted);
            }

            List <CompRepInfo> cr_subCRs = cri.GetFlatListOfSubCompReps();
            int nrSub = cr_subCRs.Count;

            if (nrSub == 0)
            {
                ComponentMessage msg = cri.ExtractMessage(MessagePositionInSeq.SINGLE_MESSAGE);
                if (msg != null)
                {
                    extracted.Add(msg);
                }
            }
            else
            {
                ComponentMessage msg = cri.ExtractMessage(MessagePositionInSeq.SEQUENCE_START_MESSAGE);
                if (msg != null)
                {
                    extracted.Add(msg);
                }
                for (int i = 0; i < nrSub; i++)
                {
                    MessagePositionInSeq pos_current = (i == (nrSub - 1)) ? MessagePositionInSeq.SEQUENCE_END_MESSAGE : MessagePositionInSeq.MESSAGE_INSIDE_SEQUENCE;
                    ComponentMessage     msg_i       = cr_subCRs[i].ExtractMessage(pos_current);
                    if (msg_i != null)
                    {
                        extracted.Add(msg_i);
                    }
                }
            }

            return(extracted);
        }
Beispiel #5
0
        private void Reset()
        {
            // parsed message STRUCTURE
            this.p_msg_pos               = MessagePositionInSeq.UNKNOWN;
            this.p_comp_parent_id        = -1;
            this.p_comp_repres_id        = -1;
            this.p_comp_repres_parent_id = -1;

            this.nr_comp_ref_ids      = 0;
            this.nr_comp_ref_ids_read = 0;
            this.p_comp_ref_ids       = new List <long>();

            this.p_msg_action_to_take = MessageAction.NONE;

            // parsed message CONTENT
            this.p_comp_id        = -1;
            this.p_comp_autom_gen = false;
            this.p_comp_descr     = "ComponentMessage";
            this.p_comp_params    = new Dictionary <string, double>();

            this.nr_comp_params      = 0;
            this.nr_comp_params_read = 0;
            this.param_name          = string.Empty;

            this.nr_geom_relationships      = 0;
            this.nr_geom_relationships_read = 0;

            this.p_gr_id               = -1;
            this.p_gr_name             = "Geometric Relationship";
            this.p_gr_state_type       = Relation2GeomType.NONE;
            this.p_gr_state_isRealized = false;
            this.p_gr_ids              = new Point4D(-1, -1, -1, -1);
            this.p_gr_ucs              = Matrix3D.Identity;
            this.p_gr_trWC2LC          = Matrix3D.Identity;
            this.p_gr_trLC2WC          = Matrix3D.Identity;

            this.p_gr_inst_size                 = new List <double>();
            this.pp_gr_nr_inst_size             = 0;
            this.p_gr_inst_nwe_id               = -1L;
            this.p_gr_inst_nwe_name             = "NW_Element";
            this.p_gr_inst_path                 = new List <Point3D>();
            this.pp_gr_nr_inst_path             = 0;
            this.pp_gr_inst_path_current_vertex = new Point3D(0, 0, 0);

            this.geom_relationships = new List <GeometricRelationship>();
        }
        public static string MessagePositionInSeqToString(MessagePositionInSeq _mpis)
        {
            switch (_mpis)
            {
            case MessagePositionInSeq.SINGLE_MESSAGE:
                return("SINGLE_MESSAGE");

            case MessagePositionInSeq.SEQUENCE_START_MESSAGE:
                return("SEQUENCE_START_MESSAGE");

            case MessagePositionInSeq.SEQUENCE_END_MESSAGE:
                return("SEQUENCE_END_MESSAGE");

            case MessagePositionInSeq.MESSAGE_INSIDE_SEQUENCE:
                return("MESSAGE_INSIDE_SEQUENCE");

            default:
                return("UNKNOWN");
            }
        }
Beispiel #7
0
        public static List <ComponentMessage> AssembleMultipleComponentMessages(Component _comp_main)
        {
            List <ComponentMessage> messages = new List <ComponentMessage>();

            if (_comp_main == null)
            {
                return(messages);
            }

            // get all subcomponents w geometric relationships and translate them (recursive)
            Dictionary <Component, long> relevant_subcomps = _comp_main.GetSubcompsWGeometricRelationships();
            int nr_subcomps = relevant_subcomps.Count;

            // translate the main component (set the parent as -1, event if it exists -> has no effect on return)
            ComponentMessage cmsg_main;

            if (nr_subcomps == 0)
            {
                cmsg_main = AssembleComponentMessage(_comp_main, MessagePositionInSeq.SINGLE_MESSAGE, -1);
            }
            else
            {
                cmsg_main = AssembleComponentMessage(_comp_main, MessagePositionInSeq.SEQUENCE_START_MESSAGE, -1);
            }
            messages.Add(cmsg_main);

            for (int i = 0; i < nr_subcomps; i++)
            {
                MessagePositionInSeq pos = MessagePositionInSeq.MESSAGE_INSIDE_SEQUENCE;
                if (i == nr_subcomps - 1)
                {
                    pos = MessagePositionInSeq.SEQUENCE_END_MESSAGE;
                }

                ComponentMessage cmsg_i = AssembleComponentMessage(relevant_subcomps.ElementAt(i).Key, pos, relevant_subcomps.ElementAt(i).Value);
                messages.Add(cmsg_i);
            }

            return(messages);
        }
Beispiel #8
0
        public List <ComponentMessage> ExtractMessagesForReferenceUpdateFrom(CompRep _cr)
        {
            List <ComponentMessage> extracted = new List <ComponentMessage>();

            if (_cr == null)
            {
                return(extracted);
            }

            CompRepInfo cri = _cr as CompRepInfo;

            if (cri == null)
            {
                return(extracted);
            }

            // call 'ExtractMessage' to force synchronization with geometry
            ComponentMessage msg1 = cri.ExtractMessage(MessagePositionInSeq.SINGLE_MESSAGE);
            // .............................................................................

            List <CompRepInfo> cr_subCRs     = cri.GetFlatListOfSubCompReps();
            List <CompRepInfo> cr_CRs_w_refs = cr_subCRs.Where(x => x.Comp_RefCompIDs.Count > 0).ToList();

            if (cri.Comp_RefCompIDs.Count > 0)
            {
                cr_CRs_w_refs.Insert(0, cri);
            }

            int nrMsg = cr_CRs_w_refs.Count;

            if (nrMsg == 1)
            {
                ComponentMessage msg = cr_CRs_w_refs[0].ExtractMessage(MessagePositionInSeq.SINGLE_MESSAGE);
                if (msg != null)
                {
                    extracted.Add(msg);
                }
            }
            else if (nrMsg > 1)
            {
                for (int i = 0; i < nrMsg; i++)
                {
                    MessagePositionInSeq pos_current = MessagePositionInSeq.SEQUENCE_START_MESSAGE;
                    if (i > 0 && i < (nrMsg - 1))
                    {
                        pos_current = MessagePositionInSeq.MESSAGE_INSIDE_SEQUENCE;
                    }
                    else if (i == (nrMsg - 1))
                    {
                        pos_current = MessagePositionInSeq.SEQUENCE_END_MESSAGE;
                    }

                    ComponentMessage msg_i = cr_CRs_w_refs[i].ExtractMessage(pos_current);
                    if (msg_i != null)
                    {
                        extracted.Add(msg_i);
                    }
                }
            }

            return(extracted);
        }
Beispiel #9
0
        public static List <ComponentMessage> AssembleUnrelatedComponentMessages(List <Component> _comps, ComponentFactory _factory)
        {
            List <ComponentMessage> messages = new List <ComponentMessage>();

            if (_comps == null)
            {
                return(messages);
            }

            // get the parent ids
            List <long> parent_ids = new List <long>();

            if (_factory != null)
            {
                foreach (Component c in _comps)
                {
                    long             c_parent_id  = -1L;
                    List <Component> parent_chain = _factory.GetParentComponentChain(c);
                    if (parent_chain.Count > 1)
                    {
                        Component direct_parent = parent_chain[parent_chain.Count - 2];
                        if (direct_parent != null)
                        {
                            c_parent_id = direct_parent.ID;
                        }
                    }
                    parent_ids.Add(c_parent_id);
                }
            }
            else
            {
                parent_ids = Enumerable.Repeat(-1L, _comps.Count).ToList();
            }

            // assemble the messages
            int nrM = _comps.Count;

            if (nrM == 1)
            {
                messages.Add(ComponentMessageTranslator.AssembleComponentMessage(_comps[0], MessagePositionInSeq.SINGLE_MESSAGE, parent_ids[0]));
            }
            else
            {
                for (int i = 0; i < nrM; i++)
                {
                    MessagePositionInSeq pos = MessagePositionInSeq.UNKNOWN;
                    if (i == 0)
                    {
                        pos = MessagePositionInSeq.SEQUENCE_START_MESSAGE;
                    }
                    else if (i == nrM - 1)
                    {
                        pos = MessagePositionInSeq.SEQUENCE_END_MESSAGE;
                    }
                    else
                    {
                        pos = MessagePositionInSeq.MESSAGE_INSIDE_SEQUENCE;
                    }

                    messages.Add(ComponentMessageTranslator.AssembleComponentMessage(_comps[i], pos, parent_ids[i]));
                }
            }

            return(messages);
        }
Beispiel #10
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;
            }
        }