From 225966dceddacfad09b3151705e8b0f6b825485c Mon Sep 17 00:00:00 2001 From: Aik-Siong Koh Date: Wed, 19 Jul 2023 09:41:17 -0600 Subject: [PATCH] ExternalSystem class --- MbDCode/ASMTAssembly.cpp | 563 ++++++++++-------- MbDCode/ASMTAssembly.h | 34 +- MbDCode/ASMTConstraintSet.cpp | 58 ++ MbDCode/ASMTConstraintSet.h | 10 + MbDCode/ASMTItem.cpp | 44 +- MbDCode/ASMTItem.h | 15 +- MbDCode/ASMTJoint.cpp | 35 +- MbDCode/ASMTJoint.h | 4 +- MbDCode/ASMTMarker.cpp | 39 +- MbDCode/ASMTMarker.h | 8 +- MbDCode/ASMTMotion.cpp | 18 + MbDCode/ASMTMotion.h | 3 + MbDCode/ASMTPart.cpp | 193 +++--- MbDCode/ASMTPart.h | 15 +- MbDCode/ASMTPrincipalMassMarker.h | 1 - MbDCode/ASMTRefPoint.cpp | 78 +-- MbDCode/ASMTRefPoint.h | 8 +- MbDCode/ASMTRotationalMotion.cpp | 29 +- MbDCode/ASMTRotationalMotion.h | 4 +- MbDCode/ASMTSpatialContainer.cpp | 192 ++++++ MbDCode/ASMTSpatialContainer.h | 47 ++ MbDCode/ASMTSpatialItem.cpp | 59 ++ MbDCode/ASMTSpatialItem.h | 20 + MbDCode/ASMTTranslationalMotion.h | 2 +- MbDCode/CADSystem.h | 2 +- MbDCode/ExternalSystem.cpp | 31 + MbDCode/ExternalSystem.h | 32 + MbDCode/MbDCode.cpp | 4 +- MbDCode/MbDCode.vcxproj | 10 +- MbDCode/MbDCode.vcxproj.filters | 22 +- MbDCode/Part.cpp | 4 +- .../{DataPosVelAcc.cpp => PosVelAccData.cpp} | 4 +- MbDCode/{DataPosVelAcc.h => PosVelAccData.h} | 4 +- MbDCode/System.cpp | 4 +- MbDCode/System.h | 5 +- 35 files changed, 1069 insertions(+), 532 deletions(-) create mode 100644 MbDCode/ASMTSpatialContainer.cpp create mode 100644 MbDCode/ASMTSpatialContainer.h create mode 100644 MbDCode/ASMTSpatialItem.cpp create mode 100644 MbDCode/ASMTSpatialItem.h create mode 100644 MbDCode/ExternalSystem.cpp create mode 100644 MbDCode/ExternalSystem.h rename MbDCode/{DataPosVelAcc.cpp => PosVelAccData.cpp} (80%) rename MbDCode/{DataPosVelAcc.h => PosVelAccData.h} (75%) diff --git a/MbDCode/ASMTAssembly.cpp b/MbDCode/ASMTAssembly.cpp index 304d873..be25d1c 100644 --- a/MbDCode/ASMTAssembly.cpp +++ b/MbDCode/ASMTAssembly.cpp @@ -33,259 +33,334 @@ void MbD::ASMTAssembly::runFile(const char* chars) void MbD::ASMTAssembly::parseASMT(std::vector& lines) { - size_t pos = lines[0].find_first_not_of("\t"); - auto leadingTabs = lines[0].substr(0, pos); - while (!lines.empty()) { - if (lines[0] == (leadingTabs + "Notes")) { - lines.erase(lines.begin()); - notes = lines[0]; - lines.erase(lines.begin()); + readNotes(lines); + readName(lines); + readPosition3D(lines); + readRotationMatrix(lines); + readVelocity3D(lines); + readOmega3D(lines); + readRefPoints(lines); + readRefCurves(lines); + readRefSurfaces(lines); + readParts(lines); + readKinematicIJs(lines); + readConstraintSets(lines); + readForceTorques(lines); + readConstantGravity(lines); + readSimulationParameters(lines); + readAnimationParameters(lines); + readTimeSeries(lines); + readAssemblySeries(lines); + readPartSeriesMany(lines); + readJointSeriesMany(lines); + readMotionSeriesMany(lines); +} + +void MbD::ASMTAssembly::readNotes(std::vector& lines) +{ + assert(lines[0] == "\tNotes"); + lines.erase(lines.begin()); + notes = readString(lines[0]); + lines.erase(lines.begin()); +} + +void MbD::ASMTAssembly::readParts(std::vector& lines) +{ + assert(lines[0] == "\tParts"); + lines.erase(lines.begin()); + parts = std::make_shared>>(); + auto it = std::find(lines.begin(), lines.end(), "\tKinematicIJs"); + std::vector partsLines(lines.begin(), it); + while (!partsLines.empty()) { + readPart(partsLines); + } + lines.erase(lines.begin(), it); + +} + +void MbD::ASMTAssembly::readPart(std::vector& lines) +{ + assert(lines[0] == "\t\tPart"); + lines.erase(lines.begin()); + auto part = CREATE::With(); + part->parseASMT(lines); + parts->push_back(part); + part->owner = this; +} + +void MbD::ASMTAssembly::readKinematicIJs(std::vector& lines) +{ + assert(lines[0] == "\tKinematicIJs"); + lines.erase(lines.begin()); + kinematicIJs = std::make_shared>>(); + auto it = std::find(lines.begin(), lines.end(), "\tConstraintSets"); + std::vector kinematicIJsLines(lines.begin(), it); + while (!kinematicIJsLines.empty()) { + readKinematicIJ(kinematicIJsLines); + } + lines.erase(lines.begin(), it); + +} + +void MbD::ASMTAssembly::readKinematicIJ(std::vector& lines) +{ + assert(false); +} + +void MbD::ASMTAssembly::readConstraintSets(std::vector& lines) +{ + assert(lines[0] == "\tConstraintSets"); + lines.erase(lines.begin()); + readJoints(lines); + readMotions(lines); + readGeneralConstraintSets(lines); +} + +void MbD::ASMTAssembly::readJoints(std::vector& lines) +{ + assert(lines[0] == "\t\tJoints"); + lines.erase(lines.begin()); + joints = std::make_shared>>(); + auto it = std::find(lines.begin(), lines.end(), "\t\tMotions"); + std::vector jointsLines(lines.begin(), it); + std::shared_ptr joint; + while (!jointsLines.empty()) { + if (jointsLines[0] == "\t\t\tRevoluteJoint") { + joint = CREATE::With(); } - else if (lines[0] == (leadingTabs + "Name")) { - lines.erase(lines.begin()); - name = lines[0]; - lines.erase(lines.begin()); + else if (jointsLines[0] == "\t\t\tCylindricalJoint") { + joint = CREATE::With(); } - else if (lines[0] == (leadingTabs + "Position3D")) { - lines.erase(lines.begin()); - std::istringstream iss(lines[0]); - position3D = std::make_shared>(); - double d; - while (iss >> d) { - position3D->push_back(d); - } - lines.erase(lines.begin()); + else { + assert(false); } - else if (lines[0] == (leadingTabs + "RotationMatrix")) { - lines.erase(lines.begin()); - rotationMatrix = std::make_shared>(3, 0); - for (int i = 0; i < 3; i++) - { - auto& row = rotationMatrix->at(i); - std::istringstream iss(lines[0]); - double d; - while (iss >> d) { - row->push_back(d); - } - lines.erase(lines.begin()); - } + jointsLines.erase(jointsLines.begin()); + joint->parseASMT(jointsLines); + joints->push_back(joint); + joint->owner = this; + } + lines.erase(lines.begin(), it); + +} + +void MbD::ASMTAssembly::readMotions(std::vector& lines) +{ + assert(lines[0] == "\t\tMotions"); + lines.erase(lines.begin()); + motions = std::make_shared>>(); + auto it = std::find(lines.begin(), lines.end(), "\t\tGeneralConstraintSets"); + std::vector motionsLines(lines.begin(), it); + std::shared_ptr motion; + while (!motionsLines.empty()) { + if (motionsLines[0] == "\t\t\tRotationalMotion") { + motion = CREATE::With(); } - else if (lines[0] == (leadingTabs + "Velocity3D")) { - lines.erase(lines.begin()); - std::istringstream iss(lines[0]); - velocity3D = std::make_shared>(); - double d; - while (iss >> d) { - velocity3D->push_back(d); - } - lines.erase(lines.begin()); + else if (motionsLines[0] == "\t\t\tTranslationalMotion") { + motion = CREATE::With(); } - else if (lines[0] == (leadingTabs + "Omega3D")) { - lines.erase(lines.begin()); - std::istringstream iss(lines[0]); - omega3D = std::make_shared>(); - double d; - while (iss >> d) { - omega3D->push_back(d); - } - lines.erase(lines.begin()); + else { + assert(false); } - else if (lines[0] == (leadingTabs + "RefPoints")) { - lines.erase(lines.begin()); - refPoints = std::make_shared>>(); - auto it = std::find(lines.begin(), lines.end(), (leadingTabs + "RefCurves")); - std::vector refPointsLines(lines.begin(), it); - while (!refPointsLines.empty()) { - if (refPointsLines[0] == (leadingTabs + "\tRefPoint")) { - refPointsLines.erase(refPointsLines.begin()); - auto refPoint = CREATE::With(); - refPoint->parseASMT(refPointsLines); - refPoints->push_back(refPoint); - refPoint->owner = this; - } - else { - assert(false); - } - } - lines.erase(lines.begin(), it); - } - else if (lines[0] == (leadingTabs + "RefCurves")) { - lines.erase(lines.begin()); - refCurves = std::make_shared>>(); - auto it = std::find(lines.begin(), lines.end(), (leadingTabs + "RefSurfaces")); - std::vector refCurvesLines(lines.begin(), it); - while (!refCurvesLines.empty()) { - if (refCurvesLines[0] == (leadingTabs + "\tRefCurve")) { - refCurvesLines.erase(refCurvesLines.begin()); - auto refCurve = CREATE::With(); - refCurve->parseASMT(refCurvesLines); - refCurves->push_back(refCurve); - refCurve->owner = this; - } - else { - assert(false); - } - } - lines.erase(lines.begin(), it); - } - else if (lines[0] == (leadingTabs + "RefSurfaces")) { - lines.erase(lines.begin()); - refSurfaces = std::make_shared>>(); - auto it = std::find(lines.begin(), lines.end(), (leadingTabs + "Parts")); - std::vector refSurfacesLines(lines.begin(), it); - while (!refSurfacesLines.empty()) { - if (refSurfacesLines[0] == (leadingTabs + "\tRefSurface")) { - refSurfacesLines.erase(refSurfacesLines.begin()); - auto refSurface = CREATE::With(); - refSurface->parseASMT(refSurfacesLines); - refSurfaces->push_back(refSurface); - refSurface->owner = this; - } - else { - assert(false); - } - } - lines.erase(lines.begin(), it); - } - else if (lines[0] == (leadingTabs + "Parts")) { - lines.erase(lines.begin()); - parts = std::make_shared>>(); - auto it = std::find(lines.begin(), lines.end(), (leadingTabs + "KinematicIJs")); - std::vector partsLines(lines.begin(), it); - while (!partsLines.empty()) { - if (partsLines[0] == (leadingTabs + "\tPart")) { - partsLines.erase(partsLines.begin()); - auto part = CREATE::With(); - part->parseASMT(partsLines); - parts->push_back(part); - part->owner = this; - } - else { - assert(false); - } - } - lines.erase(lines.begin(), it); - } - else if (lines[0] == (leadingTabs + "KinematicIJs")) { - lines.erase(lines.begin()); - kinematicIJs = std::make_shared>>(); - auto it = std::find(lines.begin(), lines.end(), (leadingTabs + "ConstraintSets")); - std::vector kinematicIJsLines(lines.begin(), it); - while (!kinematicIJsLines.empty()) { - if (kinematicIJsLines[0] == (leadingTabs + "\tKinematicIJ")) { - kinematicIJsLines.erase(kinematicIJsLines.begin()); - auto kinematicIJ = CREATE::With(); - kinematicIJ->parseASMT(kinematicIJsLines); - kinematicIJs->push_back(kinematicIJ); - kinematicIJ->owner = this; - } - else { - assert(false); - } - } - lines.erase(lines.begin(), it); - } - else if (lines[0] == (leadingTabs + "ConstraintSets")) { - lines.erase(lines.begin()); - assert(lines[0] == (leadingTabs + "\tJoints")); - lines.erase(lines.begin()); - joints = std::make_shared>>(); - auto it = std::find(lines.begin(), lines.end(), (leadingTabs + "\tMotions")); - std::vector jointsLines(lines.begin(), it); - while (!jointsLines.empty()) { - if (jointsLines[0] == (leadingTabs + "\t\tRevoluteJoint")) { - jointsLines.erase(jointsLines.begin()); - auto joint = CREATE::With(); - joint->parseASMT(jointsLines); - joints->push_back(joint); - joint->owner = this; - } - else if (jointsLines[0] == (leadingTabs + "\t\tCylindricalJoint")) { - jointsLines.erase(jointsLines.begin()); - auto joint = CREATE::With(); - joint->parseASMT(jointsLines); - joints->push_back(joint); - joint->owner = this; - } - else { - assert(false); - } - } - lines.erase(lines.begin(), it); - assert(lines[0] == (leadingTabs + "\tMotions")); - lines.erase(lines.begin()); - motions = std::make_shared>>(); - it = std::find(lines.begin(), lines.end(), (leadingTabs + "\tGeneralConstraintSets")); - std::vector motionsLines(lines.begin(), it); - while (!motionsLines.empty()) { - if (motionsLines[0] == (leadingTabs + "\t\tRotationalMotion")) { - motionsLines.erase(motionsLines.begin()); - auto motion = CREATE::With(); - motion->parseASMT(motionsLines); - motions->push_back(motion); - motion->owner = this; - } - else if (motionsLines[0] == (leadingTabs + "\t\tTranslationalMotion")) { - motionsLines.erase(motionsLines.begin()); - auto motion = CREATE::With(); - motion->parseASMT(motionsLines); - motions->push_back(motion); - motion->owner = this; - } - else { - assert(false); - } - } - lines.erase(lines.begin(), it); - assert(lines[0] == (leadingTabs + "\tGeneralConstraintSets")); - lines.erase(lines.begin()); - constraintSets = std::make_shared>>(); - it = std::find(lines.begin(), lines.end(), (leadingTabs + "ForceTorques")); - std::vector generalConstraintSetsLines(lines.begin(), it); - while (!generalConstraintSetsLines.empty()) { - assert(false); - } - lines.erase(lines.begin(), it); - } - else if (lines[0] == (leadingTabs + "ForceTorques")) { - lines.erase(lines.begin()); - forceTorques = std::make_shared>>(); - auto it = std::find(lines.begin(), lines.end(), (leadingTabs + "ConstantGravity")); - std::vector forceTorquesLines(lines.begin(), it); - while (!forceTorquesLines.empty()) { - if (forceTorquesLines[0] == (leadingTabs + "\tForceTorque")) { - forceTorquesLines.erase(forceTorquesLines.begin()); - auto forceTorque = CREATE::With(); - forceTorque->parseASMT(forceTorquesLines); - forceTorques->push_back(forceTorque); - forceTorque->owner = this; - } - else { - assert(false); - } - } - lines.erase(lines.begin(), it); - } - else if (lines[0] == (leadingTabs + "ConstantGravity")) { - lines.erase(lines.begin()); - constantGravity = CREATE::With(); - constantGravity->parseASMT(lines); - constantGravity->owner = this; - } - else if (lines[0] == (leadingTabs + "SimulationParameters")) { - lines.erase(lines.begin()); - simulationParameters = CREATE::With(); - simulationParameters->parseASMT(lines); - simulationParameters->owner = this; - } - else if (lines[0] == (leadingTabs + "AnimationParameters")) { - lines.erase(lines.begin()); - animationParameters = CREATE::With(); - animationParameters->parseASMT(lines); - animationParameters->owner = this; + motionsLines.erase(motionsLines.begin()); + motion->parseASMT(motionsLines); + motions->push_back(motion); + motion->owner = this; + } + lines.erase(lines.begin(), it); + +} + +void MbD::ASMTAssembly::readGeneralConstraintSets(std::vector& lines) +{ + assert(lines[0] == "\t\tGeneralConstraintSets"); + lines.erase(lines.begin()); + constraintSets = std::make_shared>>(); + auto it = std::find(lines.begin(), lines.end(), "\tForceTorques"); + std::vector generalConstraintSetsLines(lines.begin(), it); + while (!generalConstraintSetsLines.empty()) { + assert(false); + } + lines.erase(lines.begin(), it); +} + +void MbD::ASMTAssembly::readForceTorques(std::vector& lines) +{ + assert(lines[0] == "\tForceTorques"); + lines.erase(lines.begin()); + forceTorques = std::make_shared>>(); + auto it = std::find(lines.begin(), lines.end(), "\tConstantGravity"); + std::vector forceTorquesLines(lines.begin(), it); + while (!forceTorquesLines.empty()) { + if (forceTorquesLines[0] == "\t\tForceTorque") { + forceTorquesLines.erase(forceTorquesLines.begin()); + auto forceTorque = CREATE::With(); + forceTorque->parseASMT(forceTorquesLines); + forceTorques->push_back(forceTorque); + forceTorque->owner = this; } else { assert(false); } } + lines.erase(lines.begin(), it); } + +void MbD::ASMTAssembly::readConstantGravity(std::vector& lines) +{ + assert(lines[0] == "\tConstantGravity"); + lines.erase(lines.begin()); + constantGravity = CREATE::With(); + constantGravity->parseASMT(lines); + constantGravity->owner = this; +} + +void MbD::ASMTAssembly::readSimulationParameters(std::vector& lines) +{ + assert(lines[0] == "\tSimulationParameters"); + lines.erase(lines.begin()); + simulationParameters = CREATE::With(); + simulationParameters->parseASMT(lines); + simulationParameters->owner = this; +} + +void MbD::ASMTAssembly::readAnimationParameters(std::vector& lines) +{ + assert(lines[0] == "\tAnimationParameters"); + lines.erase(lines.begin()); + animationParameters = CREATE::With(); + animationParameters->parseASMT(lines); + animationParameters->owner = this; +} + +void MbD::ASMTAssembly::readTimeSeries(std::vector& lines) +{ + assert(lines[0] == "TimeSeries"); + lines.erase(lines.begin()); + assert(lines[0].find("Number\tInput") != std::string::npos); + lines.erase(lines.begin()); + readTimes(lines); +} + +void MbD::ASMTAssembly::readTimes(std::vector& lines) +{ + std::string str = lines[0]; + std::string substr = "Time\tInput"; + auto pos = str.find(substr); + assert(pos != std::string::npos); + str.erase(0, pos + substr.length()); + times = readRowOfDoubles(str); + times->insert(times->begin(), times->at(0)); //The first element is the input state. + lines.erase(lines.begin()); +} + +void MbD::ASMTAssembly::readPartSeriesMany(std::vector& lines) +{ + assert(lines[0].find("PartSeries") != std::string::npos); + auto it = std::find_if(lines.begin(), lines.end(), [](const std::string& s) { + return s.find("JointSeries") != std::string::npos; + }); + std::vector partSeriesLines(lines.begin(), it); + while (!partSeriesLines.empty()) { + readPartSeries(partSeriesLines); + } + lines.erase(lines.begin(), it); +} + +void MbD::ASMTAssembly::readJointSeriesMany(std::vector& lines) +{ + assert(lines[0].find("JointSeries") != std::string::npos); + auto it = std::find_if(lines.begin(), lines.end(), [](const std::string& s) { + return s.find("MotionSeries") != std::string::npos; + }); + std::vector jointSeriesLines(lines.begin(), it); + while (!jointSeriesLines.empty()) { + readJointSeries(jointSeriesLines); + } + lines.erase(lines.begin(), it); +} + +void MbD::ASMTAssembly::readAssemblySeries(std::vector& lines) +{ + std::string str = lines[0]; + std::string substr = "AssemblySeries"; + auto pos = str.find(substr); + assert(pos != std::string::npos); + str.erase(0, pos + substr.length()); + auto seriesName = readString(str); + assert(fullName("") == seriesName); + lines.erase(lines.begin()); + //xs, ys, zs, bryxs, bryys, bryzs + readXs(lines); + readYs(lines); + readZs(lines); + readBryantxs(lines); + readBryantys(lines); + readBryantzs(lines); + readVXs(lines); + readVYs(lines); + readVZs(lines); + readOmegaXs(lines); + readOmegaYs(lines); + readOmegaZs(lines); + readAXs(lines); + readAYs(lines); + readAZs(lines); + readAlphaXs(lines); + readAlphaYs(lines); + readAlphaZs(lines); +} + +void MbD::ASMTAssembly::readPartSeries(std::vector& lines) +{ + std::string str = lines[0]; + std::string substr = "PartSeries"; + auto pos = str.find(substr); + assert(pos != std::string::npos); + str.erase(0, pos + substr.length()); + auto seriesName = readString(str); + auto it = std::find_if(parts->begin(), parts->end(), [&](const std::shared_ptr& prt) { + return prt->fullName("") == seriesName; + }); + auto part = *it; + part->readPartSeries(lines); +} + +void MbD::ASMTAssembly::readJointSeries(std::vector& lines) +{ + std::string str = lines[0]; + std::string substr = "JointSeries"; + auto pos = str.find(substr); + assert(pos != std::string::npos); + str.erase(0, pos + substr.length()); + auto seriesName = readString(str); + auto it = std::find_if(joints->begin(), joints->end(), [&](const std::shared_ptr& jt) { + return jt->fullName("") == seriesName; + }); + auto joint = *it; + joint->readJointSeries(lines); +} + +void MbD::ASMTAssembly::readMotionSeriesMany(std::vector& lines) +{ + assert(lines[0].find("MotionSeries") != std::string::npos); + while (!lines.empty()) { + readMotionSeries(lines); + } +} + +void MbD::ASMTAssembly::readMotionSeries(std::vector& lines) +{ + std::string str = lines[0]; + std::string substr = "MotionSeries"; + auto pos = str.find(substr); + assert(pos != std::string::npos); + str.erase(0, pos + substr.length()); + auto seriesName = readString(str); + auto it = std::find_if(motions->begin(), motions->end(), [&](const std::shared_ptr& jt) { + return jt->fullName("") == seriesName; + }); + auto motion = *it; + motion->readMotionSeries(lines); +} + + diff --git a/MbDCode/ASMTAssembly.h b/MbDCode/ASMTAssembly.h index 05fe34d..799b16f 100644 --- a/MbDCode/ASMTAssembly.h +++ b/MbDCode/ASMTAssembly.h @@ -1,7 +1,7 @@ #pragma once #include -#include "ASMTItem.h" +#include "ASMTSpatialContainer.h" #include "ASMTRefPoint.h" #include "ASMTRefCurve.h" #include "ASMTRefSurface.h" @@ -18,19 +18,36 @@ #include "ASMTMotion.h" namespace MbD { - class ASMTAssembly : public ASMTItem + class ASMTAssembly : public ASMTSpatialContainer { // public: static void runFile(const char* chars); void parseASMT(std::vector& lines) override; + void readNotes(std::vector& lines); + void readParts(std::vector& lines); + void readPart(std::vector& lines); + void readKinematicIJs(std::vector& lines); + void readKinematicIJ(std::vector& lines); + void readConstraintSets(std::vector& lines); + void readJoints(std::vector& lines); + void readMotions(std::vector& lines); + void readGeneralConstraintSets(std::vector& lines); + void readForceTorques(std::vector& lines); + void readConstantGravity(std::vector& lines); + void readSimulationParameters(std::vector& lines); + void readAnimationParameters(std::vector& lines); + void readTimeSeries(std::vector& lines); + void readTimes(std::vector& lines); + void readAssemblySeries(std::vector& lines); + void readPartSeriesMany(std::vector& lines); + void readPartSeries(std::vector& lines); + void readJointSeriesMany(std::vector& lines); + void readJointSeries(std::vector& lines); + void readMotionSeriesMany(std::vector& lines); + void readMotionSeries(std::vector& lines); - std::string notes, name; - FColDsptr position3D, velocity3D, omega3D; - FMatDsptr rotationMatrix; - std::shared_ptr>> refPoints; - std::shared_ptr>> refCurves; - std::shared_ptr>> refSurfaces; + std::string notes; std::shared_ptr>> parts; std::shared_ptr>> kinematicIJs; std::shared_ptr>> constraintSets; @@ -40,6 +57,7 @@ namespace MbD { std::shared_ptr constantGravity; std::shared_ptr simulationParameters; std::shared_ptr animationParameters; + std::shared_ptr> times; }; } diff --git a/MbDCode/ASMTConstraintSet.cpp b/MbDCode/ASMTConstraintSet.cpp index 7d115bc..7972675 100644 --- a/MbDCode/ASMTConstraintSet.cpp +++ b/MbDCode/ASMTConstraintSet.cpp @@ -1,3 +1,61 @@ #include "ASMTConstraintSet.h" using namespace MbD; + +void MbD::ASMTConstraintSet::readMarkerI(std::vector& lines) +{ + assert(lines[0].find("MarkerI") != std::string::npos); + lines.erase(lines.begin()); + markerI = readString(lines[0]); + lines.erase(lines.begin()); +} + +void MbD::ASMTConstraintSet::readMarkerJ(std::vector& lines) +{ + assert(lines[0].find("MarkerJ") != std::string::npos); + lines.erase(lines.begin()); + markerJ = readString(lines[0]); + lines.erase(lines.begin()); +} + +void MbD::ASMTConstraintSet::readFXonIs(std::vector& lines) +{ + std::string str = lines[0]; + readDoublesInto(str, "FXonI", fxs); + lines.erase(lines.begin()); +} + +void MbD::ASMTConstraintSet::readFYonIs(std::vector& lines) +{ + std::string str = lines[0]; + readDoublesInto(str, "FYonI", fys); + lines.erase(lines.begin()); +} + +void MbD::ASMTConstraintSet::readFZonIs(std::vector& lines) +{ + std::string str = lines[0]; + readDoublesInto(str, "FZonI", fzs); + lines.erase(lines.begin()); +} + +void MbD::ASMTConstraintSet::readTXonIs(std::vector& lines) +{ + std::string str = lines[0]; + readDoublesInto(str, "TXonI", txs); + lines.erase(lines.begin()); +} + +void MbD::ASMTConstraintSet::readTYonIs(std::vector& lines) +{ + std::string str = lines[0]; + readDoublesInto(str, "TYonI", tys); + lines.erase(lines.begin()); +} + +void MbD::ASMTConstraintSet::readTZonIs(std::vector& lines) +{ + std::string str = lines[0]; + readDoublesInto(str, "TZonI", tzs); + lines.erase(lines.begin()); +} diff --git a/MbDCode/ASMTConstraintSet.h b/MbDCode/ASMTConstraintSet.h index 22b74f8..28db835 100644 --- a/MbDCode/ASMTConstraintSet.h +++ b/MbDCode/ASMTConstraintSet.h @@ -7,7 +7,17 @@ namespace MbD { { // public: + void readMarkerI(std::vector& lines); + void readMarkerJ(std::vector& lines); + void readFXonIs(std::vector& lines); + void readFYonIs(std::vector& lines); + void readFZonIs(std::vector& lines); + void readTXonIs(std::vector& lines); + void readTYonIs(std::vector& lines); + void readTZonIs(std::vector& lines); + std::string markerI, markerJ; + FRowDsptr fxs, fys, fzs, txs, tys, tzs; }; } diff --git a/MbDCode/ASMTItem.cpp b/MbDCode/ASMTItem.cpp index dcb5908..d5b39ce 100644 --- a/MbDCode/ASMTItem.cpp +++ b/MbDCode/ASMTItem.cpp @@ -12,7 +12,7 @@ void MbD::ASMTItem::parseASMT(std::vector& lines) assert(false); } -FRowDsptr MbD::ASMTItem::readRowOfDoubles(std::string line) +FRowDsptr MbD::ASMTItem::readRowOfDoubles(std::string& line) { std::istringstream iss(line); auto readRowOfDoubles = std::make_shared>(); @@ -23,7 +23,7 @@ FRowDsptr MbD::ASMTItem::readRowOfDoubles(std::string line) return readRowOfDoubles; } -FColDsptr MbD::ASMTItem::readColumnOfDoubles(std::string line) +FColDsptr MbD::ASMTItem::readColumnOfDoubles(std::string& line) { std::istringstream iss(line); auto readColumnOfDoubles = std::make_shared>(); @@ -34,7 +34,7 @@ FColDsptr MbD::ASMTItem::readColumnOfDoubles(std::string line) return readColumnOfDoubles; } -double MbD::ASMTItem::readDouble(std::string line) +double MbD::ASMTItem::readDouble(std::string& line) { std::istringstream iss(line); double d; @@ -42,7 +42,7 @@ double MbD::ASMTItem::readDouble(std::string line) return d; } -int MbD::ASMTItem::readInt(std::string line) +int MbD::ASMTItem::readInt(std::string& line) { std::istringstream iss(line); int i; @@ -50,7 +50,7 @@ int MbD::ASMTItem::readInt(std::string line) return i; } -bool MbD::ASMTItem::readBool(std::string line) +bool MbD::ASMTItem::readBool(std::string& line) { if (line.find("true") != std::string::npos) { @@ -64,3 +64,37 @@ bool MbD::ASMTItem::readBool(std::string line) assert(false); } } + +std::string MbD::ASMTItem::readString(std::string& line) +{ + std::string str = line; + str.erase(str.begin(), std::find_if(str.begin(), str.end(), [](unsigned char ch) { return !std::isspace(ch); })); + return str; +} + +void MbD::ASMTItem::readName(std::vector& lines) +{ + assert(lines[0].find("Name") != std::string::npos); + lines.erase(lines.begin()); + name = readString(lines[0]); + lines.erase(lines.begin()); +} + +std::string MbD::ASMTItem::fullName(std::string partialName) +{ + std::string longerName = "/" + name + partialName; + if (owner == nullptr) { + return longerName; + } + else { + return owner->fullName(longerName); + } +} + +void MbD::ASMTItem::readDoublesInto(std::string& str, std::string label, FRowDsptr& row) +{ + auto pos = str.find(label); + assert(pos != std::string::npos); + str.erase(0, pos + label.length()); + row = readRowOfDoubles(str); +} diff --git a/MbDCode/ASMTItem.h b/MbDCode/ASMTItem.h index 2fcbad0..546181d 100644 --- a/MbDCode/ASMTItem.h +++ b/MbDCode/ASMTItem.h @@ -8,12 +8,17 @@ namespace MbD { public: virtual void initialize(); virtual void parseASMT(std::vector& lines); - FRowDsptr readRowOfDoubles(std::string line); - FColDsptr readColumnOfDoubles(std::string line); - double readDouble(std::string line); - int readInt(std::string line); - bool readBool(std::string line); + FRowDsptr readRowOfDoubles(std::string& line); + FColDsptr readColumnOfDoubles(std::string& line); + double readDouble(std::string& line); + int readInt(std::string& line); + bool readBool(std::string& line); + std::string readString(std::string& line); + void readName(std::vector& lines); + std::string fullName(std::string partialName); + void readDoublesInto(std::string& str, std::string label, FRowDsptr& row); + std::string name; ASMTItem* owner; }; } diff --git a/MbDCode/ASMTJoint.cpp b/MbDCode/ASMTJoint.cpp index 316700c..d061f10 100644 --- a/MbDCode/ASMTJoint.cpp +++ b/MbDCode/ASMTJoint.cpp @@ -4,18 +4,25 @@ using namespace MbD; void MbD::ASMTJoint::parseASMT(std::vector& lines) { - size_t pos = lines[0].find_first_not_of("\t"); - auto leadingTabs = lines[0].substr(0, pos); - assert(lines[0] == (leadingTabs + "Name")); - lines.erase(lines.begin()); - name = lines[0]; - lines.erase(lines.begin()); - assert(lines[0] == (leadingTabs + "MarkerI")); - lines.erase(lines.begin()); - markerI = lines[0]; - lines.erase(lines.begin()); - assert(lines[0] == (leadingTabs + "MarkerJ")); - lines.erase(lines.begin()); - markerJ = lines[0]; - lines.erase(lines.begin()); + readName(lines); + readMarkerI(lines); + readMarkerJ(lines); +} + +void MbD::ASMTJoint::readJointSeries(std::vector& lines) +{ + std::string str = lines[0]; + std::string substr = "JointSeries"; + auto pos = str.find(substr); + assert(pos != std::string::npos); + str.erase(0, pos + substr.length()); + auto seriesName = readString(str); + assert(fullName("") == seriesName); + lines.erase(lines.begin()); + readFXonIs(lines); + readFYonIs(lines); + readFZonIs(lines); + readTXonIs(lines); + readTYonIs(lines); + readTZonIs(lines); } diff --git a/MbDCode/ASMTJoint.h b/MbDCode/ASMTJoint.h index efb1784..418c2af 100644 --- a/MbDCode/ASMTJoint.h +++ b/MbDCode/ASMTJoint.h @@ -1,6 +1,7 @@ #pragma once #include "ASMTConstraintSet.h" +#include "ForceTorqueData.h" namespace MbD { class ASMTJoint : public ASMTConstraintSet @@ -8,8 +9,9 @@ namespace MbD { // public: void parseASMT(std::vector& lines) override; + void readJointSeries(std::vector& lines); - std::string name, markerI, markerJ; + std::shared_ptr>> jointSeries; }; } diff --git a/MbDCode/ASMTMarker.cpp b/MbDCode/ASMTMarker.cpp index 372fc59..6e76a6a 100644 --- a/MbDCode/ASMTMarker.cpp +++ b/MbDCode/ASMTMarker.cpp @@ -4,40 +4,7 @@ using namespace MbD; void MbD::ASMTMarker::parseASMT(std::vector& lines) { - size_t pos = lines[0].find_first_not_of("\t"); - auto leadingTabs = lines[0].substr(0, pos); - while (!lines.empty()) { - if (lines[0] == (leadingTabs + "Name")) { - lines.erase(lines.begin()); - name = lines[0]; - lines.erase(lines.begin()); - } - else if (lines[0] == (leadingTabs + "Position3D")) { - lines.erase(lines.begin()); - std::istringstream iss(lines[0]); - position3D = std::make_shared>(); - double d; - while (iss >> d) { - position3D->push_back(d); - } - lines.erase(lines.begin()); - } - else if (lines[0] == (leadingTabs + "RotationMatrix")) { - lines.erase(lines.begin()); - rotationMatrix = std::make_shared>(3, 0); - for (int i = 0; i < 3; i++) - { - auto& row = rotationMatrix->at(i); - std::istringstream iss(lines[0]); - double d; - while (iss >> d) { - row->push_back(d); - } - lines.erase(lines.begin()); - } - } - else { - assert(false); - } - } + readName(lines); + readPosition3D(lines); + readRotationMatrix(lines); } diff --git a/MbDCode/ASMTMarker.h b/MbDCode/ASMTMarker.h index 0969a90..6dcc715 100644 --- a/MbDCode/ASMTMarker.h +++ b/MbDCode/ASMTMarker.h @@ -1,20 +1,16 @@ #pragma once -#include "ASMTItem.h" +#include "ASMTSpatialItem.h" #include "FullColumn.h" #include "FullMatrix.h" namespace MbD { - class ASMTMarker : public ASMTItem + class ASMTMarker : public ASMTSpatialItem { // public: void parseASMT(std::vector& lines) override; - std::string name; - FColDsptr position3D; - FMatDsptr rotationMatrix; - }; } diff --git a/MbDCode/ASMTMotion.cpp b/MbDCode/ASMTMotion.cpp index c60fa7e..491da2f 100644 --- a/MbDCode/ASMTMotion.cpp +++ b/MbDCode/ASMTMotion.cpp @@ -1,3 +1,21 @@ #include "ASMTMotion.h" using namespace MbD; + +void MbD::ASMTMotion::readMotionSeries(std::vector& lines) +{ + std::string str = lines[0]; + std::string substr = "MotionSeries"; + auto pos = str.find(substr); + assert(pos != std::string::npos); + str.erase(0, pos + substr.length()); + auto seriesName = readString(str); + assert(fullName("") == seriesName); + lines.erase(lines.begin()); + readFXonIs(lines); + readFYonIs(lines); + readFZonIs(lines); + readTXonIs(lines); + readTYonIs(lines); + readTZonIs(lines); +} diff --git a/MbDCode/ASMTMotion.h b/MbDCode/ASMTMotion.h index a1c9cd2..70ec845 100644 --- a/MbDCode/ASMTMotion.h +++ b/MbDCode/ASMTMotion.h @@ -1,13 +1,16 @@ #pragma once #include "ASMTConstraintSet.h" +#include "ForceTorqueData.h" namespace MbD { class ASMTMotion : public ASMTConstraintSet { // public: + void readMotionSeries(std::vector& lines); + std::shared_ptr>> motionSeries; }; } diff --git a/MbDCode/ASMTPart.cpp b/MbDCode/ASMTPart.cpp index ee58a52..4e3e276 100644 --- a/MbDCode/ASMTPart.cpp +++ b/MbDCode/ASMTPart.cpp @@ -5,123 +5,78 @@ using namespace MbD; void MbD::ASMTPart::parseASMT(std::vector& lines) { - size_t pos = lines[0].find_first_not_of("\t"); - auto leadingTabs = lines[0].substr(0, pos); - while (!lines.empty()) { - if (lines[0] == (leadingTabs + "Name")) { - lines.erase(lines.begin()); - name = lines[0]; - lines.erase(lines.begin()); - } - else if (lines[0] == (leadingTabs + "Position3D")) { - lines.erase(lines.begin()); - position3D = readColumnOfDoubles(lines[0]); - lines.erase(lines.begin()); - } - else if (lines[0] == (leadingTabs + "RotationMatrix")) { - lines.erase(lines.begin()); - rotationMatrix = std::make_shared>(3); - for (int i = 0; i < 3; i++) - { - auto row = readRowOfDoubles(lines[0]); - rotationMatrix->atiput(i, row); - lines.erase(lines.begin()); - } - } - else if (lines[0] == (leadingTabs + "Velocity3D")) { - lines.erase(lines.begin()); - velocity3D = readColumnOfDoubles(lines[0]); - lines.erase(lines.begin()); - } - else if (lines[0] == (leadingTabs + "Omega3D")) { - lines.erase(lines.begin()); - omega3D = readColumnOfDoubles(lines[0]); - lines.erase(lines.begin()); - } - else if (lines[0] == (leadingTabs + "FeatureOrder")) { - lines.erase(lines.begin()); - //featureOrder = std::make_shared>>(); - auto it = std::find(lines.begin(), lines.end(), (leadingTabs + "PrincipalMassMarker")); - //std::vector featureOrderLines(lines.begin(), it); - //while (!featureOrderLines.empty()) { - // if (featureOrderLines[0] == (leadingTabs + "\tExtrusion")) { - // featureOrderLines.erase(featureOrderLines.begin()); - // auto extrusion = CREATE::With(); - // extrusion->parseASMT(featureOrderLines); - // featureOrder->push_back(extrusion); - // extrusion->owner = this; - // } - // else { - // assert(false); - // } - //} - lines.erase(lines.begin(), it); - } - else if (lines[0] == (leadingTabs + "PrincipalMassMarker")) { - lines.erase(lines.begin()); - principalMassMarker = CREATE::With(); - principalMassMarker->parseASMT(lines); - principalMassMarker->owner = this; - } - else if (lines[0] == (leadingTabs + "RefPoints")) { - lines.erase(lines.begin()); - refPoints = std::make_shared>>(); - auto it = std::find(lines.begin(), lines.end(), (leadingTabs + "RefCurves")); - std::vector refPointsLines(lines.begin(), it); - while (!refPointsLines.empty()) { - if (refPointsLines[0] == (leadingTabs + "\tRefPoint")) { - refPointsLines.erase(refPointsLines.begin()); - auto refPoint = CREATE::With(); - refPoint->parseASMT(refPointsLines); - refPoints->push_back(refPoint); - refPoint->owner = this; - } - else { - assert(false); - } - } - lines.erase(lines.begin(), it); - } - else if (lines[0] == (leadingTabs + "RefCurves")) { - lines.erase(lines.begin()); - refCurves = std::make_shared>>(); - auto it = std::find(lines.begin(), lines.end(), (leadingTabs + "RefSurfaces")); - std::vector refCurvesLines(lines.begin(), it); - while (!refCurvesLines.empty()) { - if (refCurvesLines[0] == (leadingTabs + "\tRefCurve")) { - refCurvesLines.erase(refCurvesLines.begin()); - auto refCurve = CREATE::With(); - refCurve->parseASMT(refCurvesLines); - refCurves->push_back(refCurve); - refCurve->owner = this; - } - else { - assert(false); - } - } - lines.erase(lines.begin(), it); - } - else if (lines[0] == (leadingTabs + "RefSurfaces")) { - lines.erase(lines.begin()); - refSurfaces = std::make_shared>>(); - auto it = std::find(lines.begin(), lines.end(), (leadingTabs.substr(0, leadingTabs.size() - 1) + "Part")); - std::vector refSurfacesLines(lines.begin(), it); - while (!refSurfacesLines.empty()) { - if (refSurfacesLines[0] == (leadingTabs + "\tRefSurface")) { - refSurfacesLines.erase(refSurfacesLines.begin()); - auto refSurface = CREATE::With(); - refSurface->parseASMT(refSurfacesLines); - refSurfaces->push_back(refSurface); - refSurface->owner = this; - } - else { - assert(false); - } - } - lines.erase(lines.begin(), it); - } - else { - return; - } - } + readName(lines); + readPosition3D(lines); + readRotationMatrix(lines); + readVelocity3D(lines); + readOmega3D(lines); + readFeatureOrder(lines); + readPrincipalMassMarker(lines); + readRefPoints(lines); + readRefCurves(lines); + readRefSurfaces(lines); +} + +void MbD::ASMTPart::readFeatureOrder(std::vector& lines) +{ + assert(lines[0].find("FeatureOrder") != std::string::npos); + lines.erase(lines.begin()); + //featureOrder = std::make_shared>>(); + auto it = std::find_if(lines.begin(), lines.end(), [](const std::string& s) { + return s.find("PrincipalMassMarker") != std::string::npos; + }); + //std::vector featureOrderLines(lines.begin(), it); + //while (!featureOrderLines.empty()) { + // if (featureOrderLines[0] == (leadingTabs + "\tExtrusion")) { + // featureOrderLines.erase(featureOrderLines.begin()); + // auto extrusion = CREATE::With(); + // extrusion->parseASMT(featureOrderLines); + // featureOrder->push_back(extrusion); + // extrusion->owner = this; + // } + // else { + // assert(false); + // } + //} + lines.erase(lines.begin(), it); +} + +void MbD::ASMTPart::readPrincipalMassMarker(std::vector& lines) +{ + assert(lines[0].find("PrincipalMassMarker") != std::string::npos); + lines.erase(lines.begin()); + principalMassMarker = CREATE::With(); + principalMassMarker->parseASMT(lines); + principalMassMarker->owner = this; +} + +void MbD::ASMTPart::readPartSeries(std::vector& lines) +{ + std::string str = lines[0]; + std::string substr = "PartSeries"; + auto pos = str.find(substr); + assert(pos != std::string::npos); + str.erase(0, pos + substr.length()); + auto seriesName = readString(str); + assert(fullName("") == seriesName); + lines.erase(lines.begin()); + //xs, ys, zs, bryxs, bryys, bryzs + readXs(lines); + readYs(lines); + readZs(lines); + readBryantxs(lines); + readBryantys(lines); + readBryantzs(lines); + readVXs(lines); + readVYs(lines); + readVZs(lines); + readOmegaXs(lines); + readOmegaYs(lines); + readOmegaZs(lines); + readAXs(lines); + readAYs(lines); + readAZs(lines); + readAlphaXs(lines); + readAlphaYs(lines); + readAlphaZs(lines); } diff --git a/MbDCode/ASMTPart.h b/MbDCode/ASMTPart.h index cab2c96..12940d5 100644 --- a/MbDCode/ASMTPart.h +++ b/MbDCode/ASMTPart.h @@ -1,26 +1,25 @@ #pragma once -#include "ASMTItem.h" +#include "ASMTSpatialContainer.h" #include "ASMTRefPoint.h" #include "ASMTRefCurve.h" #include "ASMTRefSurface.h" #include "ASMTPrincipalMassMarker.h" +#include "PosVelAccData.h" namespace MbD { - class ASMTPart : public ASMTItem + class ASMTPart : public ASMTSpatialContainer { // public: void parseASMT(std::vector& lines) override; + void readFeatureOrder(std::vector& lines); + void readPrincipalMassMarker(std::vector& lines); + void readPartSeries(std::vector& lines); - std::string name; - FColDsptr position3D, velocity3D, omega3D; - FMatDsptr rotationMatrix; std::shared_ptr principalMassMarker; //std::shared_ptr>> featureOrder; - std::shared_ptr>> refPoints; - std::shared_ptr>> refCurves; - std::shared_ptr>> refSurfaces; + std::shared_ptr>> partSeries; }; } diff --git a/MbDCode/ASMTPrincipalMassMarker.h b/MbDCode/ASMTPrincipalMassMarker.h index 7cab1bc..1bc0b42 100644 --- a/MbDCode/ASMTPrincipalMassMarker.h +++ b/MbDCode/ASMTPrincipalMassMarker.h @@ -9,7 +9,6 @@ namespace MbD { public: void parseASMT(std::vector& lines) override; - std::string name; FColDsptr position3D; FMatDsptr rotationMatrix; double mass, density; diff --git a/MbDCode/ASMTRefPoint.cpp b/MbDCode/ASMTRefPoint.cpp index 50d74eb..bd1b5d3 100644 --- a/MbDCode/ASMTRefPoint.cpp +++ b/MbDCode/ASMTRefPoint.cpp @@ -5,54 +5,32 @@ using namespace MbD; void MbD::ASMTRefPoint::parseASMT(std::vector& lines) { - size_t pos = lines[0].find_first_not_of("\t"); - auto leadingTabs = lines[0].substr(0, pos); - while (!lines.empty()) { - if (lines[0] == (leadingTabs + "Position3D")) { - lines.erase(lines.begin()); - std::istringstream iss(lines[0]); - position3D = std::make_shared>(); - double d; - while (iss >> d) { - position3D->push_back(d); - } - lines.erase(lines.begin()); - } - else if (lines[0] == (leadingTabs + "RotationMatrix")) { - lines.erase(lines.begin()); - rotationMatrix = std::make_shared>(3, 0); - for (int i = 0; i < 3; i++) - { - auto& row = rotationMatrix->at(i); - std::istringstream iss(lines[0]); - double d; - while (iss >> d) { - row->push_back(d); - } - lines.erase(lines.begin()); - } - } - else if (lines[0] == (leadingTabs + "Markers")) { - lines.erase(lines.begin()); - markers = std::make_shared>>(); - auto it = std::find(lines.begin(), lines.end(), (leadingTabs.substr(0, leadingTabs.size() - 1) + "RefPoint")); - std::vector markersLines(lines.begin(), it); - while (!markersLines.empty()) { - if (markersLines[0] == (leadingTabs + "\tMarker")) { - markersLines.erase(markersLines.begin()); - auto marker = CREATE::With(); - marker->parseASMT(markersLines); - markers->push_back(marker); - marker->owner = this; - } - else { - return; - } - } - lines.erase(lines.begin(), it); - } - else { - return; - } - } + readPosition3D(lines); + readRotationMatrix(lines); + readMarkers(lines); +} + +void MbD::ASMTRefPoint::readMarkers(std::vector& lines) +{ + assert(lines[0].find("Markers") != std::string::npos); + lines.erase(lines.begin()); + markers = std::make_shared>>(); + auto it = std::find_if(lines.begin(), lines.end(), [](const std::string& s) { + return s.find("RefPoint") != std::string::npos; + }); + std::vector markersLines(lines.begin(), it); + while (!markersLines.empty()) { + readMarker(markersLines); + } + lines.erase(lines.begin(), it); +} + +void MbD::ASMTRefPoint::readMarker(std::vector& lines) +{ + assert(lines[0].find("Marker") != std::string::npos); + lines.erase(lines.begin()); + auto marker = CREATE::With(); + marker->parseASMT(lines); + markers->push_back(marker); + marker->owner = this; } diff --git a/MbDCode/ASMTRefPoint.h b/MbDCode/ASMTRefPoint.h index cdb816f..9de3c9e 100644 --- a/MbDCode/ASMTRefPoint.h +++ b/MbDCode/ASMTRefPoint.h @@ -1,19 +1,19 @@ #pragma once -#include "ASMTItem.h" +#include "ASMTSpatialItem.h" #include #include #include "ASMTMarker.h" namespace MbD { - class ASMTRefPoint : public ASMTItem + class ASMTRefPoint : public ASMTSpatialItem { // public: void parseASMT(std::vector& lines) override; + void readMarkers(std::vector& lines); + void readMarker(std::vector& lines); - FColDsptr position3D; - FMatDsptr rotationMatrix; std::shared_ptr>> markers; }; } diff --git a/MbDCode/ASMTRotationalMotion.cpp b/MbDCode/ASMTRotationalMotion.cpp index dc5aef0..ff4a4b4 100644 --- a/MbDCode/ASMTRotationalMotion.cpp +++ b/MbDCode/ASMTRotationalMotion.cpp @@ -4,18 +4,23 @@ using namespace MbD; void MbD::ASMTRotationalMotion::parseASMT(std::vector& lines) { - size_t pos = lines[0].find_first_not_of("\t"); - auto leadingTabs = lines[0].substr(0, pos); - assert(lines[0] == (leadingTabs + "Name")); + readName(lines); + readMotionJoint(lines); + readRotationZ(lines); +} + +void MbD::ASMTRotationalMotion::readMotionJoint(std::vector& lines) +{ + assert(lines[0].find("MotionJoint") != std::string::npos); lines.erase(lines.begin()); - name = lines[0]; - lines.erase(lines.begin()); - assert(lines[0] == (leadingTabs + "MotionJoint")); - lines.erase(lines.begin()); - motionJoint = lines[0]; - lines.erase(lines.begin()); - assert(lines[0] == (leadingTabs + "RotationZ")); - lines.erase(lines.begin()); - rotationZ = lines[0]; + motionJoint = readString(lines[0]); + lines.erase(lines.begin()); +} + +void MbD::ASMTRotationalMotion::readRotationZ(std::vector& lines) +{ + assert(lines[0].find("RotationZ") != std::string::npos); + lines.erase(lines.begin()); + rotationZ = readString(lines[0]); lines.erase(lines.begin()); } diff --git a/MbDCode/ASMTRotationalMotion.h b/MbDCode/ASMTRotationalMotion.h index 669c9b9..88d4cf8 100644 --- a/MbDCode/ASMTRotationalMotion.h +++ b/MbDCode/ASMTRotationalMotion.h @@ -8,8 +8,10 @@ namespace MbD { // public: void parseASMT(std::vector& lines) override; + void readMotionJoint(std::vector& lines); + void readRotationZ(std::vector& lines); - std::string name, motionJoint, rotationZ; + std::string motionJoint, rotationZ; }; } diff --git a/MbDCode/ASMTSpatialContainer.cpp b/MbDCode/ASMTSpatialContainer.cpp new file mode 100644 index 0000000..b1cd641 --- /dev/null +++ b/MbDCode/ASMTSpatialContainer.cpp @@ -0,0 +1,192 @@ +#include "ASMTSpatialContainer.h" + +void MbD::ASMTSpatialContainer::readRefPoints(std::vector& lines) +{ + assert(lines[0].find("RefPoints") != std::string::npos); + lines.erase(lines.begin()); + refPoints = std::make_shared>>(); + auto it = std::find_if(lines.begin(), lines.end(), [](const std::string& s) { + return s.find("RefCurves") != std::string::npos; + }); + std::vector refPointsLines(lines.begin(), it); + while (!refPointsLines.empty()) { + readRefPoint(refPointsLines); + } + lines.erase(lines.begin(), it); +} + +void MbD::ASMTSpatialContainer::readRefPoint(std::vector& lines) +{ + assert(lines[0].find("RefPoint") != std::string::npos); + lines.erase(lines.begin()); + auto refPoint = CREATE::With(); + refPoint->parseASMT(lines); + refPoints->push_back(refPoint); + refPoint->owner = this; +} + +void MbD::ASMTSpatialContainer::readRefCurves(std::vector& lines) +{ + assert(lines[0].find("RefCurves") != std::string::npos); + lines.erase(lines.begin()); + refCurves = std::make_shared>>(); + auto it = std::find_if(lines.begin(), lines.end(), [](const std::string& s) { + return s.find("RefSurfaces") != std::string::npos; + }); + std::vector refCurvesLines(lines.begin(), it); + while (!refCurvesLines.empty()) { + readRefCurve(refCurvesLines); + } + lines.erase(lines.begin(), it); +} + +void MbD::ASMTSpatialContainer::readRefCurve(std::vector& lines) +{ + assert(false); +} + +void MbD::ASMTSpatialContainer::readRefSurfaces(std::vector& lines) +{ + assert(lines[0].find("RefSurfaces") != std::string::npos); + lines.erase(lines.begin()); + refSurfaces = std::make_shared>>(); + auto it = std::find_if(lines.begin(), lines.end(), [](const std::string& s) { + return s.find("Part") != std::string::npos; + }); + std::vector refSurfacesLines(lines.begin(), it); + while (!refSurfacesLines.empty()) { + readRefSurface(refSurfacesLines); + } + lines.erase(lines.begin(), it); +} + +void MbD::ASMTSpatialContainer::readRefSurface(std::vector& lines) +{ + assert(false); +} + +void MbD::ASMTSpatialContainer::readXs(std::vector& lines) +{ + std::string str = lines[0]; + readDoublesInto(str, "X", xs); + lines.erase(lines.begin()); +} + +void MbD::ASMTSpatialContainer::readYs(std::vector& lines) +{ + std::string str = lines[0]; + readDoublesInto(str, "Y", ys); + lines.erase(lines.begin()); +} + +void MbD::ASMTSpatialContainer::readZs(std::vector& lines) +{ + std::string str = lines[0]; + readDoublesInto(str, "Z", zs); + lines.erase(lines.begin()); +} + +void MbD::ASMTSpatialContainer::readBryantxs(std::vector& lines) +{ + std::string str = lines[0]; + readDoublesInto(str, "Bryantx", bryxs); + lines.erase(lines.begin()); +} + +void MbD::ASMTSpatialContainer::readBryantys(std::vector& lines) +{ + std::string str = lines[0]; + readDoublesInto(str, "Bryanty", bryys); + lines.erase(lines.begin()); +} + +void MbD::ASMTSpatialContainer::readBryantzs(std::vector& lines) +{ + std::string str = lines[0]; + readDoublesInto(str, "Bryantz", bryzs); + lines.erase(lines.begin()); +} + +void MbD::ASMTSpatialContainer::readVXs(std::vector& lines) +{ + std::string str = lines[0]; + readDoublesInto(str, "VX", vxs); + lines.erase(lines.begin()); +} + +void MbD::ASMTSpatialContainer::readVYs(std::vector& lines) +{ + std::string str = lines[0]; + readDoublesInto(str, "VY", vys); + lines.erase(lines.begin()); +} + +void MbD::ASMTSpatialContainer::readVZs(std::vector& lines) +{ + std::string str = lines[0]; + readDoublesInto(str, "VZ", vzs); + lines.erase(lines.begin()); +} + +void MbD::ASMTSpatialContainer::readOmegaXs(std::vector& lines) +{ + std::string str = lines[0]; + readDoublesInto(str, "OmegaX", omexs); + lines.erase(lines.begin()); +} + +void MbD::ASMTSpatialContainer::readOmegaYs(std::vector& lines) +{ + std::string str = lines[0]; + readDoublesInto(str, "OmegaY", omeys); + lines.erase(lines.begin()); +} + +void MbD::ASMTSpatialContainer::readOmegaZs(std::vector& lines) +{ + std::string str = lines[0]; + readDoublesInto(str, "OmegaZ", omezs); + lines.erase(lines.begin()); +} + +void MbD::ASMTSpatialContainer::readAXs(std::vector& lines) +{ + std::string str = lines[0]; + readDoublesInto(str, "AX", axs); + lines.erase(lines.begin()); +} + +void MbD::ASMTSpatialContainer::readAYs(std::vector& lines) +{ + std::string str = lines[0]; + readDoublesInto(str, "AY", ays); + lines.erase(lines.begin()); +} + +void MbD::ASMTSpatialContainer::readAZs(std::vector& lines) +{ + std::string str = lines[0]; + readDoublesInto(str, "AZ", azs); + lines.erase(lines.begin()); +} + +void MbD::ASMTSpatialContainer::readAlphaXs(std::vector& lines) +{ + std::string str = lines[0]; + readDoublesInto(str, "AlphaX", alpxs); + lines.erase(lines.begin()); +} + +void MbD::ASMTSpatialContainer::readAlphaYs(std::vector& lines) +{ + std::string str = lines[0]; + readDoublesInto(str, "AlphaY", alpys); + lines.erase(lines.begin()); +} + +void MbD::ASMTSpatialContainer::readAlphaZs(std::vector& lines) +{ + std::string str = lines[0]; + readDoublesInto(str, "AlphaZ", alpzs); + lines.erase(lines.begin()); +} diff --git a/MbDCode/ASMTSpatialContainer.h b/MbDCode/ASMTSpatialContainer.h new file mode 100644 index 0000000..8af5521 --- /dev/null +++ b/MbDCode/ASMTSpatialContainer.h @@ -0,0 +1,47 @@ +#pragma once + +#include "ASMTSpatialItem.h" +#include "ASMTRefPoint.h" +#include "ASMTRefCurve.h" +#include "ASMTRefSurface.h" + +namespace MbD { + class ASMTSpatialContainer : public ASMTSpatialItem + { + // + public: + void readRefPoints(std::vector& lines); + void readRefPoint(std::vector& lines); + void readRefCurves(std::vector& lines); + void readRefCurve(std::vector& lines); + void readRefSurfaces(std::vector& lines); + void readRefSurface(std::vector& lines); + void readXs(std::vector& lines); + void readYs(std::vector& lines); + void readZs(std::vector& lines); + void readBryantxs(std::vector& lines); + void readBryantys(std::vector& lines); + void readBryantzs(std::vector& lines); + void readVXs(std::vector& lines); + void readVYs(std::vector& lines); + void readVZs(std::vector& lines); + void readOmegaXs(std::vector& lines); + void readOmegaYs(std::vector& lines); + void readOmegaZs(std::vector& lines); + void readAXs(std::vector& lines); + void readAYs(std::vector& lines); + void readAZs(std::vector& lines); + void readAlphaXs(std::vector& lines); + void readAlphaYs(std::vector& lines); + void readAlphaZs(std::vector& lines); + + std::shared_ptr>> refPoints; + std::shared_ptr>> refCurves; + std::shared_ptr>> refSurfaces; + FRowDsptr xs, ys, zs, bryxs, bryys, bryzs; + FRowDsptr vxs, vys, vzs, omexs, omeys, omezs; + FRowDsptr axs, ays, azs, alpxs, alpys, alpzs; + + }; +} + diff --git a/MbDCode/ASMTSpatialItem.cpp b/MbDCode/ASMTSpatialItem.cpp new file mode 100644 index 0000000..7a888a6 --- /dev/null +++ b/MbDCode/ASMTSpatialItem.cpp @@ -0,0 +1,59 @@ +#include "ASMTSpatialItem.h" + +using namespace MbD; + +void MbD::ASMTSpatialItem::readPosition3D(std::vector& lines) +{ + assert(lines[0].find("Position3D") != std::string::npos); + lines.erase(lines.begin()); + std::istringstream iss(lines[0]); + position3D = std::make_shared>(); + double d; + while (iss >> d) { + position3D->push_back(d); + } + lines.erase(lines.begin()); +} + +void MbD::ASMTSpatialItem::readRotationMatrix(std::vector& lines) +{ + assert(lines[0].find("RotationMatrix") != std::string::npos); + lines.erase(lines.begin()); + rotationMatrix = std::make_shared>(3, 0); + for (int i = 0; i < 3; i++) + { + auto& row = rotationMatrix->at(i); + std::istringstream iss(lines[0]); + double d; + while (iss >> d) { + row->push_back(d); + } + lines.erase(lines.begin()); + } +} + +void MbD::ASMTSpatialItem::readVelocity3D(std::vector& lines) +{ + assert(lines[0].find("Velocity3D") != std::string::npos); + lines.erase(lines.begin()); + std::istringstream iss(lines[0]); + velocity3D = std::make_shared>(); + double d; + while (iss >> d) { + velocity3D->push_back(d); + } + lines.erase(lines.begin()); +} + +void MbD::ASMTSpatialItem::readOmega3D(std::vector& lines) +{ + assert(lines[0].find("Omega3D") != std::string::npos); + lines.erase(lines.begin()); + std::istringstream iss(lines[0]); + omega3D = std::make_shared>(); + double d; + while (iss >> d) { + omega3D->push_back(d); + } + lines.erase(lines.begin()); +} diff --git a/MbDCode/ASMTSpatialItem.h b/MbDCode/ASMTSpatialItem.h new file mode 100644 index 0000000..61e8faa --- /dev/null +++ b/MbDCode/ASMTSpatialItem.h @@ -0,0 +1,20 @@ +#pragma once + +#include "ASMTItem.h" + +namespace MbD { + class ASMTSpatialItem : public ASMTItem + { + // + public: + void readPosition3D(std::vector& lines); + void readRotationMatrix(std::vector& lines); + void readVelocity3D(std::vector& lines); + void readOmega3D(std::vector& lines); + + FColDsptr position3D, velocity3D, omega3D; + FMatDsptr rotationMatrix; + + }; +} + diff --git a/MbDCode/ASMTTranslationalMotion.h b/MbDCode/ASMTTranslationalMotion.h index 38c58c9..359fc82 100644 --- a/MbDCode/ASMTTranslationalMotion.h +++ b/MbDCode/ASMTTranslationalMotion.h @@ -9,7 +9,7 @@ namespace MbD { public: void parseASMT(std::vector& lines) override; - std::string name, motionJoint, translationZ; + std::string motionJoint, translationZ; }; } diff --git a/MbDCode/CADSystem.h b/MbDCode/CADSystem.h index 519d9c4..65ba431 100644 --- a/MbDCode/CADSystem.h +++ b/MbDCode/CADSystem.h @@ -15,7 +15,7 @@ namespace MbD { // public: CADSystem() { - mbdSystem->externalSystem = this; + mbdSystem->externalSystem->cadSystem = this; } void outputFor(AnalysisType type); diff --git a/MbDCode/ExternalSystem.cpp b/MbDCode/ExternalSystem.cpp new file mode 100644 index 0000000..52310e9 --- /dev/null +++ b/MbDCode/ExternalSystem.cpp @@ -0,0 +1,31 @@ +#include "ExternalSystem.h" + +using namespace MbD; + +void MbD::ExternalSystem::preMbDrun() +{ +} + +void MbD::ExternalSystem::outputFor(AnalysisType type) +{ +} + +void MbD::ExternalSystem::logString(std::string& str) +{ +} + +void MbD::ExternalSystem::logString(double value) +{ +} + +void MbD::ExternalSystem::runOndselPiston() +{ +} + +void MbD::ExternalSystem::runPiston() +{ +} + +void MbD::ExternalSystem::postMbDrun() +{ +} diff --git a/MbDCode/ExternalSystem.h b/MbDCode/ExternalSystem.h new file mode 100644 index 0000000..c04b449 --- /dev/null +++ b/MbDCode/ExternalSystem.h @@ -0,0 +1,32 @@ +#pragma once + +#include +#include "enum.h" +#include + +//#include "CADSystem.h" +//#include "ASMTAssembly.h" + +namespace MbD { + class CADSystem; + class ASMTAssembly; + + class ExternalSystem + { + // + public: + void preMbDrun(); + void outputFor(AnalysisType type); + void logString(std::string& str); + void logString(double value); + void runOndselPiston(); + void runPiston(); + void postMbDrun(); + + + CADSystem* cadSystem; + ASMTAssembly* asmtAssembly; + + }; +} + diff --git a/MbDCode/MbDCode.cpp b/MbDCode/MbDCode.cpp index c85995d..8c4b15f 100644 --- a/MbDCode/MbDCode.cpp +++ b/MbDCode/MbDCode.cpp @@ -23,8 +23,8 @@ int main() auto externalSys = std::make_shared(); externalSys->runOndselPiston(); - externalSys->runPiston(); - runSpMat(); + //externalSys->runPiston(); + //runSpMat(); } void runSpMat() { diff --git a/MbDCode/MbDCode.vcxproj b/MbDCode/MbDCode.vcxproj index a2ea094..246bb09 100644 --- a/MbDCode/MbDCode.vcxproj +++ b/MbDCode/MbDCode.vcxproj @@ -159,6 +159,8 @@ + + @@ -181,7 +183,8 @@ - + + @@ -390,6 +393,8 @@ + + @@ -412,7 +417,8 @@ - + + diff --git a/MbDCode/MbDCode.vcxproj.filters b/MbDCode/MbDCode.vcxproj.filters index cb64dd4..eb3bfb4 100644 --- a/MbDCode/MbDCode.vcxproj.filters +++ b/MbDCode/MbDCode.vcxproj.filters @@ -429,7 +429,7 @@ Source Files - + Source Files @@ -702,6 +702,15 @@ Source Files + + Source Files + + + Source Files + + + Source Files + @@ -1127,7 +1136,7 @@ Header Files - + Header Files @@ -1400,6 +1409,15 @@ Header Files + + Header Files + + + Header Files + + + Header Files + diff --git a/MbDCode/Part.cpp b/MbDCode/Part.cpp index 5b018ee..6531741 100644 --- a/MbDCode/Part.cpp +++ b/MbDCode/Part.cpp @@ -4,7 +4,7 @@ #include "CREATE.h" #include "DiagonalMatrix.h" #include "EulerParameters.h" -#include "DataPosVelAcc.h" +#include "PosVelAccData.h" using namespace MbD; @@ -538,7 +538,7 @@ std::shared_ptr Part::stateData() auto omeOpO = this->omeOpO(); auto aOpO = this->qXddot(); auto alpOpO = this->alpOpO(); - auto answer = std::make_shared(); + auto answer = std::make_shared(); answer->rFfF = rOpO; answer->aAFf = aAOp; answer->vFfF = vOpO; diff --git a/MbDCode/DataPosVelAcc.cpp b/MbDCode/PosVelAccData.cpp similarity index 80% rename from MbDCode/DataPosVelAcc.cpp rename to MbDCode/PosVelAccData.cpp index 7fda007..506ba1f 100644 --- a/MbDCode/DataPosVelAcc.cpp +++ b/MbDCode/PosVelAccData.cpp @@ -1,10 +1,10 @@ #include -#include "DataPosVelAcc.h" +#include "PosVelAccData.h" using namespace MbD; -std::ostream& DataPosVelAcc::printOn(std::ostream& s) const +std::ostream& PosVelAccData::printOn(std::ostream& s) const { s << "refData = " << *refData << std::endl; s << "rFfF = " << *rFfF << std::endl; diff --git a/MbDCode/DataPosVelAcc.h b/MbDCode/PosVelAccData.h similarity index 75% rename from MbDCode/DataPosVelAcc.h rename to MbDCode/PosVelAccData.h index b60dab0..7f7534f 100644 --- a/MbDCode/DataPosVelAcc.h +++ b/MbDCode/PosVelAccData.h @@ -3,13 +3,13 @@ #include "StateData.h" namespace MbD { - class DataPosVelAcc : public StateData + class PosVelAccData : public StateData { //refData rFfF aAFf vFfF omeFfF aFfF alpFfF public: std::ostream& printOn(std::ostream& s) const override; - std::shared_ptr refData; + std::shared_ptr refData; FColDsptr rFfF, vFfF, omeFfF, aFfF, alpFfF; FMatDsptr aAFf; }; diff --git a/MbDCode/System.cpp b/MbDCode/System.cpp index b94fb1e..c4fb277 100644 --- a/MbDCode/System.cpp +++ b/MbDCode/System.cpp @@ -7,7 +7,7 @@ #include "SystemSolver.h" #include "Time.h" #include "CREATE.h" -#include "CADSystem.h" +#include "ExternalSystem.h" using namespace MbD; @@ -26,6 +26,7 @@ System* MbD::System::root() void System::initialize() { + externalSystem = std::make_shared(); time = CREATE