Skip to content

Commit 928725b

Browse files
author
salamb
committed
Added Raw data Object to handle diiferent types of samples
1 parent ec6b784 commit 928725b

File tree

10 files changed

+217
-25
lines changed

10 files changed

+217
-25
lines changed

Exec.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,28 @@ String ^ name;
1616
__int64 id;
1717
__int64 index;
1818
WP^ parent;
19+
__int64 copyID;
1920
bool typeWP;
2021
public:
21-
22+
2223
bool isWP(){return typeWP;};
2324
//get name of Executable
2425
String^ getName(){return name;};
2526
// get stpnc id of Executable
2627
__int64 getId(){return id;};
2728
// index in list of enabled executalbes for an enabled parent WorkPlan
2829
__int64 getIndex(){return index;};
29-
30+
__int64 getCopyID() { return copyID; }
31+
void setCopyID(__int64 i) { copyID = i; }
32+
bool copyCreated() { if (copyID == -1) { return false; } else { return true; } }
3033
WP^ getParent();
3134
Exec(String^ n,__int64 ID,__int64 in,WP^p,bool iswp){
3235
name=n;
3336
id=ID;
3437
index=in;
3538
parent=p;
3639
typeWP=iswp;
40+
copyID = -1;
3741
}
3842
};
3943
#endif

Patcher.cpp

Lines changed: 67 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -430,17 +430,6 @@ List<List<long long>^> ^ Patcher::getAllRapidPaths(long long workplan, STEPNCLib
430430
return rapidToolPaths;
431431
}
432432

433-
double Patcher::actualFeedRate(array<double>^ coor1,array<double>^ coor2){
434-
double dx=coor1[0]-coor2[0];
435-
double dy=coor1[1]-coor2[1];
436-
double dz=coor1[2]-coor2[2];
437-
438-
double dist= Math::Sqrt( Math::Pow(dx,2)+Math::Pow(dy,2)+Math::Pow(dz,2))/coor2[3];
439-
440-
//Console::WriteLine("dx {0} dy{1} dz {2} deltat {3} speed{4}",dx,dy,dz,coor2[3],dist);
441-
442-
return dist;
443-
}
444433
List<double> ^Patcher::getAllPoints(List<long long>^ paths,STEPNCLib::Finder ^find){
445434
List<long long >^ curves=nullptr;
446435
List<double> ^pts=gcnew List<double>();
@@ -602,7 +591,7 @@ void Patcher::OpenFile(String^file,String^ desiredWorkPlanPath,String^newWorkPla
602591
find->Open238(file);
603592
apt->Open238(file);
604593
array<String^>^ nameList=desiredWorkPlanPath->Split('/');
605-
__int64 id= getWorkPlanByPath(nameList,find);
594+
wpID= getWorkPlanByPath(nameList,find);
606595
apt->Inches();
607596
find->APIUnitsInch();
608597
}
@@ -625,22 +614,85 @@ void Patcher::DeleteBefore(__int64 wpid,STEPNCLib::Finder ^find,STEPNCLib::AptSt
625614
void Patcher::createPatchedFile(String^ partFile,String^ WPpath,String^newFileName,String^newWorkPlan,String^ coor){
626615
STEPNCLib::AptStepMaker^ apt = gcnew AptStepMaker();
627616
STEPNCLib::Finder^find = gcnew Finder();
628-
629-
__int64 oldWPID;
617+
bool newWS = true;
618+
bool newWP = true;
630619

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

635-
626+
samples->changeSourceTxt(coor);
627+
samples->parse();
636628

637629
root=getAllExec(oldWPID,find,nullptr,0);
630+
631+
/////init
638632

633+
long wp_id = find->GetMainWorkplan();
634+
Console::WriteLine("Main Workplan name " + find->GetExecutableName(wp_id));
635+
636+
// add a new workplan at the end of the project
637+
apt->NestWorkplanAfter("Workplan for MTConnect results", find->GetWorkplanExecutableCount(wp_id) + 1, wp_id);
638+
// get the first path
639+
ToolPath^ firstPath=root->firstPath();
640+
double feed = 0;
641+
array<double>^ coor1;
642+
array<double>^coor2;
643+
644+
for (int i = 0; i > samples->getSize()-1; i++) {
645+
coor1 = samples->getCoor(i);
646+
coor2 = samples->getCoor(i + 1);
647+
feed = samples->actualFeedRate(i,i+1);
639648

649+
650+
651+
652+
}
640653

641654

642655
}
656+
//wpid of extension WP
657+
//not of the copied WP
658+
void Patcher::generateWPForToolPath(STEPNCLib::AptStepMaker^ apt,STEPNCLib::Finder^ find,ToolPath^newtool,ToolPath^old) {
659+
WS^ desiredWS = newtool->getWS();
660+
List<WP^> ^path = desiredWS->pathtoRoot();
661+
List<WP^>^oldPath = old->getWS()->pathtoRoot();
662+
path->Reverse();
663+
oldPath->Reverse();
664+
int max1 = path->Count;
665+
int max2 = oldPath->Count;
666+
int countAbove;
667+
int positionInPath;
668+
WP^branchAfter = nullptr;
669+
for (int i = 0; i < max1&&i < max2; i++) {
670+
if (path[i]->getId() != oldPath[i]->getId()) {
671+
672+
positionInPath = i- 1;
673+
branchAfter = path[i-1];
674+
675+
}
676+
677+
678+
}
679+
if (branchAfter != nullptr) {
680+
countAbove= branchAfter->distanceAbove(path[path->Count - 1]);
681+
for (int i = 0; i < countAbove; i++) {
682+
apt->EndWorkplan();
683+
684+
}
685+
}
686+
else {
687+
branchAfter = old->getWS()->getParent;
688+
689+
}
690+
for (int i = positionInPath + 1; i < max1; i++) {
691+
apt->NestWorkplan(path[positionInPath]->getName());
692+
path[positionInPath]->setCopyID(apt->GetCurrentWorkplan());
693+
}
643694

695+
}
644696

645697

646698
/*

Patcher.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ ref class Patcher{
5151
void createPatchedFile(String^ partFile,String^ WPpath,String^newFileName,String^newWorkPlan,String^ coor);
5252
//ToolPath^ firstPath(__int64 root);
5353
void DeleteBefore(__int64 wpid, STEPNCLib::Finder ^find, STEPNCLib::AptStepMaker^apt);
54-
54+
void generateWPForToolPath(STEPNCLib::AptStepMaker^ apt, STEPNCLib::Finder^ find, ToolPath^newtool, ToolPath^old)
5555
};
5656
#endif

RawData.cpp

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#include"stdafx.h"
2+
3+
bool RawData::changeSourceTxt(String^ file) {
4+
if (file != nullptr) {
5+
6+
sourceFile = file;
7+
}
8+
try {
9+
read = gcnew StreamReader(file);
10+
}
11+
catch (Exception ^e) {
12+
Console::WriteLine(e);
13+
return false;
14+
}
15+
type = TXTFILE->Clone;
16+
17+
}
18+
bool RawData::parse() {
19+
coor->Clear();
20+
if (type == TXTFILE) {
21+
return parseTxt();
22+
}
23+
}
24+
25+
26+
bool RawData::parseTxt() {
27+
String ^data = nullptr;
28+
array<String^>^ values;
29+
array<double>^ coorWithTimeDiff;
30+
while (!read->EndOfStream) {
31+
data = read->ReadLine();
32+
if (!data->Contains("#") && data->Contains("UNAVAILABLE")) {
33+
values = data->Split();
34+
coorWithTimeDiff = gcnew array<double>(4);
35+
coorWithTimeDiff[0]= Convert::ToDouble(values[0]);
36+
coorWithTimeDiff[1] = Convert::ToDouble(values[1]);
37+
coorWithTimeDiff[2] = Convert::ToDouble(values[2]);
38+
coor->Add(coorWithTimeDiff);
39+
}
40+
41+
}
42+
43+
44+
45+
}
46+
47+
__int64 RawData::getSize() {
48+
return coor->Count;
49+
50+
}
51+
array<double>^ RawData::getCoor(__int64 i) {
52+
53+
if (i < getSize()) { return coor[i]; }
54+
else {
55+
56+
return nullptr;
57+
}
58+
}
59+
60+
double RawData::actualFeedRate(__int64 i, __int64 j) {
61+
array<double>^ coor1 = getCoor(i);
62+
array<double>^ coor2 = getCoor(j);
63+
64+
double dx = coor1[0] - coor2[0];
65+
double dy = coor1[1] - coor2[1];
66+
double dz = coor1[2] - coor2[2];
67+
68+
double dist = Math::Sqrt(Math::Pow(dx, 2) + Math::Pow(dy, 2) + Math::Pow(dz, 2)) / coor2[3];
69+
70+
//Console::WriteLine("dx {0} dy{1} dz {2} deltat {3} speed{4}",dx,dy,dz,coor2[3],dist);
71+
72+
return dist;
73+
}
74+
75+

RawData.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#pragma once
2+
using namespace System;
3+
using namespace System;
4+
using namespace System::Net;
5+
6+
using namespace System::Collections::Generic;
7+
using namespace System::IO;
8+
using namespace System::Text;
9+
using namespace System::Xml;
10+
using namespace System::Collections::Generic;
11+
ref class RawData {
12+
private:
13+
const String^ TXTFILE = "TXT";
14+
String^ sourceFile;
15+
StreamReader ^read ;
16+
String^type;
17+
List<array<double>^>^ coor;
18+
public:
19+
20+
bool changeSourceTxt(String^ file);
21+
//bool changeSourceXml(String^file);
22+
//bool changeSourceMTConnect(String^ request);
23+
24+
bool parse();
25+
RawData() { read = nullptr;
26+
sourceFile = nullptr;
27+
}
28+
__int64 getSize();
29+
bool RawData::parseTxt();
30+
31+
array<double>^getCoor(__int64 i);
32+
33+
double actualFeedRate(__int64, __int64);
34+
35+
36+
};

ToolPath.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ ToolPath::ToolPath(WS^ p, bool rapid, double f, double s, __int64 in, __int64 ID
2020
spindleSpeed = s;
2121
index = in;
2222
id = ID;
23-
23+
copyID = -1;
2424
}
2525
WS^ ToolPath::getWS() { return parent; }
2626
__int64 ToolPath::getId(){ return id; }
@@ -40,7 +40,9 @@ ToolPath^ ToolPath::nextPath(bool % newWP, bool% newWS) {
4040
List<WP^>^path = getWS()->pathtoRoot();
4141
for (int i = 0; i<path->Count; i++) {
4242
nextToolPath = recurseToNextToolPath(path[i], tempWS->getIndex());
43-
43+
if (nextToolPath != nullptr) {
44+
return nextToolPath;
45+
}
4446

4547
}
4648
}
@@ -86,3 +88,5 @@ ToolPath^ ToolPath::recurseToolPath(Exec^ current) {
8688
return nullptr;
8789
}
8890

91+
__int64 ToolPath::getCopyID() { return copyID; }
92+
bool ToolPath::copyCreated() { if (copyID == -1) { return false; } else { return true; } }

ToolPath.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ ref class ToolPath
1919
__int64 index;
2020
__int64 id;
2121
WS^ parent;
22-
22+
__int64 copyID;
2323

2424

2525

@@ -34,6 +34,8 @@ ref class ToolPath
3434
ToolPath^ nextPath(bool % newWP, bool% newWS);
3535
ToolPath^ recurseToNextToolPath(WP^ current, __int64 startIndexAfter);
3636
ToolPath^ recurseToolPath(Exec^ current);
37+
__int64 getCopyID();
38+
bool copyCreated();
3739
//get pointer to next path regardless if it is a new WS or WP
3840
//null if non exist
3941
/*

WP.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ __int64 WP::getExecutableCount() { return execList->Count; };
99
WP::WP(String^ n, __int64 ID, __int64 in, WP^p) :Exec(n, ID, in, p, true) {
1010
execList = gcnew List<Exec^>();
1111
};
12+
ToolPath ^ WP::firstPath() {
1213

14+
return firstPath(this);
15+
}
1316

1417
ToolPath ^ WP::firstPath(WP^ root) {
1518
if (root == nullptr) {
@@ -34,4 +37,18 @@ ToolPath ^ WP::firstPath(WP^ root) {
3437
}
3538
return nullptr;
3639

37-
};
40+
};
41+
__int64 WP::distanceAbove(WP^ ancestor) {
42+
WP^ temp = this;
43+
__int64 count = 0;
44+
while (temp!=nullptr&&temp->getId() != ancestor->getId()) {
45+
46+
temp = temp->getParent;
47+
count += 1;
48+
49+
50+
}
51+
return count;
52+
53+
54+
}

WP.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@ using namespace System::Text;
1818

1919

2020
List<Exec^>^ execList;
21+
ToolPath ^ firstPath(WP^ root);
2122
public:
2223
void addExecutable(Exec^ e);
2324
WP(String^ n, __int64 ID, __int64 in, WP^p);
2425

2526
Exec^ getExecutable(__int64 i);
2627

2728
__int64 getExecutableCount();
28-
ToolPath ^ firstPath(WP^ root);
29-
29+
30+
ToolPath ^ WP::firstPath();
31+
__int64 distanceAbove(WP^);
3032
};
3133
#endif

stdafx.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ using namespace STEPNCLib;
1313
#include"MtConnector.h"
1414
#include"Patcher.h"
1515
#include"ToolPath.h"
16-
16+
#include"RawData.h"
1717

0 commit comments

Comments
 (0)