public IEnumerable <int> Run(XbimModel Model) { foreach (var label in _EntityLabelsToParse) { if (transverse) { yield return(label); } else if (_QueryCommand.Trim() == "") { yield return(label); } var entity = Model.Instances[label]; if (entity != null) { IfcType ifcType = IfcMetaData.IfcType(entity); // directs first SquareBracketIndexer sbi = new SquareBracketIndexer(_QueryCommand); var prop = ifcType.IfcProperties.Where(x => x.Value.PropertyInfo.Name == sbi.Property).FirstOrDefault().Value; if (prop == null) // otherwise test inverses { prop = ifcType.IfcInverses.Where(x => x.PropertyInfo.Name == sbi.Property).FirstOrDefault(); } if (prop != null) { object propVal = prop.PropertyInfo.GetValue(entity, null); if (propVal != null) { if (prop.IfcAttribute.IsEnumerable) { IEnumerable <object> propCollection = propVal as IEnumerable <object>; if (propCollection != null) { propCollection = sbi.getItem(propCollection); foreach (var item in propCollection) { IPersistIfcEntity pe = item as IPersistIfcEntity; yield return(pe.EntityLabel); } } } else { IPersistIfcEntity pe = propVal as IPersistIfcEntity; if (pe != null && sbi.Index < 1) // index is negative (not specified) or 0 { yield return(pe.EntityLabel); } } } } } } }
public IEnumerable<int> Run(XbimModel Model) { foreach (var label in _EntityLabelsToParse) { if (transverse) yield return label; else if (_QueryCommand.Trim() == "") yield return label; var entity = Model.Instances[label]; if (entity != null) { IfcType ifcType = IfcMetaData.IfcType(entity); // directs first SquareBracketIndexer sbi = new SquareBracketIndexer(_QueryCommand); var prop = ifcType.IfcProperties.Where(x => x.Value.PropertyInfo.Name == sbi.Property).FirstOrDefault().Value; if (prop == null) // otherwise test inverses { prop = ifcType.IfcInverses.Where(x => x.PropertyInfo.Name == sbi.Property).FirstOrDefault(); } if (prop != null) { object propVal = prop.PropertyInfo.GetValue(entity, null); if (propVal != null) { if (prop.IfcAttribute.IsEnumerable) { IEnumerable<object> propCollection = propVal as IEnumerable<object>; if (propCollection != null) { propCollection = sbi.getItem(propCollection); foreach (var item in propCollection) { IPersistIfcEntity pe = item as IPersistIfcEntity; yield return pe.EntityLabel; } } } else { IPersistIfcEntity pe = propVal as IPersistIfcEntity; if (pe != null && sbi.Index < 1) // index is negative (not specified) or 0 yield return pe.EntityLabel; } } } } } }
private void txtCommand_KeyDown(object sender, KeyEventArgs e) { if (e.Key == System.Windows.Input.Key.Enter && (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)) ) { #if DEBUG // stores the commands being launched var fname = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "xbimquerying.txt"); using (StreamWriter writer = File.CreateText(fname)) { writer.Write(txtCommand.Text); writer.Flush(); writer.Close(); } #endif e.Handled = true; if (bDoClear) txtOut.Document = new FlowDocument(); string[] CommandArray = txtCommand.Text.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); if (txtCommand.SelectedText != string.Empty) CommandArray = txtCommand.SelectedText.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); foreach (var cmd_f in CommandArray) { ReportAdd("> " + cmd_f, Brushes.ForestGreen); var cmd = cmd_f; int i = cmd.IndexOf("//"); if (i > 0) { cmd = cmd.Substring(0, i); } if (cmd.TrimStart().StartsWith("//")) continue; // put here all commands that don't require a database open var mdbclosed = Regex.Match(cmd, @"help", RegexOptions.IgnoreCase); if (mdbclosed.Success) { DisplayHelp(); continue; } mdbclosed = Regex.Match(cmd, @"xplorer", RegexOptions.IgnoreCase); if (mdbclosed.Success) { if (ParentWindow != null) ParentWindow.Focus(); else { // todo: bonghi: open the model in xplorer if needed. XplorerMainWindow xp = new XplorerMainWindow(); ParentWindow = xp; xp.Show(); } continue; } mdbclosed = Regex.Match(cmd, @"clear *\b(?<mode>(on|off))*", RegexOptions.IgnoreCase); if (mdbclosed.Success) { try { string option = mdbclosed.Groups["mode"].Value; if (option == "") { txtOut.Document = new FlowDocument(); continue; } else if (option == "on") bDoClear = true; else if (option == "off") bDoClear = false; else { ReportAdd(string.Format("Autoclear not changed ({0} is not a valid option).", option)); continue; } ReportAdd(string.Format("Autoclear set to {0}", option.ToLower())); continue; } catch (Exception) { } txtOut.Document = new FlowDocument(); continue; } if (Model == null) { ReportAdd("Plaese open a database.", Brushes.Red); continue; } // all commands here // var m = Regex.Match(cmd, @"^(entitylabel|el) (?<el>\d+)(?<recursion> -*\d+)*", RegexOptions.IgnoreCase); if (m.Success) { int recursion = 0; int v = Convert.ToInt32(m.Groups["el"].Value); try { recursion = Convert.ToInt32(m.Groups["recursion"].Value); } catch (Exception) { } ReportAdd(ReportEntity(v, recursion)); continue; } m = Regex.Match(cmd, @"^(Header|he)$", RegexOptions.IgnoreCase); if (m.Success) { if (Model.Header == null) { ReportAdd("Model header is not defined.", Brushes.Red); continue; } ReportAdd("FileDescription:"); foreach (var item in Model.Header.FileDescription.Description) { ReportAdd(string.Format("- Description: {0}", item)); } ReportAdd(string.Format("- ImplementationLevel: {0}", Model.Header.FileDescription.ImplementationLevel)); ReportAdd(string.Format("- EntityCount: {0}", Model.Header.FileDescription.EntityCount)); ReportAdd("FileName:"); ReportAdd(string.Format("- Name: {0}", Model.Header.FileName.Name)); ReportAdd(string.Format("- TimeStamp: {0}", Model.Header.FileName.TimeStamp)); foreach (var item in Model.Header.FileName.Organization) { ReportAdd(string.Format("- Organization: {0}", item)); } ReportAdd(string.Format("- OriginatingSystem: {0}", Model.Header.FileName.OriginatingSystem)); ReportAdd(string.Format("- PreprocessorVersion: {0}", Model.Header.FileName.PreprocessorVersion)); foreach (var item in Model.Header.FileName.AuthorName) { ReportAdd(string.Format("- AuthorName: {0}", item)); } ReportAdd(string.Format("- AuthorizationName: {0}", Model.Header.FileName.AuthorizationName)); foreach (var item in Model.Header.FileName.AuthorizationMailingAddress) { ReportAdd(string.Format("- AuthorizationMailingAddress: {0}", item)); } ReportAdd("FileSchema:"); foreach (var item in Model.Header.FileSchema.Schemas) { ReportAdd(string.Format("- Schema: {0}", item)); } continue; } // SelectionHighlighting [WholeMesh|Normals] m = Regex.Match(cmd, @"^(SelectionHighlighting|sh) (?<mode>(wholemesh|normals))+", RegexOptions.IgnoreCase); if (m.Success) { string mode = m.Groups["mode"].Value.ToLowerInvariant(); if (mode == "normals") { ReportAdd("Selection visual style set to 'Normals'"); ParentWindow.DrawingControl.SelectionHighlightMode = DrawingControl3D.SelectionHighlightModes.Normals; } else { ReportAdd("Selection visual style set to 'WholeMesh'"); ParentWindow.DrawingControl.SelectionHighlightMode = DrawingControl3D.SelectionHighlightModes.WholeMesh; } continue; } m = Regex.Match(cmd, @"^(IfcSchema|is) (?<mode>(list|count|short|full) )*(?<type>.+)", RegexOptions.IgnoreCase); if (m.Success) { string type = m.Groups["type"].Value; string mode = m.Groups["mode"].Value; if (type == "/") { } else if (type == PrepareRegex(type)) // there's not a regex expression, we will prepare one assuming the search for a bare name. { type = @".*\." + type + "$"; // any character repeated then a dot then the name and the end of line } else type = PrepareRegex(type); var TypeList = MatchingTypes(type); if (mode.ToLower() == "list ") { foreach (var item in TypeList) ReportAdd(item); } else if (mode.ToLower() == "count ") { ReportAdd("count: " + TypeList.Count()); } else { // report int BeVerbose = 1; if (mode.ToLower() == "short ") BeVerbose = 0; if (mode.ToLower() == "full ") BeVerbose = 2; foreach (var item in TypeList) { ReportAdd(ReportType(item, BeVerbose)); } } continue; } m = Regex.Match(cmd, @"^(reload|re) *(?<entities>([\d,]+|[^ ]+))", RegexOptions.IgnoreCase); if (m.Success) { string start = m.Groups["entities"].Value; IEnumerable<int> labels = tointarray(start, ','); if (labels.Count() > 0) { ParentWindow.DrawingControl.LoadGeometry(Model, labels); } else { ParentWindow.DrawingControl.LoadGeometry(Model); } continue; } m = Regex.Match(cmd, @"^(GeometryInfo|gi) (?<mode>(binary|viewer) )*(?<entities>([\d,]+|[^ ]+))", RegexOptions.IgnoreCase); if (m.Success) { string start = m.Groups["entities"].Value; string mode = m.Groups["mode"].Value; IEnumerable<int> labels = tointarray(start, ','); foreach (var item in labels) { ReportAdd("Geometry for: " + item.ToString(), Brushes.Green); ReportAdd(GeomQuerying.GeomInfoBoundBox(Model, item)); ReportAdd(GeomQuerying.GeomLayers(Model, item, ParentWindow.DrawingControl.scenes)); if (mode == "binary ") { ReportAdd(GeomQuerying.GeomInfoMesh(Model, item)); } if (mode == "viewer ") { ReportAdd( GeomQuerying.Viewerdata(ParentWindow.DrawingControl, Model, item) ); } } continue; } m = Regex.Match(cmd, @"^(select|se) (?<mode>(count|list|short) )*(?<tt>(transverse|tt) )*(?<hi>(highlight|hi) )*(?<start>([\d,-]+|[^ ]+)) *(?<props>.*)", RegexOptions.IgnoreCase); if (m.Success) { string start = m.Groups["start"].Value; string props = m.Groups["props"].Value; string mode = m.Groups["mode"].Value; // transverse tree mode bool transverseT = false; string transverse = m.Groups["tt"].Value; if (transverse != "") transverseT = true; bool Highlight = false; string HighlightT = m.Groups["hi"].Value; if (HighlightT != "") Highlight = true; IEnumerable<int> labels = tointarray(start, ','); IEnumerable<int> ret = null; if (labels.Count() == 0) { // see if it's a type string instead SquareBracketIndexer sbi = new SquareBracketIndexer(start); labels = QueryEngine.EntititesForType(sbi.Property, Model); labels = sbi.getItem(labels); } ret = QueryEngine.RecursiveQuery(Model, props, labels, transverseT); // textual report if (mode.ToLower() == "count ") { ReportAdd(string.Format("Count: {0}", ret.Count())); } else if (mode.ToLower() == "list ") { foreach (var item in ret) { ReportAdd(item.ToString()); } } else { bool BeVerbose = true; if (mode.ToLower() == "short ") BeVerbose = false; foreach (var item in ret) { ReportAdd(ReportEntity(item, 0, Verbose: BeVerbose)); } } // visual selection if (Highlight) { EntitySelection s = new EntitySelection(); foreach (var item in ret) { s.Add(Model.Instances[item]); } ParentWindow.DrawingControl.Selection = s; } continue; } m = Regex.Match(cmd, @"^zoom (" + @"(?<RegionName>.+$)" + ")", RegexOptions.IgnoreCase); if (m.Success) { string RName = m.Groups["RegionName"].Value; var regionData = Model.GetGeometryData(Xbim.XbimExtensions.XbimGeometryType.Region).FirstOrDefault(); if (regionData == null) { ReportAdd("data not found"); } XbimRegionCollection regions = XbimRegionCollection.FromArray(regionData.ShapeData); var reg = regions.Where(x => x.Name == RName).FirstOrDefault(); if (reg != null) { XbimMatrix3D mcp = XbimMatrix3D.Copy(ParentWindow.DrawingControl.wcsTransform); var bb = reg.Centre; var tC = mcp.Transform(reg.Centre); var tS = mcp.Transform(reg.Size); XbimRect3D r3d = new XbimRect3D( tC.X - tS.X / 2, tC.Y - tS.Y / 2, tC.Z - tS.Z / 2, tS.X, tS.X, tS.Z ); ParentWindow.DrawingControl.ZoomTo(r3d); ParentWindow.Activate(); continue; } else { ReportAdd(string.Format("Something wrong with region name: '{0}'", RName)); ReportAdd("Names that should work are: "); foreach (var str in regions) { ReportAdd(string.Format(" - '{0}'", str.Name)); } continue; } } m = Regex.Match(cmd, @"^clip off$", RegexOptions.IgnoreCase); if (m.Success) { ParentWindow.DrawingControl.ClearCutPlane(); ReportAdd("Clip removed"); ParentWindow.Activate(); continue; } m = Regex.Match(cmd, @"^clip (" + @"(?<elev>[-+]?([0-9]*\.)?[0-9]+) *$" + "|" + @"(?<px>[-+]?([0-9]*\.)?[0-9]+) *, *" + @"(?<py>[-+]?([0-9]*\.)?[0-9]+) *, *" + @"(?<pz>[-+]?([0-9]*\.)?[0-9]+) *, *" + @"(?<nx>[-+]?([0-9]*\.)?[0-9]+) *, *" + @"(?<ny>[-+]?([0-9]*\.)?[0-9]+) *, *" + @"(?<nz>[-+]?([0-9]*\.)?[0-9]+)" + "|" + @"(?<StoreyName>.+$)" + ")", RegexOptions.IgnoreCase); if (m.Success) { double px = 0, py = 0, pz = 0; double nx = 0, ny = 0, nz = -1; if (m.Groups["elev"].Value != string.Empty) { pz = Convert.ToDouble(m.Groups["elev"].Value); } else if (m.Groups["StoreyName"].Value != string.Empty) { string msg = ""; string storName = m.Groups["StoreyName"].Value; var storey = Model.Instances.OfType<Xbim.Ifc2x3.ProductExtension.IfcBuildingStorey>().Where(x => x.Name == storName).FirstOrDefault(); if (storey != null) { //get the object position data (should only be one) Xbim.XbimExtensions.XbimGeometryData geomdata = Model.GetGeometryData(storey.EntityLabel, Xbim.XbimExtensions.XbimGeometryType.TransformOnly).FirstOrDefault(); if (geomdata != null) { Xbim.Common.Geometry.XbimPoint3D pt = new Xbim.Common.Geometry.XbimPoint3D(0, 0, geomdata.Transform.OffsetZ); Xbim.Common.Geometry.XbimMatrix3D mcp = Xbim.Common.Geometry.XbimMatrix3D.Copy(ParentWindow.DrawingControl.wcsTransform); var transformed = mcp.Transform(pt); msg = string.Format("Clip 1m above storey elevation {0} (height: {1})", pt.Z, transformed.Z + 1); pz = transformed.Z + 1; } } if (msg == "") { ReportAdd(string.Format("Something wrong with storey name: '{0}'", storName)); ReportAdd("Names that should work are: "); var strs = Model.Instances.OfType<Xbim.Ifc2x3.ProductExtension.IfcBuildingStorey>(); foreach (var str in strs) { ReportAdd(string.Format(" - '{0}'", str.Name)); } continue; } ReportAdd(msg); } else { px = Convert.ToDouble(m.Groups["px"].Value); py = Convert.ToDouble(m.Groups["py"].Value); pz = Convert.ToDouble(m.Groups["pz"].Value); nx = Convert.ToDouble(m.Groups["nx"].Value); ny = Convert.ToDouble(m.Groups["ny"].Value); nz = Convert.ToDouble(m.Groups["nz"].Value); } ParentWindow.DrawingControl.ClearCutPlane(); ParentWindow.DrawingControl.SetCutPlane( px, py, pz, nx, ny, nz ); ReportAdd("Clip command sent"); ParentWindow.Activate(); continue; } m = Regex.Match(cmd, @"^Styler (?<command>.+)", RegexOptions.IgnoreCase); if (m.Success) { var st = ParentWindow.DrawingControl.LayerStyler as Xbim.Presentation.LayerStyling.LayerStylerTypeAndIFCStyleExtended; if (st != null) { string command = m.Groups["command"].Value; ReportAdd( st.SendCommand(command, ParentWindow.DrawingControl.Selection) ); ParentWindow.DrawingControl.ReloadModel(); } else { ReportAdd("Command not valid under current styler configuration."); } continue; } m = Regex.Match(cmd, @"^Visual (?<action>list|tree|on|off|mode)( (?<Name>[^ ]+))*", RegexOptions.IgnoreCase); if (m.Success) { string Name = m.Groups["Name"].Value; if (m.Groups["action"].Value.ToLowerInvariant() == "list") { foreach (var item in ParentWindow.DrawingControl.ListItems(Name)) { ReportAdd(item); } } else if (m.Groups["action"].Value.ToLowerInvariant() == "tree") { foreach (var item in ParentWindow.DrawingControl.LayersTree()) { ReportAdd(item); } } else if (m.Groups["action"].Value.ToLowerInvariant() == "mode") { string t = Name.ToLowerInvariant(); if (t == "type") { ReportAdd("Visual mode set to EntityType."); ParentWindow.DrawingControl.LayerStyler = new Xbim.Presentation.LayerStyling.LayerStylerTypeAndIFCStyle(); ParentWindow.DrawingControl.ReloadModel(Options: DrawingControl3D.ModelRefreshOptions.ViewPreserveAll); } else if (t == "entity") { ReportAdd("Visual mode set to EntityLabel."); ParentWindow.DrawingControl.LayerStyler = new Xbim.Presentation.LayerStyling.LayerStylerPerEntity(); ParentWindow.DrawingControl.ReloadModel(Options: DrawingControl3D.ModelRefreshOptions.ViewPreserveAll); } else if (t == "oddeven") { ReportAdd("Visual mode set to Odd/Even."); ParentWindow.DrawingControl.LayerStyler = new Xbim.Presentation.LayerStyling.LayerStylerEvenOdd(); ParentWindow.DrawingControl.ReloadModel(Options: DrawingControl3D.ModelRefreshOptions.ViewPreserveAll); } else if (t == "demo") { ReportAdd("Visual mode set to Demo."); ParentWindow.DrawingControl.LayerStyler = new Xbim.Presentation.LayerStyling.LayerStylerTypeAndIFCStyleExtended(); ParentWindow.DrawingControl.ReloadModel(Options: DrawingControl3D.ModelRefreshOptions.ViewPreserveAll); } else ReportAdd(string.Format("mode not understood: {0}.", t)); } else { bool bVis = false; if (m.Groups["action"].Value.ToLowerInvariant() == "on") bVis = true; ParentWindow.DrawingControl.SetVisibility(Name, bVis); } continue; } m = Regex.Match(cmd, @"^SimplifyGUI$", RegexOptions.IgnoreCase); if (m.Success) { XbimXplorer.Simplify.IfcSimplify s = new Simplify.IfcSimplify(); s.Show(); continue; } m = Regex.Match(cmd, @"^test$", RegexOptions.IgnoreCase); if (m.Success) { int iPass = -728; ReportAdd(RunTestCode(iPass)); continue; } ReportAdd(string.Format("Command not understood: {0}.", cmd)); } } }
private void Execute() { #if DEBUG // stores the commands being launched var fname = Path.Combine(Path.GetTempPath(), "xbimquerying.txt"); using (var writer = File.CreateText(fname)) { writer.Write(TxtCommand.Text); writer.Flush(); writer.Close(); } #endif if (_bDoClear) TxtOut.Document = new FlowDocument(); var commandArray = TxtCommand.Text.Split(new[] {"\r\n"}, StringSplitOptions.RemoveEmptyEntries); if (TxtCommand.SelectedText != string.Empty) commandArray = TxtCommand.SelectedText.Split(new[] {"\r\n"}, StringSplitOptions.RemoveEmptyEntries); foreach (var cmdF in commandArray) { ReportAdd("> " + cmdF, Brushes.ForestGreen); var cmd = cmdF; var i = cmd.IndexOf("//", StringComparison.Ordinal); if (i > 0) { cmd = cmd.Substring(0, i); } if (cmd.TrimStart().StartsWith("//")) continue; // put here all commands that don't require a database open var mdbclosed = Regex.Match(cmd, @"^help$", RegexOptions.IgnoreCase); if (mdbclosed.Success) { DisplayHelp(); continue; } mdbclosed = Regex.Match(cmd, @"^Plugin Refresh$", RegexOptions.IgnoreCase); if (mdbclosed.Success) { if (_parentWindow != null) _parentWindow.RefreshPlugins(); continue; } mdbclosed = Regex.Match(cmd, @"^Plugin Load (?<assemblyName>.+)$", RegexOptions.IgnoreCase); if (mdbclosed.Success) { var assemblyName = mdbclosed.Groups["assemblyName"].Value; if (File.Exists(assemblyName)) if (_parentWindow != null && _parentWindow is XplorerMainWindow) ((XplorerMainWindow)_parentWindow).LoadPlugin(assemblyName); continue; } mdbclosed = Regex.Match(cmd, @"^xplorer$", RegexOptions.IgnoreCase); if (mdbclosed.Success) { if (_parentWindow != null) _parentWindow.Focus(); else { // todo: bonghi: open the model in xplorer if needed. var xp = new XplorerMainWindow(); _parentWindow = xp; xp.Show(); } continue; } mdbclosed = Regex.Match(cmd, @"^versions$", RegexOptions.IgnoreCase); if (mdbclosed.Success) { var asms = AppDomain.CurrentDomain.GetAssemblies(); ReportAdd("List of loaded assemblies:", Brushes.Black); foreach (var asm in asms) { var asmName = asm.GetName(); ReportAdd(string.Format(" - {0}", asmName.FullName), Brushes.Black); } continue; } mdbclosed = Regex.Match(cmd, @"clear *\b(?<mode>(on|off))*", RegexOptions.IgnoreCase); if (mdbclosed.Success) { try { var option = mdbclosed.Groups["mode"].Value; if (option == "") { TxtOut.Document = new FlowDocument(); continue; } if (option == "on") _bDoClear = true; else if (option == "off") _bDoClear = false; else { ReportAdd(string.Format("Autoclear not changed ({0} is not a valid option).", option)); continue; } ReportAdd(string.Format("Autoclear set to {0}", option.ToLower())); continue; } // ReSharper disable once EmptyGeneralCatchClause catch { } TxtOut.Document = new FlowDocument(); continue; } if (Model == null) { ReportAdd("Plaese open a database.", Brushes.Red); continue; } // all commands here // var m = Regex.Match(cmd, @"^(entitylabel|el) (?<el>\d+)(?<recursion> -*\d+)*", RegexOptions.IgnoreCase); if (m.Success) { var recursion = 0; var v = Convert.ToInt32(m.Groups["el"].Value); try { recursion = Convert.ToInt32(m.Groups["recursion"].Value); } // ReSharper disable once EmptyGeneralCatchClause catch { } ReportAdd(ReportEntity(v, recursion)); continue; } m = Regex.Match(cmd, @"^(Header|he)$", RegexOptions.IgnoreCase); if (m.Success) { if (Model.Header == null) { ReportAdd("Model header is not defined.", Brushes.Red); continue; } ReportAdd("FileDescription:"); foreach (var item in Model.Header.FileDescription.Description) { ReportAdd(string.Format("- Description: {0}", item)); } ReportAdd(string.Format("- ImplementationLevel: {0}", Model.Header.FileDescription.ImplementationLevel)); ReportAdd(string.Format("- EntityCount: {0}", Model.Header.FileDescription.EntityCount)); ReportAdd("FileName:"); ReportAdd(string.Format("- Name: {0}", Model.Header.FileName.Name)); ReportAdd(string.Format("- TimeStamp: {0}", Model.Header.FileName.TimeStamp)); foreach (var item in Model.Header.FileName.Organization) { ReportAdd(string.Format("- Organization: {0}", item)); } ReportAdd(string.Format("- OriginatingSystem: {0}", Model.Header.FileName.OriginatingSystem)); ReportAdd(string.Format("- PreprocessorVersion: {0}", Model.Header.FileName.PreprocessorVersion)); foreach (var item in Model.Header.FileName.AuthorName) { ReportAdd(string.Format("- AuthorName: {0}", item)); } ReportAdd(string.Format("- AuthorizationName: {0}", Model.Header.FileName.AuthorizationName)); foreach (var item in Model.Header.FileName.AuthorizationMailingAddress) { ReportAdd(string.Format("- AuthorizationMailingAddress: {0}", item)); } ReportAdd("FileSchema:"); foreach (var item in Model.Header.FileSchema.Schemas) { ReportAdd(string.Format("- Schema: {0}", item)); } continue; } // SelectionHighlighting [WholeMesh|Normals] m = Regex.Match(cmd, @"^(SelectionHighlighting|sh) (?<mode>(wholemesh|normals|wireframe))+", RegexOptions.IgnoreCase); if (m.Success) { var mode = m.Groups["mode"].Value.ToLowerInvariant(); if (mode == "normals") { ReportAdd("Selection visual style set to 'Normals'"); _parentWindow.DrawingControl.SelectionHighlightMode = DrawingControl3D.SelectionHighlightModes.Normals; } else if (mode == "wholemesh") { ReportAdd("Selection visual style set to 'WholeMesh'"); _parentWindow.DrawingControl.SelectionHighlightMode = DrawingControl3D.SelectionHighlightModes.WholeMesh; } else if (mode == "wireframe") { ReportAdd("Selection visual style set to 'WireFrame'"); _parentWindow.DrawingControl.SelectionHighlightMode = DrawingControl3D.SelectionHighlightModes.WireFrame; } continue; } m = Regex.Match(cmd, @"^(IfcSchema|is) (?<mode>(list|count|short|full) )*(?<type>\w+)[ ]*", RegexOptions.IgnoreCase); if (m.Success) { var type = m.Groups["type"].Value; var mode = m.Groups["mode"].Value; if (type == "/") { // this is a magic case handled by the matchingType } else if (type == PrepareRegex(type)) // there's not a regex expression, we will prepare one assuming the search for a bare name. { type = @".*\." + type + "$"; // any character repeated then a dot then the name and the end of line } else type = PrepareRegex(type); var typeList = MatchingTypes(type); if (mode.ToLower() == "list ") { foreach (var item in typeList) ReportAdd(item); } else if (mode.ToLower() == "count ") { ReportAdd("count: " + typeList.Count()); } else { // report var beVerbose = 1; if (mode.ToLower() == "short ") beVerbose = 0; if (mode.ToLower() == "full ") beVerbose = 2; foreach (var item in typeList) { ReportAdd(ReportType(item, beVerbose)); } } continue; } m = Regex.Match(cmd, @"^(reload|re) *(?<entities>([\d,]+|[^ ]+))", RegexOptions.IgnoreCase); if (m.Success) { var start = m.Groups["entities"].Value; IEnumerable<int> labels = ToIntarray(start, ','); if (labels.Any()) { _parentWindow.DrawingControl.LoadGeometry(Model, labels); } else { _parentWindow.DrawingControl.LoadGeometry(Model); } continue; } m = Regex.Match(cmd, @"^(GeometryInfo|gi) (?<mode>(binary|viewer) )*(?<entities>([\d,]+|[^ ]+))", RegexOptions.IgnoreCase); if (m.Success) { var start = m.Groups["entities"].Value; var mode = m.Groups["mode"].Value; IEnumerable<int> labels = ToIntarray(start, ','); foreach (var item in labels) { ReportAdd("Geometry for: " + item, Brushes.Green); ReportAdd(GeomQuerying.GeomInfoBoundBox(Model, item)); ReportAdd(GeomQuerying.GeomLayers(Model, item, _parentWindow.DrawingControl.Scenes)); if (mode == "binary ") { ReportAdd(GeomQuerying.GeomInfoMesh(Model, item)); } if (mode == "viewer ") { ReportAdd( GeomQuerying.Viewerdata(_parentWindow.DrawingControl, Model, item) ); } } continue; } m = Regex.Match(cmd, @"^(select|se) " + @"(?<mode>(count|list|typelist|short|full) )*" + @"(?<tt>(transverse|tt) )*" + @"(?<hi>(highlight|hi) )*" + @"(?<svt>(showvaluetype|svt) )*" + @"(?<start>([\d,-]+|[^ ]+)) *(?<props>.*)", RegexOptions.IgnoreCase); if (m.Success) { var start = m.Groups["start"].Value; var props = m.Groups["props"].Value; var mode = m.Groups["mode"].Value; var svt = m.Groups["svt"].Value; // transverse tree mode var transverseT = false; var transverse = m.Groups["tt"].Value; if (transverse != "") transverseT = true; var highlight = false; var highlightT = m.Groups["hi"].Value; if (highlightT != "") highlight = true; IEnumerable<int> labels = ToIntarray(start, ','); if (!labels.Any()) { // see if it's a type string instead; var subRe = new Regex(@"[\+\-]*([A-Za-z0-9\[\]]+)"); var res = subRe.Matches(start); foreach (Match submatch in res) { var modeAdd = !submatch.Value.Contains("-"); // the syntax could be IfcWall[10] var sbi = new SquareBracketIndexer(submatch.Groups[1].Value); IEnumerable<int> thisLabels = QueryEngine.EntititesForType(sbi.Property, Model); thisLabels = sbi.GetItem(thisLabels); labels = modeAdd ? labels.Concat(thisLabels) : labels.Where(t => !thisLabels.Contains(t)); } } var ret = QueryEngine.RecursiveQuery(Model, props, labels, transverseT); // textual report switch (mode.ToLower()) { case "count ": ReportAdd(string.Format("Count: {0}", ret.Count())); break; case "list ": foreach (var item in ret) { ReportAdd(item.ToString(CultureInfo.InvariantCulture)); } break; case "typelist ": foreach (var item in ret) { ReportAdd(item + "\t" + Model.Instances[item].IfcType().Name); } break; default: var beVerbose = false; if (mode.ToLower() == "short ") beVerbose = false; if (mode.ToLower() == "full ") beVerbose = true; var svtB = (svt != ""); foreach (var item in ret) { ReportAdd(ReportEntity(item, 0, verbose: beVerbose, showValueType: svtB)); } break; } // visual selection if (highlight) { var s = new EntitySelection(); foreach (var item in ret) { s.Add(Model.Instances[item]); } _parentWindow.DrawingControl.Selection = s; } continue; } m = Regex.Match(cmd, @"^zoom (" + @"(?<RegionName>.+$)" + ")", RegexOptions.IgnoreCase); if (m.Success) { var rName = m.Groups["RegionName"].Value; var regionData = Model.GetGeometryData(XbimGeometryType.Region).FirstOrDefault(); if (regionData == null) { ReportAdd("data not found"); } var regions = XbimRegionCollection.FromArray(regionData.ShapeData); var reg = regions.FirstOrDefault(x => x.Name == rName); if (reg != null) { var mcp = XbimMatrix3D.Copy(_parentWindow.DrawingControl.ModelPositions[Model].Transfrom); var tC = mcp.Transform(reg.Centre); var tS = mcp.Transform(reg.Size); var r3D = new XbimRect3D( tC.X - tS.X/2, tC.Y - tS.Y/2, tC.Z - tS.Z/2, tS.X, tS.X, tS.Z ); _parentWindow.DrawingControl.ZoomTo(r3D); _parentWindow.Activate(); continue; } else { ReportAdd(string.Format("Something wrong with region name: '{0}'", rName)); ReportAdd("Names that should work are: "); foreach (var str in regions) { ReportAdd(string.Format(" - '{0}'", str.Name)); } continue; } } m = Regex.Match(cmd, @"^clip off$", RegexOptions.IgnoreCase); if (m.Success) { _parentWindow.DrawingControl.ClearCutPlane(); ReportAdd("Clip removed"); _parentWindow.Activate(); continue; } m = Regex.Match(cmd, @"^clip (" + @"(?<elev>[-+]?([0-9]*\.)?[0-9]+) *$" + "|" + @"(?<px>[-+]?([0-9]*\.)?[0-9]+) *, *" + @"(?<py>[-+]?([0-9]*\.)?[0-9]+) *, *" + @"(?<pz>[-+]?([0-9]*\.)?[0-9]+) *, *" + @"(?<nx>[-+]?([0-9]*\.)?[0-9]+) *, *" + @"(?<ny>[-+]?([0-9]*\.)?[0-9]+) *, *" + @"(?<nz>[-+]?([0-9]*\.)?[0-9]+)" + "|" + @"(?<StoreyName>.+$)" + ")", RegexOptions.IgnoreCase); if (m.Success) { double px = 0, py = 0, pz = 0; double nx = 0, ny = 0, nz = -1; if (m.Groups["elev"].Value != string.Empty) { pz = Convert.ToDouble(m.Groups["elev"].Value); } else if (m.Groups["StoreyName"].Value != string.Empty) { var msg = ""; var storName = m.Groups["StoreyName"].Value; var storey = Model.Instances.OfType<IfcBuildingStorey>().FirstOrDefault(x => x.Name == storName); if (storey != null) { //get the object position data (should only be one) if (Model.GeometrySupportLevel == 1) { var geomdata = Model.GetGeometryData(storey.EntityLabel, XbimGeometryType.TransformOnly) .FirstOrDefault(); if (geomdata != null) { var pt = new XbimPoint3D(0, 0, XbimMatrix3D.FromArray(geomdata.DataArray2).OffsetZ); var mcp = XbimMatrix3D.Copy(_parentWindow.DrawingControl.ModelPositions[Model].Transfrom); var transformed = mcp.Transform(pt); msg = string.Format("Clip 1m above storey elevation {0} (height: {1})", pt.Z, transformed.Z + 1); pz = transformed.Z + 1; } } else if (Model.GeometrySupportLevel == 2) { var v = new TransformGraph(Model); v.AddProduct(storey); var v2 = v[storey].LocalMatrix; var pt = new XbimPoint3D(0, 0, v2.OffsetZ); var mcp = XbimMatrix3D.Copy(_parentWindow.DrawingControl.ModelPositions[Model].Transfrom); var transformed = mcp.Transform(pt); msg = string.Format("Clip 1m above storey elevation {0} (height: {1})", pt.Z, transformed.Z + 1); pz = transformed.Z + 1; } } if (msg == "") { ReportAdd(string.Format("Something wrong with storey name: '{0}'", storName)); ReportAdd("Names that should work are: "); var strs = Model.Instances.OfType<IfcBuildingStorey>(); foreach (var str in strs) { ReportAdd(string.Format(" - '{0}'", str.Name)); } continue; } ReportAdd(msg); } else { px = Convert.ToDouble(m.Groups["px"].Value); py = Convert.ToDouble(m.Groups["py"].Value); pz = Convert.ToDouble(m.Groups["pz"].Value); nx = Convert.ToDouble(m.Groups["nx"].Value); ny = Convert.ToDouble(m.Groups["ny"].Value); nz = Convert.ToDouble(m.Groups["nz"].Value); } _parentWindow.DrawingControl.ClearCutPlane(); _parentWindow.DrawingControl.SetCutPlane( px, py, pz, nx, ny, nz ); ReportAdd("Clip command sent"); _parentWindow.Activate(); continue; } m = Regex.Match(cmd, @"^Styler (?<command>.+)", RegexOptions.IgnoreCase); if (m.Success) { var st = _parentWindow.DrawingControl.LayerStyler as LayerStylerTypeAndIfcStyleExtended; if (st != null) { var command = m.Groups["command"].Value; ReportAdd( st.SendCommand(command, _parentWindow.DrawingControl.Selection) ); _parentWindow.DrawingControl.ReloadModel(); } else { ReportAdd("Command not valid under current styler configuration."); } continue; } m = Regex.Match(cmd, @"^Visual (?<action>list|tree|on|off|mode)( (?<Name>[^ ]+))*", RegexOptions.IgnoreCase); if (m.Success) { var parName = m.Groups["Name"].Value; if (m.Groups["action"].Value.ToLowerInvariant() == "list") { foreach (var item in _parentWindow.DrawingControl.ListItems(parName)) { ReportAdd(item); } } else if (m.Groups["action"].Value.ToLowerInvariant() == "tree") { foreach (var item in _parentWindow.DrawingControl.LayersTree()) { ReportAdd(item); } } else if (m.Groups["action"].Value.ToLowerInvariant() == "mode") { parName = parName.ToLowerInvariant(); var sb = new StringBuilder(); // foreach model if (_parentWindow.DrawingControl.LayerStylerForceVersion1 || Model.GeometrySupportLevel == 1) ReportAdd(string.Format(@"Current mode is {0}", _parentWindow.DrawingControl.LayerStyler.GetType()) , Brushes.Green); else if (Model.GeometrySupportLevel == 2) ReportAdd(string.Format(@"Current mode is {0}", _parentWindow.DrawingControl.GeomSupport2LayerStyler.GetType()), Brushes.Green); else ReportAdd(@"Visual mode not enabled on GeometrySupportLevel 0", Brushes.Red); bool stylerSet = false; var v1 = TypesImplementingInterface(typeof (ILayerStyler)); foreach (var instance in v1.Where(IsRealClass)) { if (instance.Name.ToLowerInvariant() == parName || instance.FullName.ToLowerInvariant() == parName) { _parentWindow.DrawingControl.LayerStylerForceVersion1 = true; _parentWindow.DrawingControl.LayerStyler = (ILayerStyler) Activator.CreateInstance(instance); _parentWindow.DrawingControl.FederationLayerStyler = (ILayerStyler)Activator.CreateInstance(instance); _parentWindow.DrawingControl.ReloadModel( options: DrawingControl3D.ModelRefreshOptions.ViewPreserveAll ); ReportAdd("Visual mode set to " + instance.FullName + ".", Brushes.Orange); stylerSet = true; continue; } sb.AppendLine(" - " + instance.FullName); } var v2 = TypesImplementingInterface(typeof(ILayerStylerV2)); foreach (var instance in v2.Where(IsRealClass)) { if (instance.Name.ToLowerInvariant() == parName || instance.FullName.ToLowerInvariant() == parName) { _parentWindow.DrawingControl.LayerStylerForceVersion1 = false; _parentWindow.DrawingControl.GeomSupport2LayerStyler = (ILayerStylerV2) Activator.CreateInstance(instance); _parentWindow.DrawingControl.ReloadModel( options: DrawingControl3D.ModelRefreshOptions.ViewPreserveAll ); ReportAdd("Visual mode set to " + instance.FullName + ".", Brushes.Orange); stylerSet = true; continue; } sb.AppendLine(" - " + instance.FullName); } if (!stylerSet) ReportAdd(string.Format("Nothing done; valid modes are:\r\n{0}", sb)); } else { var bVis = m.Groups["action"].Value.ToLowerInvariant() == "on"; _parentWindow.DrawingControl.SetVisibility(parName, bVis); } continue; } m = Regex.Match(cmd, @"^SimplifyGUI$", RegexOptions.IgnoreCase); if (m.Success) { var s = new IfcSimplify(); s.Show(); continue; } m = Regex.Match(cmd, @"^test$", RegexOptions.IgnoreCase); if (m.Success) { if (SelectedEntity != null) Debug.Write(SelectedEntity.EntityLabel); else Debug.Write(null); continue; } ReportAdd(string.Format("Command not understood: {0}.", cmd)); } }