Author Topic: Open Source Survey Package?  (Read 18788 times)

0 Members and 1 Guest are viewing this topic.

MickD

  • King Gator
  • Posts: 3637
  • (x-in)->[process]->(y-out) ... simples!
Re: Open Source Survey Package?
« Reply #105 on: November 06, 2005, 05:42:50 PM »
I don't think you can exp/imp things which are only relevant to the C++ std lib's as the caller/sender has no knowledge of them (say from/to vb), similar to COM interfaces you will probably have to convert/use vanilla type variables such as char[]'s for strings for example.
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

Chuck Gabriel

  • Guest
Re: Open Source Survey Package?
« Reply #106 on: November 06, 2005, 05:46:04 PM »
Swift,

You can see I changed a few miscellaneous minor things in your code, but the primary things I did to get it to compile were:

1) Defined operator< and operator== for the point class.  Not sure why, but the compiler insisted upon this.  Vector isn't a sorted container, so I truly don't understand this one.

2) Removed std::string from the code, and replaced it with char*.  I haven't found anything to indicate that it is possible to export std::string.

Code: [Select]
#ifndef POINTS_H
#define POINTS_H

#ifdef POINTS_EXPORTS

#define DECLSPECIFIER __declspec(dllexport)
#define EXPIMP_TEMPLATE

#else

#define DECLSPECIFIER __declspec(dllimport)
#define EXPIMP_TEMPLATE extern

#endif

#include <vector>

EXPIMP_TEMPLATE class DECLSPECIFIER Point{
public:
// Data
  unsigned int nPtNo;
  double dX;
  double dY;
  double dZ;
  char cDesc[32];

// Constructors and destructor
Point() {}
Point(unsigned int num, double xVal, double yVal, double zVal, const char* desc) :
nPtNo(num), dX(xVal), dY(yVal), dZ(zVal) {
strncpy(cDesc, desc, 31);
cDesc[31] = 0;
}
virtual ~Point() {}

// Operators
// The compiler was pretty insistent that operator< and operator== be defined
// for the Point class
bool operator<(const Point& p) const {
return dX < p.dX;
}
bool operator==(const Point& p) const {
return (dX == p.dX) &&
     (dY == p.dY) &&
(dZ == p.dZ);
}
};

// Explicit instantiation of vector<Point>
EXPIMP_TEMPLATE template class DECLSPECIFIER std::vector<Point>;

EXPIMP_TEMPLATE class DECLSPECIFIER CPoints {
private:
  bool bPtProtect;
  std::vector<Point> pts;
  char* cPath;
public:
  CPoints(); //new drawing
  CPoints(const char* path); //path found in existing drawing
 
  int ImportTextFile();
  int ExportTextFile();
  // int ImportCarlsonCrd(); // I have these figured out, I will need samples and or specs
  // int ExportCarlsonCrd(); // to support other binary formats
  int RotatePoints();
  int TranslatePoints();
  int EditPoints();
  int ListPoints();
  int AddPoint(Point);
  int AddPoint(unsigned int nPtNo,
               double dX,
               double dY,
               double dZ,
               char cDesc[32]);
  Point Getpoint(unsigned int PtNo);
  int GetPtIndexCount(void);
  Point GetPtByIndex(int nPtIndex);
  unsigned int GetHighPointNo(void);
  int GetPointNoExtremes(unsigned int &LowNo, unsigned int &HighNo);

//////////////////////////////////VB Wrappers////////////////////////////////////////////
  void* __stdcall CreatePoint();
  void* __stdcall CreatePoint(const char* path);
  void* __stdcall DestroyPoint(void* objptr);
//////////////////////////////////VB Wrappers////////////////////////////////////////////
  bool operator<(const CPoints& c) const {
    return pts <  c.pts;
  }
  bool operator==(const CPoints& c) const {
    return pts == c.pts;
  }
};

#endif

Chuck Gabriel

  • Guest
Re: Open Source Survey Package?
« Reply #107 on: November 06, 2005, 06:08:51 PM »
I take back point #2.  Check which version of the C runtime you are linking against.  I found a usenet post that said the DLL version of the runtime already exports std::basic_string<char>, so I checked and VC++ had set my DLL project up to link to the multithreaded version by default.  I switched it to Multithreaded DLL, swapped the std::string back in place of char*, and it compiled with no problem.

Swift

  • Swamp Rat
  • Posts: 596
Re: Open Source Survey Package?
« Reply #108 on: November 06, 2005, 07:56:22 PM »
Thanks Chuck. I'm working on basic file stuff now. I hope to have a first try ready soon.

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Open Source Survey Package?
« Reply #109 on: November 07, 2005, 11:02:28 AM »
Now remeber im still in the learning process so pardon the question. Whats the diff between these: #ifndef & #ifdef?
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Chuck Gabriel

  • Guest
Re: Open Source Survey Package?
« Reply #110 on: November 07, 2005, 11:18:59 AM »
#ifndef <- If macro is NOT defined

#ifdef <- If macro IS defined


JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Open Source Survey Package?
« Reply #111 on: November 07, 2005, 11:25:16 AM »
Ah gotcha. Thanx
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Swift

  • Swamp Rat
  • Posts: 596
Re: Open Source Survey Package?
« Reply #112 on: November 14, 2005, 08:22:01 PM »
ok, I have a frame work in place and working using win32 api calls to select and parse a comma delimited text file (Thanks Cornbread) I have it compiled in VC6 for the moment if anyone wants to work on the arx for inserting blocks with attributes code. Also if anyone has a lisp routine laying around that does the same I could use it to work on the SDS for Intellicad.

Chuck Gabriel

  • Guest
Re: Open Source Survey Package?
« Reply #113 on: November 14, 2005, 09:24:41 PM »
The AcadUtilities class implemented in AcadUtilities.cpp contains the core functionality for inserting blocks (amongst other things).  The other functions in that class will probably be useful later on in the project as well.  The other files contain support functions and classes.

The functions in AcadUtilities that add objects to the database always assume the objects are to be added to modelspace.  If this turns out to be too inflexible, it would be easy enough to modify.  We probably should make that decision up front though, as changes to the interface will necessitate changes to any client code.
« Last Edit: November 15, 2005, 02:52:51 PM by Chuck Gabriel »

Swift

  • Swamp Rat
  • Posts: 596
Re: Open Source Survey Package?
« Reply #114 on: November 15, 2005, 02:03:57 PM »
Thanks Chuck, I'll see what I can do with it tonight.

Chuck Gabriel

  • Guest
Re: Open Source Survey Package?
« Reply #115 on: November 15, 2005, 07:57:38 PM »
Here is a sample of how to use what I posted yesterday:

Code: [Select]
#include "AcadUtilities.h"

void foo() {
  AcadUtilities acadUtils(curDoc()->database());
 
  // Import a layer
  // importLayer searches through the file specified by the LAYERS_FILE constant
  // until it finds a layer name that matches the argument.  Then uses
  // the data in the layers file to create the layer in the current dwg.
  // Layers file format is LayerName,Color,Linetype
  if(!acadUtils.importLayer("MyLayer")) {
    acutPrintf("\nUnable to import layer:  MyLayer");
    acutPrintf("\nAborting!");
    return;
  }

  // Import a block definition
  // First argument is file name.  Second is the name to give the block
  AcDbObjectId blockObjId = acadUtils.importBlock("MyBlock.dwg", "MyBlock");
  if(!blockObjId) {
    acutPrintf("\nUnable to import block:  MyBlock.dwg");
    acutPrintf("\nAborting!");
    return;
  }

  // Insert an instance of the block
  // Arguments are
  // ObjectId of block table record,
  // Insertion point,
  // Scale,
  // Rotation,
  // Layer to insert onto
  acadUtils.insertBlock(blockObjId,
                               AcGePoint3d(0, 0, 0),
                               AcGeScale3d(1, 1, 1),
                               0,
                              "MyLayer");
  // Draw a line
  // Start point,
  // End point,
  // Layer
  acadUtils.addLine(AcGePoint3d(0, 0, 0),
                          AcGePoint3d(1, 1, 0),
                         "MyLayer");

  // Draw a box
  // Lower left corner,
  // Upper right corner,
  // Layer
  acadUtils.addRectangle(AcGePoint3d(0, 0, 0),
                                  AcGePoint3d(1, 1, 0),
                                 "MyLayer");

  // Draw text
  // Insertion,
  // Height,
  // Rotation,
  // Horizontal alignment,
  // Vertical alignment,
  // Text string,
  // Layer
  acadUtils.addText(AcGePoint3d(0, 0, 0),
                           0.09375,
                           0,
                           AcDb::kTextMid,
                           AcDb::kTextVertMid,
                           "SAMPLE TEXT",
                           "MyLayer");
}

[edit]formatting went a little wonky[/edit]
« Last Edit: November 15, 2005, 08:01:40 PM by Chuck Gabriel »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Open Source Survey Package?
« Reply #116 on: November 15, 2005, 08:10:04 PM »
Hi Chuck,
Can you change the Linetype adder in the Utility to have this sort of functionality ?
... instead on automatically using acad.lin

Code: [Select]
  (setq linTypeFile (if (= acEnglish (getvar "Measurement"))
                     (findfile "acad.lin")
                     (findfile "acadiso.lin")
                   )
 )
...
... >>

edit : translated the magic number stuff
« Last Edit: November 15, 2005, 08:40:06 PM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Chuck Gabriel

  • Guest
Re: Open Source Survey Package?
« Reply #117 on: November 15, 2005, 08:23:51 PM »
Good catch Kerry.

Code: [Select]
AcDbObjectId AcadUtilities::importLineType(const string& lineTypeName) {
// Does the linetype already exist?
AcDbLinetypeTableRecordPointer lineTypeRecord(lineTypeName.c_str(),
                                            _pDb,
AcDb::kForRead);
if(lineTypeRecord.openStatus() == Acad::eOk)
return lineTypeRecord->objectId();  // Yep.  It's already there.  Use it.

string linetypeFileName;
if(_pDb->measurement() == AcDb::MeasurementValue::kEnglish)
linetypeFileName = "ACAD.LIN";
else
linetypeFileName = "ACADISO.LIN";

if(_pDb->loadLineTypeFile(lineTypeName.c_str(), linetypeFileName.c_str()) == Acad::eOk) {
AcDbLinetypeTableRecordPointer lineTypeRecord(lineTypeName.c_str(),
_pDb,
AcDb::kForRead);
if(lineTypeRecord.openStatus() == Acad::eOk)
return lineTypeRecord->objectId();
}
acutPrintf("\nUnable to load linetype: %s", lineTypeName.c_str());
return AcDbObjectId::kNull;
}

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Open Source Survey Package?
« Reply #118 on: November 15, 2005, 08:39:02 PM »
Thanks Chuck,
That should keep us folk over the pond happy .. :)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Chuck Gabriel

  • Guest
Re: Open Source Survey Package?
« Reply #119 on: November 28, 2005, 06:34:42 PM »
This is mostly for Swift.  I forgot you specifically needed to deal with attributed blocks.  Here is a snippet out of a larger program that demonstrates how to do that.

Code: [Select]
// Insert the footing mark
AcDbObjectId blockRefId = _acadUtils.insertBlock(blockObjId,
   markInsertion,
  AcGeScale3d(dimScale, dimScale, dimScale),
  0,
  COLUMN_MARK_LAYER);

// Open the newly inserted block reference so it can be manipulated
AcDbObjectPointer<AcDbBlockReference> footingMark(blockRefId, AcDb::kForWrite);
if(footingMark.openStatus() != Acad::eOk) {
acutPrintf("\nUnable to open footing mark for write.");
return;
}

// Determine footing mark
double width, length;
width = centerToLeft + centerToRight;
length = centerToBottom + centerToTop;
ostringstream os;
if(width == length)
os << "F" << int(width / 1.2);
else
os << "F" << int(width / 1.2) << "x" << int(length / 1.2);
string footingMarkText = os.str();

// Determine t/ftg elevation
char szFootingElevation[25];
acdbRToS(elevation, 4, 4, szFootingElevation);
string footingElevation(szFootingElevation);
// Add the leading zero if the elevation is expressed in inches only
if(footingElevation.find("'") == string::npos) {
ostringstream os;
if(elevation < 0) {
os << "-0'-" << footingElevation.substr(1);
}
else {
os << "0'-" << footingElevation.substr(0);
}
footingElevation = os.str();
}
// Remove the inch marks from the end of the elevation
footingElevation = footingElevation.substr(0, footingElevation.length() - 1);

// Append and set the attributes
AcGeMatrix3d transMat = footingMark->blockTransform();
AcDbObjectIterator* pIterator = footingMark->attributeIterator();
for(pIterator->start() ; !pIterator->done() ; pIterator->step()) {
AcDbObjectId attributeObjId = pIterator->objectId();
AcDbObjectPointer<AcDbAttribute> attribute(attributeObjId, AcDb::kForWrite);
if(attribute.openStatus() != Acad::eOk) {
acutPrintf("\nUnable to open attribute reference for write.");
continue;
}
char* pszTag = attribute->tag();
string tagString(pszTag);
delete pszTag;
if(tagString == "FTG_MARK") {
attribute->setTextString(footingMarkText.c_str());
}
else {
if(tagString == "COL_MARK") {
attribute->setTextString(columnMark.c_str());
}
else {
if(tagString == "T/FTG") {
attribute->setTextString(footingElevation.c_str());
}
}
}
}
delete pIterator;