/// <inheritdoc/> public override void Initialize(EffectContext effectContext, TransformGraph transformGraph) { var path = Windows.ApplicationModel.Package.Current.InstalledLocation.Path; effectContext.LoadPixelShader(GUID_RipplePixelShader, NativeFile.ReadAllBytes(path + "\\Ripple.cso")); transformGraph.SetSingleTransformNode(this); }
//EffectContext _effectContext; public override void Initialize(EffectContext effectContext, TransformGraph transformGraph) { //WARNING : as soon as TransformGraph.SetSingleTransformNode is called it chain calls the //SetDrawInformation via a callbac. Unfortunately this is too early because the code below //within this method is used to populate stateful data needed by the SetDrawInformation call. //transformGraph.SetSingleTransformNode(this); var path = Windows.ApplicationModel.Package.Current.InstalledLocation.Path; byte[] vertexShaderBytecode = NativeFile.ReadAllBytes(path + "\\WaveEffect.cso"); effectContext.LoadVertexShader(GUID_WaveVertexShader, vertexShaderBytecode); // Only generate the vertex buffer if it has not already been initialized. vertexBuffer = effectContext.FindVertexBuffer(GUID_WaveVertexBuffer); if (vertexBuffer == null) { //InitializeVertexBuffer(effectContext); var mesh = GenerateMesh(); // Updating geometry every time the effect is rendered can be costly, so it is // recommended that vertex buffer remain static if possible (which it is in this // sample effect). using (var stream = DataStream.Create(mesh, true, true)) { var vbProp = new VertexBufferProperties(1, VertexUsage.Static, stream); var cvbProp = new CustomVertexBufferProperties(vertexShaderBytecode, new[] { new InputElement("MESH_POSITION", 0, SharpDX.DXGI.Format.R32G32_Float, 0, 0), }, Utilities.SizeOf <Vector2>()); // The GUID is optional, and is provided here to register the geometry globally. // As mentioned above, this avoids duplication if multiple versions of the effect // are created. vertexBuffer = new VertexBuffer(effectContext, GUID_WaveVertexBuffer, vbProp, cvbProp); } } PrepareForRender(ChangeType.Properties | ChangeType.Context); transformGraph.SetSingleTransformNode(this); }
/// <summary> /// Get the Transform Graph for this model /// </summary> /// <returns>TransformGraph object</returns> public TransformGraph GetTransformGraph() { TransformGraph graph = null; if (!string.IsNullOrEmpty(ModelFileName)) { //get the file name to store the geometry string cacheFile = Path.ChangeExtension(ModelFileName, ".xbimGC"); //if no Geometry file than create it if (!File.Exists(cacheFile)) { GenerateGeometry(cacheFile); } //now we have a file read it into the XbimSceneStream if (File.Exists(cacheFile)) { XbimSceneStream scene = new XbimSceneStream(Model, cacheFile); graph = scene.Graph; //the graph holds product boundary box's so we will return it scene.Close(); } } return(graph); }
/// <inheritdoc/> public override void SetGraph(TransformGraph transformGraph) { throw new NotImplementedException(); }
/// <summary> /// Use this function on a Xbim Model that has just been creted from IFC content /// This will create the default 3D mesh geometry for all IfcProducts and add it to the model /// </summary> /// <param name="model"></param> public static void GenerateGeometry(XbimModel model, ILogger Logger = null, ReportProgressDelegate progDelegate = null, IEnumerable<IfcProduct> toMesh = null) { //Create the geometry engine by reflection to allow dynamic loading of different binary platforms (32, 64 etc) Assembly assembly = AssemblyResolver.GetModelGeometryAssembly(); if (assembly == null) { if (Logger != null) { #if DEBUG Logger.Error("Failed to load Xbim.ModelGeometry.OCCd.dll Please ensure it is installed correctly"); #else Logger.Error("Failed to load Xbim.ModelGeometry.OCC.dll Please ensure it is installed correctly"); #endif } return; } IXbimGeometryEngine engine = (IXbimGeometryEngine)assembly.CreateInstance("Xbim.ModelGeometry.XbimGeometryEngine"); engine.Init(model); if (engine == null) { if (Logger != null) { #if DEBUG Logger.Error("Failed to create Xbim Geometry engine. Please ensure Xbim.ModelGeometry.OCCd.dll is installed correctly"); #else Logger.Error("Failed to create Xbim Geometry engine. Please ensure Xbim.ModelGeometry.OCC.dll is installed correctly"); #endif } return; } //now convert the geometry IEnumerable<IfcProduct> toDraw; if (toMesh != null) toDraw = toMesh; else toDraw = model.InstancesLocal.OfType<IfcProduct>().Where(t => !(t is IfcFeatureElement)); //List<IfcProduct> toDraw = new List<IfcProduct>(); // toDraw.Add(model.Instances[513489] as IfcProduct); if (!toDraw.Any()) return; //othing to do TransformGraph graph = new TransformGraph(model); //create a new dictionary to hold maps ConcurrentDictionary<int, Object> maps = new ConcurrentDictionary<int, Object>(); //add everything that may have a representation graph.AddProducts(toDraw); //load the products as we will be accessing their geometry ConcurrentDictionary<int, MapData> mappedModels = new ConcurrentDictionary<int, MapData>(); ConcurrentQueue<MapRefData> mapRefs = new ConcurrentQueue<MapRefData>(); ConcurrentDictionary<int, int[]> written = new ConcurrentDictionary<int, int[]>(); int tally = 0; int percentageParsed = 0; int total = graph.ProductNodes.Values.Count; try { //use parallel as this improves the OCC geometry generation greatly ParallelOptions opts = new ParallelOptions(); opts.MaxDegreeOfParallelism = 16; XbimRect3D bounds = XbimRect3D.Empty; double deflection = model.ModelFactors.DeflectionTolerance; #if DOPARALLEL Parallel.ForEach<TransformNode>(graph.ProductNodes.Values, opts, node => //go over every node that represents a product #else foreach (var node in graph.ProductNodes.Values) #endif { IfcProduct product = node.Product(model); try { IXbimGeometryModel geomModel = engine.GetGeometry3D(product, maps); if (geomModel != null) //it has geometry { XbimMatrix3D m3d = node.WorldMatrix(); if (geomModel.IsMap) //do not process maps now { MapData toAdd = new MapData(geomModel, m3d, product); if (!mappedModels.TryAdd(geomModel.RepresentationLabel, toAdd)) //get unique rep mapRefs.Enqueue(new MapRefData(toAdd)); //add ref } else { int[] geomIds; XbimGeometryCursor geomTable = model.GetGeometryTable(); XbimLazyDBTransaction transaction = geomTable.BeginLazyTransaction(); if (written.TryGetValue(geomModel.RepresentationLabel, out geomIds)) { byte[] matrix = m3d.ToArray(true); short? typeId = IfcMetaData.IfcTypeId(product); foreach (var geomId in geomIds) { geomTable.AddMapGeometry(geomId, product.EntityLabel, typeId.Value, matrix, geomModel.SurfaceStyleLabel); } } else { XbimTriangulatedModelCollection tm = geomModel.Mesh(deflection); XbimRect3D bb = tm.Bounds; byte[] matrix = m3d.ToArray(true); short? typeId = IfcMetaData.IfcTypeId(product); geomIds = new int[tm.Count + 1]; geomIds[0] = geomTable.AddGeometry(product.EntityLabel, XbimGeometryType.BoundingBox, typeId.Value, matrix, bb.ToDoublesArray(), 0, geomModel.SurfaceStyleLabel); bb = XbimRect3D.TransformBy(bb, m3d); if (bounds.IsEmpty) bounds = bb; else bounds.Union(bb); short subPart = 0; foreach (XbimTriangulatedModel b in tm) { geomIds[subPart + 1] = geomTable.AddGeometry(product.EntityLabel, XbimGeometryType.TriangulatedMesh, typeId.Value, matrix, b.Triangles, subPart, b.SurfaceStyleLabel); subPart++; } // Debug.Assert(written.TryAdd(geomModel.RepresentationLabel, geomIds)); Interlocked.Increment(ref tally); if (progDelegate != null) { int newPercentage = Convert.ToInt32((double)tally / total * 100.0); if (newPercentage > percentageParsed) { percentageParsed = newPercentage; progDelegate(percentageParsed, "Meshing"); } } } transaction.Commit(); model.FreeTable(geomTable); } } else { // store a transform only if no geomtery is available XbimGeometryCursor geomTable = model.GetGeometryTable(); XbimLazyDBTransaction transaction = geomTable.BeginLazyTransaction(); XbimMatrix3D m3dtemp = node.WorldMatrix(); byte[] matrix = m3dtemp.ToArray(true); short? typeId = IfcMetaData.IfcTypeId(product); geomTable.AddGeometry(product.EntityLabel, XbimGeometryType.TransformOnly, typeId.Value, matrix, new byte[] {}); transaction.Commit(); model.FreeTable(geomTable); Interlocked.Increment(ref tally); if (progDelegate != null) { int newPercentage = Convert.ToInt32((double)tally / total * 100.0); if (newPercentage > percentageParsed) { percentageParsed = newPercentage; progDelegate(percentageParsed, "Meshing"); } } } } catch (Exception e1) { String message = String.Format("Error Triangulating product geometry of entity #{0} - {1}", product.EntityLabel, product.GetType().Name ); if (Logger != null) Logger.Error(message, e1); } } #if DOPARALLEL ); #endif graph = null; // Debug.WriteLine(tally); #if DOPARALLEL //now sort out maps again in parallel Parallel.ForEach<KeyValuePair<int, MapData>>(mappedModels, opts, map => #else foreach (var map in mappedModels) #endif { IXbimGeometryModel geomModel = map.Value.Geometry; XbimMatrix3D m3d = map.Value.Matrix; IfcProduct product = map.Value.Product; //have we already written it? int[] writtenGeomids = new int[0]; if (!written.TryAdd(geomModel.RepresentationLabel, writtenGeomids)) { //make maps mapRefs.Enqueue(new MapRefData(map.Value)); //add ref } else { m3d = XbimMatrix3D.Multiply(geomModel.Transform, m3d); WriteGeometry(model, written, geomModel, ref bounds, m3d, product, deflection); } Interlocked.Increment(ref tally); if (progDelegate != null) { int newPercentage = Convert.ToInt32((double)tally / total * 100.0); if (newPercentage > percentageParsed) { percentageParsed = newPercentage; progDelegate(percentageParsed, "Meshing"); } } map.Value.Clear(); //release any native memory we are finished with this } #if DOPARALLEL ); #endif //clear up maps mappedModels.Clear(); XbimGeometryCursor geomMapTable = model.GetGeometryTable(); XbimLazyDBTransaction mapTrans = geomMapTable.BeginLazyTransaction(); foreach (var map in mapRefs) //don't do this in parallel to avoid database thrashing as it is very fast { int[] geomIds; if (!written.TryGetValue(map.RepresentationLabel, out geomIds)) { if (Logger != null) Logger.WarnFormat("A geometry mapped reference (#{0}) has been found that has no base geometry", map.RepresentationLabel); } else { byte[] matrix = map.Matrix.ToArray(true); foreach (var geomId in geomIds) { geomMapTable.AddMapGeometry(geomId, map.EntityLabel, map.EntityTypeId, matrix, map.SurfaceStyleLabel); } mapTrans.Commit(); mapTrans.Begin(); } Interlocked.Increment(ref tally); if (progDelegate != null) { int newPercentage = Convert.ToInt32((double)tally / total * 100.0); if (newPercentage > percentageParsed) { percentageParsed = newPercentage; progDelegate(percentageParsed, "Meshing"); } } if (tally % 100 == 100) { mapTrans.Commit(); mapTrans.Begin(); } } mapTrans.Commit(); // Store model regions in the database. // all regions are stored for the project in one row and need to be desirialised to XbimRegionCollection before being enumerated on read. // // todo: bonghi: currently geometry labels of partitioned models are not stored, only their bounding box and count are. // mapTrans.Begin(); XbimRegionCollection regions = PartitionWorld(model, bounds); IfcProject project = model.IfcProject; int projectId = 0; if (project != null) projectId = Math.Abs(project.EntityLabel); geomMapTable.AddGeometry(projectId, XbimGeometryType.Region, IfcMetaData.IfcTypeId(typeof(IfcProject)), XbimMatrix3D.Identity.ToArray(), regions.ToArray()); mapTrans.Commit(); model.FreeTable(geomMapTable); if (progDelegate != null) { progDelegate(0, "Ready"); } } catch (Exception e2) { if (Logger != null) Logger.Warn("General Error Triangulating geometry", e2); } finally { } }
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)); } }
public override void SetGraph(TransformGraph transformGraph) { // TODO: Map NotImplementedException to this SharpDXException throw new NotImplementedException(); }