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

Refer to the Drawing Exploration Example.

// ****************************************************************************
// $Id$
//
// Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
// Copyright (C) 2014-2025, CADEX. All rights reserved.
//
// This file is part of the Manufacturing Toolkit 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/LicenseManager_Activate.h>
#include <cadex/Drawing/Drawing.hxx>
#include <cadex/Drawing/ElementVisitor.hxx>
#include <cadex/Drawing/Geometry.hxx>
#include <cadex/Drawing/Hatch.hxx>
#include <cadex/Drawing/Sheet.hxx>
#include <cadex/Drawing/Text.hxx>
#include <cadex/Drawing/View.hxx>
#include <cadex/Geom/Point2d.hxx>
#include <cadex/ModelData/Model.hxx>
#include <cadex/ModelData/ModelReader.hxx>
#include <cadex/ModelData/ModelReaderParameters.hxx>
#include <iostream>
#include "../../mtk_license.cxx"
using namespace std;
using namespace cadex;
// Explore view content
class DrawingElementVisitor : public Drawing::ElementVoidVisitor
{
public:
void operator() (const Drawing::CurveSet& theElement) override
{
cout << "------- CurveSet <" << myCurveSetCounter << ">" << endl;
cout << "--------- number of curves: " << theElement.NumberOfCurves() << endl;
myCurveSetCounter++;
}
void operator() (const Drawing::Hatch& theElement) override
{
cout << "------- Hatch <" << myHatchCounter << ">" << endl;
cout << "--------- number of contours: " << theElement.NumberOfContours() << endl;
size_t aNumberOfCurves = 0;
for (size_t i = 0; i < theElement.NumberOfContours(); ++i) {
aNumberOfCurves += theElement.Contour (i).NumberOfCurves();
}
cout << "--------- number of curves: " << aNumberOfCurves << endl;
cout << "--------- pattern: " << PatternToString (theElement.Pattern()) << endl;
cout << "--------- angle: " << theElement.Angle() << endl;
cout << "--------- scale: " << theElement.Scale() << endl;
myHatchCounter++;
}
void operator() (const Drawing::Text& theElement) override
{
cout << "------- Text <" << myTextCounter << ">" << endl;
cout << "--------- text: \"" << theElement.GetText() << "\"" << endl;
cout << "--------- origin: " << PointToString (theElement.TextOrigin()) << endl;
cout << "--------- rotation: " << theElement.TextProperties().Rotation() << endl;
cout << "--------- font size: " << theElement.FontSize() << endl;
myTextCounter++;
}
private:
string PointToString (const Geom::Point2d& thePoint)
{
return "(" + std::to_string (thePoint.X()) + "; " + std::to_string (thePoint.Y()) + ")";
}
string PatternToString (const Drawing::Hatch::PatternType& thePattern)
{
switch (thePattern) {
case Drawing::Hatch::PatternType::Solid: return "Solid";
case Drawing::Hatch::PatternType::ANSI_31: return "ANSI 31";
case Drawing::Hatch::PatternType::ANSI_32: return "ANSI 32";
case Drawing::Hatch::PatternType::ANSI_33: return "ANSI 33";
case Drawing::Hatch::PatternType::ANSI_34: return "ANSI 34";
case Drawing::Hatch::PatternType::ANSI_35: return "ANSI 35";
case Drawing::Hatch::PatternType::ANSI_36: return "ANSI 36";
case Drawing::Hatch::PatternType::ANSI_37: return "ANSI 37";
case Drawing::Hatch::PatternType::ANSI_38: return "ANSI 38";
case Drawing::Hatch::PatternType::ISO_02: return "ISO 02";
case Drawing::Hatch::PatternType::ISO_03: return "ISO 03";
case Drawing::Hatch::PatternType::ISO_04: return "ISO 04";
case Drawing::Hatch::PatternType::ISO_05: return "ISO 05";
case Drawing::Hatch::PatternType::ISO_06: return "ISO 06";
case Drawing::Hatch::PatternType::ISO_07: return "ISO 07";
case Drawing::Hatch::PatternType::ISO_08: return "ISO 08";
case Drawing::Hatch::PatternType::ISO_09: return "ISO 09";
case Drawing::Hatch::PatternType::ISO_10: return "ISO 10";
case Drawing::Hatch::PatternType::ISO_11: return "ISO 11";
case Drawing::Hatch::PatternType::ISO_12: return "ISO 12";
case Drawing::Hatch::PatternType::ISO_13: return "ISO 13";
case Drawing::Hatch::PatternType::ISO_14: return "ISO 14";
case Drawing::Hatch::PatternType::ISO_15: return "ISO 15";
default: return "Other";
}
}
size_t myCurveSetCounter = 0;
size_t myHatchCounter = 0;
size_t myTextCounter = 0;
};
// Iterate views
void ExploreSheet (const Drawing::Sheet& theSheet)
{
Drawing::Sheet::ViewIterator aViewIt (theSheet);
size_t aViewCounter = 0;
while (aViewIt.HasNext()) {
const auto& aView = aViewIt.Next();
cout << "---- View <" << aViewCounter << ">" << endl;
DrawingElementVisitor aVisitor;
aView.Accept (aVisitor);
aViewCounter++;
}
}
// Iterate sheets
void ExploreDrawing (const Drawing::Drawing& theDrawing)
{
Drawing::Drawing::SheetIterator aSheetIt (theDrawing);
size_t aSheetCounter = 0;
while (aSheetIt.HasNext()) {
const auto& aSheet = aSheetIt.Next();
cout << "-- Sheet <" << aSheetCounter << ">" << endl;
ExploreSheet (aSheet);
aSheetCounter++;
}
}
int main (int argc, char* argv[])
{
auto aKey = MTKLicenseKey::Value();
// Activate the license (aKey must be defined in mtk_license.cxx)
if (!CADExLicense_Activate (aKey)) {
cerr << "Failed to activate Manufacturing Toolkit 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];
// Enable drawings reading
aReaderParameters.SetReadDrawing (true);
aReader.SetParameters (aReaderParameters);
if (!aReader.Read (aSource, aModel)) {
cerr << "Failed to read the file " << aSource << endl;
return 1;
}
Drawing::Drawing aDrawing = aModel.Drawing();
if (aDrawing.IsNull()) {
cerr << "The model doesn't contain a drawing" << endl;
return 1;
}
cout << "Drawing \"" << aModel.Name() << "\":" << endl;
ExploreDrawing (aDrawing);
return 0;
}
Describes drawing elements composed of 2D curves.
Definition CurveSet.cs:20
uint NumberOfCurves()
Returns the number of curves currently composing the element.
Definition CurveSet.cs:67
Iterator over sheets of a drawing.
Definition Drawing.cs:108
Represents a single 2D drawing of a model.
Definition Drawing.cs:33
Defines a visitor for drawing elements with empty implementation.
Definition ElementVoidVisitor.cs:20
Represents an area filled with a pattern.
Definition Hatch.cs:37
PatternType
Definition Hatch.cs:196
cadex.Drawing.Hatch.PatternType Pattern()
Returns the pattern of the hatch.
Definition Hatch.cs:133
double Scale()
Returns the scale of the hatch.
Definition Hatch.cs:144
double Angle()
Returns the angle of the hatch.
Definition Hatch.cs:155
uint NumberOfContours()
Returns the number of hatch contours.
Definition Hatch.cs:93
cadex.Drawing.PiecewiseContour Contour(uint theIndex)
Returns the contour.
Definition Hatch.cs:102
Iterates over views of a drawing sheet.
Definition Sheet.cs:177
Represents a single sheet of a model drawing.
Definition Sheet.cs:33
Defines a text for drawing.
Definition Text.cs:19
cadex.Geom.Point2d TextOrigin()
Returns a position of the text on the 2D plane.
Definition Text.cs:181
float FontSize()
Returns size of the font in points.
Definition Text.cs:193
cadex.UTF16String GetText()
Returns a text.
Definition Text.cs:168
cadex.Drawing.Text.Properties TextProperties()
Returns the properties of dimension text.
Definition Text.cs:205
Defines a 3D point.
Definition Point2d.cs:17
Provides MTK data model.
Definition Model.cs:30
cadex.UTF16String Name()
Returns a model name.
Definition Model.cs:93
Reads supported formats, see Import section.
Definition ModelReader.cs:17
bool Read(cadex.UTF16String theFilePath, cadex.ModelData.Model theModel)
Reads the file at the specified path into the specified model.
Definition ModelReader.cs:86
void SetParameters(cadex.ModelData.ModelReaderParameters theParameters)
Sets reader parameters.
Definition ModelReader.cs:67
Defines parameters of the ModelReader.
Definition ModelReaderParameters.cs:19
void SetReadDrawing(bool theReadDrawing)
Sets whether a drawing should be read from the file.
Definition ModelReaderParameters.cs:98
Contains classes, namespaces, enums, types, and global functions related to Manufacturing Toolkit.
Definition BaseObject.cs:12