Skip to content

Commit

Permalink
Added Raw data Object to handle diiferent types of samples
Browse files Browse the repository at this point in the history
  • Loading branch information
salamb committed Jan 15, 2016
1 parent ec6b784 commit 928725b
Show file tree
Hide file tree
Showing 10 changed files with 217 additions and 25 deletions.
8 changes: 6 additions & 2 deletions Exec.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,28 @@ String ^ name;
__int64 id;
__int64 index;
WP^ parent;
__int64 copyID;
bool typeWP;
public:

bool isWP(){return typeWP;};
//get name of Executable
String^ getName(){return name;};
// get stpnc id of Executable
__int64 getId(){return id;};
// index in list of enabled executalbes for an enabled parent WorkPlan
__int64 getIndex(){return index;};

__int64 getCopyID() { return copyID; }
void setCopyID(__int64 i) { copyID = i; }
bool copyCreated() { if (copyID == -1) { return false; } else { return true; } }
WP^ getParent();
Exec(String^ n,__int64 ID,__int64 in,WP^p,bool iswp){
name=n;
id=ID;
index=in;
parent=p;
typeWP=iswp;
copyID = -1;
}
};
#endif
82 changes: 67 additions & 15 deletions Patcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,17 +430,6 @@ List<List<long long>^> ^ Patcher::getAllRapidPaths(long long workplan, STEPNCLib
return rapidToolPaths;
}

double Patcher::actualFeedRate(array<double>^ coor1,array<double>^ coor2){
double dx=coor1[0]-coor2[0];
double dy=coor1[1]-coor2[1];
double dz=coor1[2]-coor2[2];

double dist= Math::Sqrt( Math::Pow(dx,2)+Math::Pow(dy,2)+Math::Pow(dz,2))/coor2[3];

//Console::WriteLine("dx {0} dy{1} dz {2} deltat {3} speed{4}",dx,dy,dz,coor2[3],dist);

return dist;
}
List<double> ^Patcher::getAllPoints(List<long long>^ paths,STEPNCLib::Finder ^find){
List<long long >^ curves=nullptr;
List<double> ^pts=gcnew List<double>();
Expand Down Expand Up @@ -602,7 +591,7 @@ void Patcher::OpenFile(String^file,String^ desiredWorkPlanPath,String^newWorkPla
find->Open238(file);
apt->Open238(file);
array<String^>^ nameList=desiredWorkPlanPath->Split('/');
__int64 id= getWorkPlanByPath(nameList,find);
wpID= getWorkPlanByPath(nameList,find);
apt->Inches();
find->APIUnitsInch();
}
Expand All @@ -625,22 +614,85 @@ void Patcher::DeleteBefore(__int64 wpid,STEPNCLib::Finder ^find,STEPNCLib::AptSt
void Patcher::createPatchedFile(String^ partFile,String^ WPpath,String^newFileName,String^newWorkPlan,String^ coor){
STEPNCLib::AptStepMaker^ apt = gcnew AptStepMaker();
STEPNCLib::Finder^find = gcnew Finder();

__int64 oldWPID;
bool newWS = true;
bool newWP = true;

__int64 oldWPID;
RawData^ samples = gcnew RawData();
OpenFile(partFile,WPpath,newWorkPlan,find,apt,oldWPID);
array<String^>^ nameList=WPpath->Split('/');
//get the workplan id


samples->changeSourceTxt(coor);
samples->parse();

root=getAllExec(oldWPID,find,nullptr,0);

/////init

long wp_id = find->GetMainWorkplan();
Console::WriteLine("Main Workplan name " + find->GetExecutableName(wp_id));

// add a new workplan at the end of the project
apt->NestWorkplanAfter("Workplan for MTConnect results", find->GetWorkplanExecutableCount(wp_id) + 1, wp_id);
// get the first path
ToolPath^ firstPath=root->firstPath();
double feed = 0;
array<double>^ coor1;
array<double>^coor2;

for (int i = 0; i > samples->getSize()-1; i++) {
coor1 = samples->getCoor(i);
coor2 = samples->getCoor(i + 1);
feed = samples->actualFeedRate(i,i+1);




}


}
//wpid of extension WP
//not of the copied WP
void Patcher::generateWPForToolPath(STEPNCLib::AptStepMaker^ apt,STEPNCLib::Finder^ find,ToolPath^newtool,ToolPath^old) {
WS^ desiredWS = newtool->getWS();
List<WP^> ^path = desiredWS->pathtoRoot();
List<WP^>^oldPath = old->getWS()->pathtoRoot();
path->Reverse();
oldPath->Reverse();
int max1 = path->Count;
int max2 = oldPath->Count;
int countAbove;
int positionInPath;
WP^branchAfter = nullptr;
for (int i = 0; i < max1&&i < max2; i++) {
if (path[i]->getId() != oldPath[i]->getId()) {

positionInPath = i- 1;
branchAfter = path[i-1];

}


}
if (branchAfter != nullptr) {
countAbove= branchAfter->distanceAbove(path[path->Count - 1]);
for (int i = 0; i < countAbove; i++) {
apt->EndWorkplan();

}
}
else {
branchAfter = old->getWS()->getParent;

}
for (int i = positionInPath + 1; i < max1; i++) {
apt->NestWorkplan(path[positionInPath]->getName());
path[positionInPath]->setCopyID(apt->GetCurrentWorkplan());
}

}


/*
Expand Down
2 changes: 1 addition & 1 deletion Patcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ ref class Patcher{
void createPatchedFile(String^ partFile,String^ WPpath,String^newFileName,String^newWorkPlan,String^ coor);
//ToolPath^ firstPath(__int64 root);
void DeleteBefore(__int64 wpid, STEPNCLib::Finder ^find, STEPNCLib::AptStepMaker^apt);

void generateWPForToolPath(STEPNCLib::AptStepMaker^ apt, STEPNCLib::Finder^ find, ToolPath^newtool, ToolPath^old)
};
#endif
75 changes: 75 additions & 0 deletions RawData.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include"stdafx.h"

bool RawData::changeSourceTxt(String^ file) {
if (file != nullptr) {

sourceFile = file;
}
try {
read = gcnew StreamReader(file);
}
catch (Exception ^e) {
Console::WriteLine(e);
return false;
}
type = TXTFILE->Clone;

}
bool RawData::parse() {
coor->Clear();
if (type == TXTFILE) {
return parseTxt();
}
}


bool RawData::parseTxt() {
String ^data = nullptr;
array<String^>^ values;
array<double>^ coorWithTimeDiff;
while (!read->EndOfStream) {
data = read->ReadLine();
if (!data->Contains("#") && data->Contains("UNAVAILABLE")) {
values = data->Split();
coorWithTimeDiff = gcnew array<double>(4);
coorWithTimeDiff[0]= Convert::ToDouble(values[0]);
coorWithTimeDiff[1] = Convert::ToDouble(values[1]);
coorWithTimeDiff[2] = Convert::ToDouble(values[2]);
coor->Add(coorWithTimeDiff);
}

}



}

__int64 RawData::getSize() {
return coor->Count;

}
array<double>^ RawData::getCoor(__int64 i) {

if (i < getSize()) { return coor[i]; }
else {

return nullptr;
}
}

double RawData::actualFeedRate(__int64 i, __int64 j) {
array<double>^ coor1 = getCoor(i);
array<double>^ coor2 = getCoor(j);

double dx = coor1[0] - coor2[0];
double dy = coor1[1] - coor2[1];
double dz = coor1[2] - coor2[2];

double dist = Math::Sqrt(Math::Pow(dx, 2) + Math::Pow(dy, 2) + Math::Pow(dz, 2)) / coor2[3];

//Console::WriteLine("dx {0} dy{1} dz {2} deltat {3} speed{4}",dx,dy,dz,coor2[3],dist);

return dist;
}


36 changes: 36 additions & 0 deletions RawData.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#pragma once
using namespace System;
using namespace System;
using namespace System::Net;

using namespace System::Collections::Generic;
using namespace System::IO;
using namespace System::Text;
using namespace System::Xml;
using namespace System::Collections::Generic;
ref class RawData {
private:
const String^ TXTFILE = "TXT";
String^ sourceFile;
StreamReader ^read ;
String^type;
List<array<double>^>^ coor;
public:

bool changeSourceTxt(String^ file);
//bool changeSourceXml(String^file);
//bool changeSourceMTConnect(String^ request);

bool parse();
RawData() { read = nullptr;
sourceFile = nullptr;
}
__int64 getSize();
bool RawData::parseTxt();

array<double>^getCoor(__int64 i);

double actualFeedRate(__int64, __int64);


};
8 changes: 6 additions & 2 deletions ToolPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ToolPath::ToolPath(WS^ p, bool rapid, double f, double s, __int64 in, __int64 ID
spindleSpeed = s;
index = in;
id = ID;

copyID = -1;
}
WS^ ToolPath::getWS() { return parent; }
__int64 ToolPath::getId(){ return id; }
Expand All @@ -40,7 +40,9 @@ ToolPath^ ToolPath::nextPath(bool % newWP, bool% newWS) {
List<WP^>^path = getWS()->pathtoRoot();
for (int i = 0; i<path->Count; i++) {
nextToolPath = recurseToNextToolPath(path[i], tempWS->getIndex());

if (nextToolPath != nullptr) {
return nextToolPath;
}

}
}
Expand Down Expand Up @@ -86,3 +88,5 @@ ToolPath^ ToolPath::recurseToolPath(Exec^ current) {
return nullptr;
}

__int64 ToolPath::getCopyID() { return copyID; }
bool ToolPath::copyCreated() { if (copyID == -1) { return false; } else { return true; } }
4 changes: 3 additions & 1 deletion ToolPath.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ref class ToolPath
__int64 index;
__int64 id;
WS^ parent;

__int64 copyID;



Expand All @@ -34,6 +34,8 @@ ref class ToolPath
ToolPath^ nextPath(bool % newWP, bool% newWS);
ToolPath^ recurseToNextToolPath(WP^ current, __int64 startIndexAfter);
ToolPath^ recurseToolPath(Exec^ current);
__int64 getCopyID();
bool copyCreated();
//get pointer to next path regardless if it is a new WS or WP
//null if non exist
/*
Expand Down
19 changes: 18 additions & 1 deletion WP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ __int64 WP::getExecutableCount() { return execList->Count; };
WP::WP(String^ n, __int64 ID, __int64 in, WP^p) :Exec(n, ID, in, p, true) {
execList = gcnew List<Exec^>();
};
ToolPath ^ WP::firstPath() {

return firstPath(this);
}

ToolPath ^ WP::firstPath(WP^ root) {
if (root == nullptr) {
Expand All @@ -34,4 +37,18 @@ ToolPath ^ WP::firstPath(WP^ root) {
}
return nullptr;

};
};
__int64 WP::distanceAbove(WP^ ancestor) {
WP^ temp = this;
__int64 count = 0;
while (temp!=nullptr&&temp->getId() != ancestor->getId()) {

temp = temp->getParent;
count += 1;


}
return count;


}
6 changes: 4 additions & 2 deletions WP.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ using namespace System::Text;


List<Exec^>^ execList;
ToolPath ^ firstPath(WP^ root);
public:
void addExecutable(Exec^ e);
WP(String^ n, __int64 ID, __int64 in, WP^p);

Exec^ getExecutable(__int64 i);

__int64 getExecutableCount();
ToolPath ^ firstPath(WP^ root);


ToolPath ^ WP::firstPath();
__int64 distanceAbove(WP^);
};
#endif
2 changes: 1 addition & 1 deletion stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ using namespace STEPNCLib;
#include"MtConnector.h"
#include"Patcher.h"
#include"ToolPath.h"

#include"RawData.h"

0 comments on commit 928725b

Please sign in to comment.