Hide menu
Loading...
Searching...
No Matches
bim/exploring/main.cxx

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.
//
// ****************************************************************************
#include <cadex/Base_String.hxx>
#include <cadex/Base_UTF16String.hxx>
#include <cadex/LicenseManager_Activate.h>
#include <cadex/ModelData_BIMBeam.hxx>
#include <cadex/ModelData_BIMBuilding.hxx>
#include <cadex/ModelData_BIMColumn.hxx>
#include <cadex/ModelData_BIMCustomGeometryElement.hxx>
#include <cadex/ModelData_BIMCompositeElement.hxx>
#include <cadex/ModelData_BIMConstructionElement.hxx>
#include <cadex/ModelData_BIMDoor.hxx>
#include <cadex/ModelData_BIMElement.hxx>
#include <cadex/ModelData_BIMFurniture.hxx>
#include <cadex/ModelData_BIMHost.hxx>
#include <cadex/ModelData_BIMMaterial.hxx>
#include <cadex/ModelData_BIMModel.hxx>
#include <cadex/ModelData_BIMPlate.hxx>
#include <cadex/ModelData_BIMPropertyLibrary.hxx>
#include <cadex/ModelData_BIMRailing.hxx>
#include <cadex/ModelData_BIMRoof.hxx>
#include <cadex/ModelData_BIMSite.hxx>
#include <cadex/ModelData_BIMSlab.hxx>
#include <cadex/ModelData_BIMStair.hxx>
#include <cadex/ModelData_BIMStorey.hxx>
#include <cadex/ModelData_BIMVisitor.hxx>
#include <cadex/ModelData_BIMWall.hxx>
#include <cadex/ModelData_BIMWindow.hxx>
#include <cadex/ModelData_ModelReader.hxx>
#include <iomanip>
#include <iostream>
#include <unordered_map>
#include "../../cadex_license.cxx"
using namespace std;
using namespace cadex;
class BimStructureVisitor : public ModelData_BIMVisitor
{
public:
void Visit (const ModelData_BIMBeam& theElement) override
{
cout << GetFiller() << theElement.Name() << endl;
myCounts["Beam"] += 1;
}
void Visit (const ModelData_BIMColumn& theElement) override
{
cout << GetFiller() << theElement.Name() << endl;
myCounts["Column"] += 1;
}
void Visit (const ModelData_BIMCustomGeometryElement& theElement) override
{
cout << GetFiller() << theElement.Name() << endl;
myCounts["CustomGeometryElement"] += 1;
}
void Visit (const ModelData_BIMDoor& theElement) override
{
cout << GetFiller() << theElement.Name() << endl;
myCounts["Door"] += 1;
}
void Visit (const ModelData_BIMFurniture& theElement) override
{
cout << GetFiller() << theElement.Name() << endl;
myCounts["Furniture"] += 1;
}
void Visit (const ModelData_BIMPlate& theElement) override
{
cout << GetFiller() << theElement.Name() << endl;
myCounts["Plate"] += 1;
}
void Visit (const ModelData_BIMRailing& theElement) override
{
cout << GetFiller() << theElement.Name() << endl;
myCounts["Railing"] += 1;
}
void Visit (const ModelData_BIMRoof& theElement) override
{
cout << GetFiller() << theElement.Name() << endl;
myCounts["Roof"] += 1;
}
void Visit (const ModelData_BIMSlab& theElement) override
{
cout << GetFiller() << theElement.Name() << endl;
myCounts["Slab"] += 1;
}
void Visit (const ModelData_BIMStair& theElement) override
{
cout << GetFiller() << theElement.Name() << endl;
myCounts["Stair"] += 1;
}
void Visit (const ModelData_BIMWall& theElement) override
{
cout << GetFiller() << theElement.Name() << endl;
myCounts["Wall"] += 1;
}
void Visit (const ModelData_BIMWindow& theElement) override
{
cout << GetFiller() << theElement.Name() << endl;
myCounts["Window"] += 1;
}
bool VisitEnter (const ModelData_BIMBuilding& theElement) override
{
cout << GetFiller() << theElement.Name() << endl;
myNestingLevel += 1;
myCounts["Building"] += 1;
return true;
}
void VisitLeave (const ModelData_BIMBuilding&) override
{
myNestingLevel -= 1;
}
bool VisitEnter (const ModelData_BIMSite& theElement) override
{
cout << GetFiller() << theElement.Name() << endl;;
myNestingLevel += 1;
myCounts["Site"] += 1;
return true;
}
void VisitLeave (const ModelData_BIMSite& ) override
{
myNestingLevel -= 1;
}
bool VisitEnter (const ModelData_BIMCompositeElement& theElement) override
{
cout << GetFiller() << theElement.Name() << endl;;
myNestingLevel += 1;
myCounts["CompositeElement"] += 1;
return true;
}
void VisitLeave (const ModelData_BIMCompositeElement& ) override
{
myNestingLevel -= 1;
}
bool VisitEnter (const ModelData_BIMStorey& theElement) override
{
cout << GetFiller() << theElement.Name() << endl;
myNestingLevel += 1;
myCounts["Storey"] += 1;
return true;
}
void VisitLeave (const ModelData_BIMStorey& ) override
{
myNestingLevel -= 1;
}
void PrintCounts ()
{
cout << "Element Types:" << endl;
for (const auto& aType : myCounts) {
cout << aType.first << ": " << aType.second << endl;
}
}
private:
string GetFiller() const
{
return string(4 * myNestingLevel, '-') + " ";
}
size_t myNestingLevel = 0;
unordered_map<string, size_t> myCounts;
};
int main (int argc, char *argv[])
{
auto aKey = LicenseKey::Value();
// Activate the license (aKey must be defined in cadex_license.cxx)
if (!CADExLicense_Activate (aKey)) {
cerr << "Failed to activate CAD Exchanger license." << endl;
return 1;
}
// Get the input
if (argc != 2) {
cerr << "Usage: " << argv[0] << " <input_file>, where:" << endl;
cerr << " <input_file> is a name of the file to be read" << endl;
return 1;
}
const char* aSource = argv[1];
cout << aSource << endl;
// Reading and converting the file
if (!aReader.Read (aSource, aModel)) {
cerr << "Failed to read the file: " << aSource << endl;
return 1;
}
// Create a Counter
BimStructureVisitor aStructureVisitor;
aModel.Accept (aStructureVisitor);
cout << endl;
aStructureVisitor.PrintCounts();
return 0;
}
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
bool Read(const Base_UTF16String &theFilePath, ModelData_Model &theModel)
Reads the file at the specified path into the specified model.
Definition: ModelData_ModelReader.cxx:182
Defines classes, types, and global functions related to CAD Exchanger.
Definition: A3DSTestLib.hxx:22