private void RemovePlacementBasedReferencesToInstanceFromOtherComponents(GeometricRelationship _gr)
        {
            if (this.ReferencedBy == null || this.ReferencedBy.Count == 0)
            {
                return;
            }

            // check if _gr is the only placement in the geometry with id _gr.GeomIDs.X
            List <GeometricRelationship> other_placements = this.R2GInstances.FindAll(x => x.ID != _gr.ID && x.State.Type == _gr.State.Type && x.GeomIDs.X == _gr.GeomIDs.X).ToList();

            if (other_placements == null && other_placements.Count > 0)
            {
                return;
            }

            List <Component> holding_placement_based_refs = this.ReferencedBy.Where(x => x.R2GInstances[0].State.Type == Relation2GeomType.DESCRIBES && x.R2GInstances[0].GeomIDs.X == _gr.GeomIDs.X).ToList();

            if (holding_placement_based_refs == null || holding_placement_based_refs.Count == 0)
            {
                return;
            }

            foreach (Component c in holding_placement_based_refs)
            {
                c.RemoveReferencedComponent_Level0(this, true, ComponentManagerType.ADMINISTRATOR);
            }
        }
        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>
        /// <para>For calculating with the parameter slots in instances w/o affecting the component and its parameters.</para>
        /// <para>Performed recursively in case the sub-components contain calculations themselves.</para>
        /// </summary>
        /// <param name="_container"></param>
        internal void ExecuteCalculationChainWoArtefacts(FlNetElement _container)
        {
            if (_container == null)
            {
                return;
            }
            GeometricRelationship instance = this.R2GInstances.FirstOrDefault(x => x.InstanceNWElementID == _container.ID);

            if (instance == null)
            {
                return;
            }

            // populate the parameter values
            if (instance.InstanceParamValues == null || instance.InstanceParamValues.Count == 0)
            {
                this.UpdateInstanceIn(_container, new Point(0, 0), false);
            }

            // recursion
            this.ExecuteCalculationChainForInstance(instance);

            // result transfer params -> size, if necessary
            instance.ApplySizeTransferSettings();
        }
        internal GeometricRelationship UpdateInstanceIn(FlNetElement _container, Point _offset, bool _reset)
        {
            if (_container == null)
            {
                return(null);
            }

            GeometricRelationship gr = this.R2GInstances.FirstOrDefault(x => x.InstanceNWElementID == _container.ID);

            if (gr == null)
            {
                return(null);
            }
            if (gr.InstanceNWElementID != _container.ID)
            {
                return(null);
            }

            // assemble parameters to pass to the instance
            Dictionary <string, double> param_slots = this.ExtractParameterValues();

            // size is a special case !!!
            param_slots[Parameter.Parameter.RP_HEIGHT_MIN] = gr.InstanceSize[0];
            param_slots[Parameter.Parameter.RP_WIDTH_MIN]  = gr.InstanceSize[1];
            param_slots[Parameter.Parameter.RP_LENGTH_MIN] = gr.InstanceSize[2];
            param_slots[Parameter.Parameter.RP_HEIGHT_MAX] = gr.InstanceSize[3];
            param_slots[Parameter.Parameter.RP_WIDTH_MAX]  = gr.InstanceSize[4];
            param_slots[Parameter.Parameter.RP_LENGTH_MAX] = gr.InstanceSize[5];

            // controlled reset
            if (gr.InstanceParamValues == null)
            {
                gr.InstanceParamValues = param_slots;
                return(gr);
            }

            if (_reset)
            {
                gr.InstanceParamValues = param_slots;
                gr.UpdatePositionFrom(_container, _offset, Component.SCALE_PIXEL_TO_M);
                return(gr);
            }
            else
            {
                foreach (var entry in param_slots)
                {
                    if (!(gr.InstanceParamValues.ContainsKey(entry.Key)))
                    {
                        gr.InstanceParamValues.Add(entry.Key, entry.Value);
                    }
                }
                gr.ApplySizeTransferSettings();
            }

            return(gr);
        }
        internal GeometricRelationship UpdateInstanceToContainerBinding(long _container_id, long _container_new_id, string _container_new_name)
        {
            GeometricRelationship gr = this.R2GInstances.FirstOrDefault(x => x.InstanceNWElementID == _container_id);

            if (gr == null)
            {
                return(null);
            }

            gr.UpdateContainerInfo(_container_new_id, _container_new_name);
            return(gr);
        }
Exemple #6
0
        protected static StructureNode CreateFrom(GeometricRelationship _node_source, StructureNode _sn_parent)
        {
            if (_node_source == null)
            {
                return(null);
            }

            List <HierarchicalContainer> g_content = _node_source.GeometricContent;

            if (g_content.Count == 0)
            {
                return(null);
            }

            // a geometric relationship node cannot exist w/o parent component
            if (_sn_parent == null)
            {
                return(null);
            }
            if (!_sn_parent.ContentType_Used || _sn_parent.ContentType == null)
            {
                return(null);
            }
            if (_sn_parent.ContentType != typeof(Component.Component))
            {
                return(null);
            }

            // create the node
            StructureNode node = new StructureNode();

            // content
            node.IDAsLong         = _node_source.ID;
            node.IDAsLong_Used    = true;
            node.ContentType      = typeof(GeometricRelationship);
            node.ContentType_Used = true;

            // structure
            node.ParentNode = _sn_parent;

            foreach (Point3DContainer p3dc in g_content)
            {
                StructureNode p3dc_sn = StructureNode.CreateFrom(p3dc, node);
                if (p3dc_sn != null)
                {
                    node.children_nodes.Add(p3dc_sn);
                }
            }

            return(node);
        }
Exemple #7
0
        public CompRepInfo FindByGeomId(long _id_volume, int _id_surface)
        {
            foreach (CompRep record in this.comp_rep_record_flat)
            {
                CompRepInfo cri = record as CompRepInfo;
                if (cri == null)
                {
                    continue;
                }

                GeometricRelationship geom_rel = cri.GR_Relationships.FirstOrDefault(x => x.GrIds.X == _id_volume && x.GrIds.Y == _id_surface);
                if (geom_rel != null)
                {
                    return(cri);
                }
            }

            return(null);
        }
        internal void UpdateInstancePositionIn(FlNetElement _container, Point _offset)
        {
            if (_container == null)
            {
                return;
            }

            GeometricRelationship gr = this.R2GInstances.FirstOrDefault(x => x.InstanceNWElementID == _container.ID);

            if (gr == null)
            {
                return;
            }
            if (gr.InstanceNWElementID != _container.ID)
            {
                return;
            }

            gr.UpdatePositionFrom(_container, new Point(0, 0), Component.SCALE_PIXEL_TO_M);
        }
        internal GeometricRelationship UpdateInstanceConnectivityInfo(FlNetEdge _edge)
        {
            if (_edge == null)
            {
                return(null);
            }
            GeometricRelationship gr = this.R2GInstances.FirstOrDefault(x => x.InstanceNWElementID == _edge.ID);

            if (gr == null)
            {
                return(null);
            }

            if (_edge.Start != null && _edge.End != null)
            {
                gr.InstancePath[0] = new System.Windows.Media.Media3D.Point3D(_edge.Start.ID, _edge.End.ID, -1);
            }

            return(gr);
        }
        /// <summary>
        /// Executes calculations in all subcomponents and saves the result in the input instance. Uses depth-first sub-component search.
        /// </summary>
        /// <param name="_instance"></param>
        protected void ExecuteCalculationChainForInstance(GeometricRelationship _instance)
        {
            foreach (var entry in this.ContainedComponents)
            {
                Component subC = entry.Value;
                if (subC == null)
                {
                    continue;
                }

                subC.ExecuteCalculationChainForInstance(_instance);
            }

            foreach (Calculation c in this.ContainedCalculations)
            {
                Dictionary <string, double> instance_param_values = _instance.InstanceParamValues;
                c.PerformCalculationWoArtefacts(ref instance_param_values);
                _instance.InstanceParamValues = new Dictionary <string, double>(instance_param_values);
            }
        }
        public static List <MappingObject> CreateMultipleFrom(Component _comp, TypeNode _tn, bool _as_example, List <KeyValuePair <string, TypeNode> > _correspondencies, out MappingError err)
        {
            err = MappingError.NONE;
            List <MappingObject> created_mappings = new List <MappingObject>();

            if (_comp == null || _tn == null || _correspondencies == null || _correspondencies.Count < 2)
            {
                err = MappingError.MISSING_MAPPING_END;
                return(created_mappings);
            }

            Component    current_comp = _comp;
            MappingError tmp_err      = MappingError.NONE;

            foreach (var entry in _correspondencies)
            {
                string[] key_comps = entry.Key.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries);
                if (key_comps == null || key_comps.Length < 2)
                {
                    err = MappingError.MISSING_MAPPING_END;
                    return(created_mappings);
                }

                if ((key_comps[0] + "_") == MappingComponent.PREFIX_COMP)
                {
                    // -------------------------- COMPONENTS --------------------------- //
                    long comp_id = -1;
                    bool success = long.TryParse(key_comps[1], out comp_id);
                    if (!success)
                    {
                        err = MappingError.MISSING_MAPPING_END;
                        return(created_mappings);
                    }

                    if (comp_id != current_comp.ID)
                    {
                        // look for the component in the children of current_comp
                        List <Component> all_sub_comps = current_comp.GetFlatSubCompList();
                        Component        next          = all_sub_comps.FirstOrDefault(x => x.ID == comp_id);
                        if (next == null)
                        {
                            err = MappingError.MISSING_MAPPING_END;
                            return(created_mappings);
                        }
                        else
                        {
                            current_comp = next;
                        }
                    }
                }
                else if ((key_comps[0] + "_") == MappingComponent.PREFIX_ID)
                {
                    // ------------------------ COMPONENT IDS -------------------------- //
                    MappingString ms = MappingString.Create(current_comp, entry.Key, entry.Value, _as_example, out tmp_err);
                    if (tmp_err != MappingError.NONE)
                    {
                        err = tmp_err;
                        return(created_mappings);
                    }
                    else
                    {
                        created_mappings.Add(ms);
                    }
                }
                else if ((key_comps[0] + "_") == MappingComponent.PREFIX_PARAM)
                {
                    // -------------------------- PARAMETERS --------------------------- //
                    long param_id = -1;
                    bool success  = long.TryParse(key_comps[1], out param_id);
                    if (!success || !current_comp.ContainedParameters.ContainsKey(param_id))
                    {
                        err = MappingError.MISSING_MAPPING_END;
                        return(created_mappings);
                    }
                    Parameter        p  = current_comp.ContainedParameters[param_id];
                    MappingParameter mp = MappingParameter.Create(p, current_comp, entry.Value, _as_example, false, out tmp_err);
                    if (tmp_err != MappingError.NONE)
                    {
                        err = tmp_err;
                        return(created_mappings);
                    }
                    else
                    {
                        created_mappings.Add(mp);
                    }
                }
                else if ((key_comps[0] + "_") == MappingComponent.PREFIX_P3DC)
                {
                    // --------------------------- GEOMETRY ---------------------------- //
                    if (key_comps.Length < 3)
                    {
                        err = MappingError.MISSING_MAPPING_END;
                        return(created_mappings);
                    }
                    long id_primary = -1;
                    int  id_second  = -1;
                    bool success_1  = long.TryParse(key_comps[1], out id_primary);
                    bool success_2  = int.TryParse(key_comps[2], out id_second);
                    if (!success_1 || !success_2)
                    {
                        err = MappingError.MISSING_MAPPING_END;
                        return(created_mappings);
                    }
                    GeometricRelationship gr = current_comp.R2GInstances.FirstOrDefault(x => x.ID == id_primary);
                    if (gr == null)
                    {
                        err = MappingError.MISSING_MAPPING_END;
                        return(created_mappings);
                    }
                    Point3DContainer p3dc = gr.GeometricContent.FirstOrDefault(x => x.ID_primary == id_primary && x.ID_secondary == id_second) as Point3DContainer;
                    if (p3dc == null)
                    {
                        err = MappingError.MISSING_MAPPING_END;
                        return(created_mappings);
                    }

                    MappingSinglePoint msp = MappingSinglePoint.Create(p3dc, current_comp, entry.Value, _as_example, out tmp_err);
                    if (tmp_err != MappingError.NONE)
                    {
                        err = tmp_err;
                        return(created_mappings);
                    }
                    else
                    {
                        created_mappings.Add(msp);
                    }
                }
            }

            return(created_mappings);
        }
        /// <summary>
        /// Called when placing a component in a NW element. It creates a new instance of the component.
        /// </summary>
        /// <param name="_container"></param>
        internal void CreateInstance(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
            if (this.Factory != null)
            {
                bool success = this.RecordWritingAccess(this.Factory.Caller);
                if (!success)
                {
                    return;
                }
            }
            else
            {
                return;
            }

            // check for duplicates
            foreach (GeometricRelationship gr in this.R2GInstances)
            {
                if (gr.InstanceNWElementID == _container.ID)
                {
                    return;
                }
            }

            // check for previous instancing:
            bool first_instancing = (this.R2GInstances.Count == 1 && this.R2GInstances[0].InstanceNWElementID < 0);

            // add an automatically generated sub-component containing the size parameters
            // add an automatically generated sub-component containing the cumulative parameters
            if (!this.ContainsValidAutoSubcomponentForSize())
            {
                this.AutoAddSubcomponentForSize();
            }
            if (!this.ContainsValidAutoSubcomponentForCumulation())
            {
                this.AutoAddSubcomponentForCumulation();
            }

            // assemble parameters to pass to the instance
            Dictionary <string, double> param_slots = this.ExtractParameterValues();

            // if there has not been any assignment so far, use the first and only GeometricRelationship
            if (first_instancing)
            {
                this.R2GInstances[0].PlaceInFlowNetworkElement(_container, new Point(0, 0), Component.SCALE_PIXEL_TO_M, new List <double> {
                    0, 0, 0, 0, 0, 0
                }, param_slots);
            }
            else
            {
                this.R2GInstances.Add(GeometricRelationship.CreateAndPlaceInFlowNetworkElement(_container, new Point(0, 0), Component.SCALE_PIXEL_TO_M, param_slots));
            }

            this.UpdateCumulativeValuesFromInstances(); // for the instance counter
        }