2009-05-14
01:07 PM
- last edited on
2023-05-23
04:40 PM
by
Rubia Torres
API_LibPartSection CreateSection(const HPGLPattern<double, GS::Guid> & hpgl)
{
char buffer[1000];
API_LibPartSection section;
BoundingBox<double> box;
box.AddSegments(hpgl.GetSegments().begin(), hpgl.GetSegments().end());
box.AddArcs(hpgl.GetArcs().begin(), hpgl.GetArcs().end());
double aa = box.maxx() - box.minx();
double bb = box.maxy() - box.miny();
// Comment script section
BNZeroMemory (§ion, sizeof (API_LibPartSection));
section.sectType = API_SectComText;
ACAPI_LibPart_NewSection (§ion);
CHCopyC(hpgl.GetDescription().c_str(), buffer);
ACAPI_LibPart_WriteSection (Strlen32 (buffer), buffer);
ACAPI_LibPart_EndSection ();
// Master script section
BNZeroMemory (§ion, sizeof (API_LibPartSection));
section.sectType = API_Sect1DScript;
ACAPI_LibPart_NewSection (§ion);
buffer[0] = '\0';
ACAPI_LibPart_WriteSection (Strlen32 (buffer), buffer);
ACAPI_LibPart_EndSection ();
// 3D script section
BNZeroMemory (§ion, sizeof (API_LibPartSection));
section.sectType = API_Sect3DScript;
ACAPI_LibPart_NewSection (§ion);
buffer[0] = '\0';
ACAPI_LibPart_WriteSection (Strlen32 (buffer), buffer);
ACAPI_LibPart_EndSection ();
// 2D script section
BNZeroMemory (§ion, sizeof (API_LibPartSection));
section.sectType = API_Sect2DScript;
ACAPI_LibPart_NewSection (§ion);
for(size_t i = 0; i < hpgl.GetSegments().size(); ++i)
{
std::ostringstream os;
const Segment2<double, GS::Guid> & segment = hpgl.GetSegments();
os << "LINE2 " << segment.p0()[0] - box.minx() << ", " << segment.p0()[1] - box.miny() << ", " << segment.p1()[0] - box.minx() << ", " << segment.p1()[1] - box.miny() << std::endl;
CHCopyC(os.str().c_str(), buffer);
ACAPI_LibPart_WriteSection(Strlen32 (buffer), buffer);
}
for(size_t i = 0; i < hpgl.GetArcs().size(); ++i)
{
std::ostringstream os;
const Arc2<double, GS::Guid> & arc = hpgl.GetArcs();
os << "ARC2 " << arc.p0()[0] - box.minx() << ", " << arc.p0()[1] - box.miny() << ", " << arc.radius() << ", " << (arc.startAngle() * 180) / M_PI << ", " << (arc.endAngle() * 180) / M_PI << std::endl;
CHCopyC(os.str().c_str(), buffer);
ACAPI_LibPart_WriteSection(Strlen32 (buffer), buffer);
}
ACAPI_LibPart_EndSection ();
// Parameters section
BNZeroMemory (§ion, sizeof (API_LibPartSection));
section.sectType = API_SectParamDef;
return section;
} API_LibPart CreateGDLFromHPGL(const HPGLPattern<double, GS::Guid> & hpgl)
{
API_LibPart libPart;
GSErrCode err = NoError;
BoundingBox<double> box;
box.AddSegments(hpgl.GetSegments().begin(), hpgl.GetSegments().end());
box.AddArcs(hpgl.GetArcs().begin(), hpgl.GetArcs().end());
double aa = box.maxx() - box.minx();
double bb = box.maxy() - box.miny();
BNZeroMemory (&libPart, sizeof (API_LibPart));
libPart.typeID = APILib_ObjectID;
libPart.isTemplate = false;
libPart.isPlaceable = true;
CHCopyC("{4ABD0A6E-634B-4931-B3AA-9BEE01F39666}-{00000000-0000-0000-0000-000000000000}", libPart.parentUnID);
CHANSI2Unicode(hpgl.GetName().c_str(), hpgl.GetName().length(), libPart.docu_UName, API_UniLongNameLen);
CHANSI2Unicode(hpgl.GetName().c_str(), hpgl.GetName().length(), libPart.file_UName, API_UniLongNameLen);
err = ACAPI_LibPart_Search(&libPart, false);
if(err == NoError) // update needed
{
API_LibPartSection section = CreateSection(hpgl);
GSHandle sectionHdl = NULL;
err = ACAPI_LibPart_GetSect_ParamDef (&libPart, NULL, &aa, &bb, NULL, §ionHdl);
API_LibPartDetails details;
BNZeroMemory (&details, sizeof (API_LibPartDetails));
err = ACAPI_LibPart_SetDetails_ParamDef (&libPart, sectionHdl, &details);
err = ACAPI_LibPart_UpdateSection(libPart.index, §ion, sectionHdl, NULL);
if(err == NoError)
{
err = ACAPI_LibPart_Save(&libPart);
if(err == NoError)
{
}
else
{
// I HAVE ERROR HERE
}
}
else
{
// NO ERROR
}
BMKillHandle(§ionHdl);
}
else // New LibPart needed
{
IO::Location folderLoc(hpgl.GetDir().c_str());
folderLoc.AppendToLocal ("GDL");
IO::Folder destFolder (folderLoc, IO::Folder::Create);
if (destFolder.GetStatus () != NoError || !destFolder.IsWriteable ())
err = APIERR_GENERAL;
libPart.location = &folderLoc;
err = ACAPI_LibPart_Create (&libPart);
if (err == NoError) {
API_LibPartSection section = CreateSection(hpgl);
GSHandle sectionHdl = NULL;
ACAPI_LibPart_GetSect_ParamDef (&libPart, NULL, &aa, &bb, NULL, §ionHdl);
API_LibPartDetails details;
BNZeroMemory (&details, sizeof (API_LibPartDetails));
ACAPI_LibPart_SetDetails_ParamDef (&libPart, sectionHdl, &details);
ACAPI_LibPart_AddSection (§ion, sectionHdl, NULL);
BMKillHandle (§ionHdl);
// Save the constructed library part
if (err == NoError)
err = ACAPI_LibPart_Save (&libPart);
if (libPart.location != NULL) {
delete libPart.location;
libPart.location = NULL;
}
}
}
return libPart;
} 2009-05-15 01:35 PM
char buf[1000];
char * buffer = buf;
std::ostringstream os;
os << "LINE2 0, 0, 10, 10" << std::endl;
CHCopyC(os.str().c_str(), buffer);
API_LibPartSection section;
BNZeroMemory (§ion, sizeof (API_LibPartSection));
section.sectType = API_Sect2DScript;
GSHandle sectionHdl = NULL;
GS::UniString us;
err = ACAPI_LibPart_GetSection(libPart.index, §ion, §ionHdl, &us);
//BNZeroMemory (§ion, sizeof (API_LibPartSection));
//section.sectType = API_Sect2DScript;
//ACAPI_LibPart_NewSection (§ion);
//err = ACAPI_LibPart_WriteSection (Strlen32 (buffer), buffer);
//ACAPI_LibPart_EndSection ();
err = ACAPI_LibPart_UpdateSection(libPart.index, §ion, &buffer /*sectionHdl*/, &us);
BNZeroMemory (§ion, sizeof (API_LibPartSection));
section.sectType = API_Sect2DScript;
BMKillHandle(§ionHdl);
sectionHdl = NULL;
err = ACAPI_LibPart_GetSection(libPart.index, §ion, §ionHdl, 0);
CHCopyC(os.str().c_str(), buffer);
BMKillHandle(§ionHdl);
if(err == NoError)
{
err = ACAPI_LibPart_Save(&libPart);
if(err == NoError)
{
}
else
{
// I HAVE ERROR HERE
}
}
else
{
// NO ERROR
} 2009-05-15 07:14 PM
2009-05-15 07:29 PM
2009-05-16 01:56 PM
bamboos wrote:Sorry, I'm struggling to understand what you are trying to do. Take a look at
I've try to update section in multiple ways... and nothing works. Sometimes the ACAPI_LibPart_UpdateSection returns noerror but ACAPI_LibPart_Save returns "General error" (no idea what is wrong). In other way ACAPI_LibPart_UpdateSection gives the "General error" :/:/ and sometimes the "Insufficient memory." error... What is wrong.
2009-05-18 09:33 AM