Hide menu
Loading...
Searching...
No Matches
bim/exploring/Program.cs

Refer to the BIM Model Exploring Example.

// ****************************************************************************
// $Id$
//
// Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
// Copyright (C) 2014-2023, CADEX. All rights reserved.
//
// This file is part of the CAD Exchanger software.
//
// You may use this file under the terms of the BSD license as follows:
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ****************************************************************************
using cadex;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
namespace bimexploring
{
class Program
{
// For more information see https://stackoverflow.com/questions/8836093/how-can-i-specify-a-dllimport-path-at-runtime
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern bool SetDllDirectory(string lpPathName);
static int Main(string[] args)
{
// Add runtime path to CAD Exchanger libraries (e.g. compiled with Visual Studio 2015)
SetDllDirectory("../../../../../../win64/vc14.1/bin");
string aKey = LicenseKey.Value();
// Activate the license (aKey must be defined in cadex_license.cs)
if (!LicenseManager.Activate (aKey))
{
Console.WriteLine("Failed to activate CAD Exchanger license.");
return 1;
}
if (args.Length != 1)
{
Console.WriteLine("Usage: " + System.Reflection.Assembly.GetExecutingAssembly().Location
+ " <input_file>, where:");
Console.WriteLine(" <input_file> is a name of the file to be read");
return 1;
}
string aSource = args[0];
// Reading and converting the file
if (!new ModelData_ModelReader().Read(new Base_UTF16String(aSource), aModel))
{
Console.WriteLine("Failed to read the file: " + aSource);
return 1;
}
// Create a Counter
BimStructureVisitor aStructureVisitor = new BimStructureVisitor();
aModel.Accept(aStructureVisitor);
Console.WriteLine();
aStructureVisitor.PrintCounts();
return 0;
}
}
class BimStructureVisitor : ModelData_BIMVisitor
{
public BimStructureVisitor()
{
myNestingLevel = 0;
}
public void PrintCounts()
{
Console.WriteLine("Element Types:");
foreach (KeyValuePair<string, int> i in myCounts)
{
Console.WriteLine("{0}: {1}", i.Key, i.Value);
}
}
public override bool VisitEnter(ModelData_BIMBuilding theElement)
{
Console.WriteLine(GetFiller() + theElement.Name());
myNestingLevel += 1;
AddCounts("Building");
return true;
}
public override void VisitLeave(ModelData_BIMBuilding theElement)
{
myNestingLevel -= 1;
}
public override bool VisitEnter(ModelData_BIMSite theElement)
{
Console.WriteLine(GetFiller() + theElement.Name());
myNestingLevel += 1;
AddCounts("Site");
return true;
}
public override void VisitLeave(ModelData_BIMSite theElement)
{
myNestingLevel -= 1;
}
public override bool VisitEnter(ModelData_BIMCompositeElement theElement)
{
Console.WriteLine(GetFiller() + theElement.Name());
myNestingLevel += 1;
AddCounts("CompositeElement");
return true;
}
public override void VisitLeave(ModelData_BIMCompositeElement theElement)
{
myNestingLevel -= 1;
}
public override bool VisitEnter(ModelData_BIMStorey theElement)
{
Console.WriteLine(GetFiller() + theElement.Name());
myNestingLevel += 1;
AddCounts("Storey");
return true;
}
public override void VisitLeave(ModelData_BIMStorey theElement)
{
myNestingLevel -= 1;
}
public override void Visit(ModelData_BIMBeam theElement)
{
Console.WriteLine(GetFiller() + " " + theElement.Name());
AddCounts("Beam");
}
public override void Visit(ModelData_BIMColumn theElement)
{
Console.WriteLine(GetFiller() + " " + theElement.Name());
AddCounts("Column");
}
public override void Visit(ModelData_BIMCustomGeometryElement theElement)
{
Console.WriteLine(GetFiller() + " " + theElement.Name());
AddCounts("CustomGeometryElement");
}
public override void Visit(ModelData_BIMDoor theElement)
{
Console.WriteLine(GetFiller() + " " + theElement.Name());
AddCounts("Door");
}
public override void Visit(ModelData_BIMFurniture theElement)
{
Console.WriteLine(GetFiller() + " " + theElement.Name());
AddCounts("Furniture");
}
public override void Visit(ModelData_BIMPlate theElement)
{
Console.WriteLine(GetFiller() + " " + theElement.Name());
AddCounts("Plate");
}
public override void Visit(ModelData_BIMRailing theElement)
{
Console.WriteLine(GetFiller() + " " + theElement.Name());
AddCounts("Railing");
}
public override void Visit(ModelData_BIMRoof theElement)
{
Console.WriteLine(GetFiller() + " " + theElement.Name());
AddCounts("Roof");
}
public override void Visit(ModelData_BIMSlab theElement)
{
Console.WriteLine(GetFiller() + " " + theElement.Name());
AddCounts("Slab");
}
public override void Visit(ModelData_BIMStair theElement)
{
Console.WriteLine(GetFiller() + " " + theElement.Name());
AddCounts("Stair");
}
public override void Visit(ModelData_BIMWall theElement)
{
Console.WriteLine(GetFiller() + " " + theElement.Name());
AddCounts("Wall");
}
public override void Visit(ModelData_BIMWindow theElement)
{
Console.WriteLine(GetFiller() + " " + theElement.Name());
AddCounts("Window");
}
private string GetFiller()
{
IEnumerable<string> aTabs = Enumerable.Repeat("-", 4*myNestingLevel);
return (myNestingLevel > 0) ? aTabs.Aggregate((sum, next) => sum + next) : "";
}
private void AddCounts(string theElementType)
{
if (!myCounts.ContainsKey(theElementType))
{
myCounts.Add(theElementType, 1);
}
else
{
myCounts[theElementType] += 1;
}
}
private Dictionary<string, int> myCounts = new Dictionary<string, int>();
private int myNestingLevel;
}
}
Defines a Unicode (UTF-16) string wrapping a standard string.
Definition: Base_UTF16String.hxx:34
const Base_UTF16String & Name() const
Returns an element name.
Definition: ModelData_BIMBaseObject.cxx:62
Beam represents a structural element that resists bending or lateraly loads.
Definition: ModelData_BIMBeam.hxx:30
Building is an element of spatial structure hierarchy (together with site, storey,...
Definition: ModelData_BIMBuilding.hxx:33
Column represents structural or architectural vertical element, that can transmit loads from top elem...
Definition: ModelData_BIMColumn.hxx:30
Composite Element represents the complex BIM Element, consisting of several other BIM Elements....
Definition: ModelData_BIMCompositeElement.hxx:30
CustomGeometryElement represents general bim element with geometry for defining elements that have no...
Definition: ModelData_BIMCustomGeometryElement.hxx:30
Door element can be used for represent standard entrance or internal doors, gates,...
Definition: ModelData_BIMDoor.hxx:30
Furniture represents element for defining furnishings such as a table, chair, cabinet,...
Definition: ModelData_BIMFurniture.hxx:30
Provides CAD Exchanger BIM data model.
Definition: ModelData_BIMModel.hxx:37
void Accept(ModelData_BIMVisitor &theVisitor) const
Accepts a visitor.
Definition: ModelData_BIMModel.cxx:510
Plate represents planar element, that is often add-on part for wall, roof or slab.
Definition: ModelData_BIMPlate.hxx:30
Railing represents a frame assembly for physical support, fall prevention and also decorating.
Definition: ModelData_BIMRailing.hxx:30
Roof represents covering element of the top part of a building.
Definition: ModelData_BIMRoof.hxx:30
Site represents the area of land, on which the building construction is to be. Often,...
Definition: ModelData_BIMSite.hxx:32
Slab represents an element that encloses a building space vertically. The slab may provide the floor ...
Definition: ModelData_BIMSlab.hxx:30
Stair represents a passageway allowing persons to step from one level to another level at a different...
Definition: ModelData_BIMStair.hxx:30
Storey represents a horizontal aggregation of building spaces that are vertically bound and are all a...
Definition: ModelData_BIMStorey.hxx:32
Defines a BIM elements visitor.
Definition: ModelData_BIMVisitor.hxx:42
Wall represents an element that bounds or subdivides building spaces. Wall are usually vertical,...
Definition: ModelData_BIMWall.hxx:30
Window element can represent vertical, sloped or horizontal window in the wall or roof,...
Definition: ModelData_BIMWindow.hxx:30
Reads any format that CAD Exchanger can import.
Definition: ModelData_ModelReader.hxx:33
Defines classes, types, and global functions related to CAD Exchanger.
Definition: A3DSTestLib.hxx:22