/*!  
  Should be called _once_ after you've finished setting up your
  layer (name and color number).  Calling this method more than once
  for a layer might lead to hard-to-find bugs. After calling this
  method, the layer information (color number) will be available to
  entities using this layer.  
*/
void 
dimeLayerTable::registerLayer(dimeModel * model)
{
  if (this->layerInfo == NULL && this->layerName != NULL) {
    this->layerInfo = (dimeLayer*) 
      model->addLayer(this->layerName, DXFABS(this->colorNumber));    
  }
}
dimeTableEntry *
dimeLayerTable::copy(dimeModel * const model) const
{
  dimeMemHandler *memh = model->getMemHandler();
  dimeLayerTable *l = new(memh) dimeLayerTable;
  l->colorNumber = this->colorNumber;
  if (this->layerName) {
    DXF_STRCPY(memh, l->layerName, this->layerName);
  }
  if (this->layerInfo) {
    l->layerInfo = (dimeLayer*)model->addLayer(this->layerInfo->getLayerName(), 
                                               DXFABS(this->colorNumber));
  }
  if (!copyRecords(l, model)) {
    // check if allocated on heap.
    if (!memh) delete l;
    l = NULL;
  }
  return l;
}
Exemple #3
0
void 
convert_arc(const dimeEntity *entity, const dimeState *state, 
	    dxfLayerData *layerData, dxfConverter *converter)
{
  dimeArc *arc = (dimeArc*) entity;

  dimeMatrix matrix;
  state->getMatrix(matrix);

  dimeVec3f e = arc->getExtrusionDir();
  dxfdouble thickness = arc->getThickness();

  if (e != dimeVec3f(0,0,1)) {
    dimeMatrix m;
    dimeEntity::generateUCS(e, m);
    matrix.multRight(m);
  }
  e = dimeVec3f(0,0,1);

  dimeVec3f center;
  arc->getCenter(center);

  dimeParam param;
  if (arc->getRecord(38, param)) {
    center[2] = param.double_data;
  }
  
  dxfdouble radius = arc->getRadius();
  
  double end = arc->getEndAngle();

  while (end < arc->getStartAngle()) {
    end += 360.0;
  }

  double delta = DXFDEG2RAD(end - arc->getStartAngle());

  if (delta == 0.0) {
#ifndef NDEBUG
    fprintf(stderr,"ARC with startAngle == endAngle!\n");
#endif
    end += 2*M_PI;
    delta = DXFDEG2RAD(end - arc->getStartAngle());
  }
  
  int ARC_NUMPTS = converter->getNumSub();
  if (ARC_NUMPTS <= 0) { // use maxerr
    ARC_NUMPTS = calc_num_sub(converter->getMaxerr(), radius);
  }

  // find the number of this ARC that fits inside 2PI
  int parts = (int) DXFABS((2*M_PI) / delta);
  
  // find # pts to use for arc
  // add one to avoid arcs with 0 line segments
  int numpts = ARC_NUMPTS / parts + 1;
  if (numpts > ARC_NUMPTS) numpts = ARC_NUMPTS;
  
  double inc = delta / numpts;
  double rad = DXFDEG2RAD(arc->getStartAngle());
  int i;

  dimeVec3f v;
  dimeVec3f prev(center[0] + radius * cos(rad),
		 center[1] + radius * sin(rad),
		 center[2]);
  rad += inc;
  
  for (i = 1; i < numpts; i++) {
    v = dimeVec3f(center[0] + radius * cos(rad),
		  center[1] + radius * sin(rad),
		  center[2]);
    if (thickness == 0.0) {
      layerData->addLine(prev, v, &matrix);
    }
    else {
      layerData->addQuad(prev, v, v + e * thickness, prev + e * thickness,
			 &matrix);
    }
    prev = v;
    rad += inc;
  }
  rad = DXFDEG2RAD(end);
  v = dimeVec3f(center[0] + radius * cos(rad),
		center[1] + radius * sin(rad),
		center[2]);
  if (thickness == 0.0) {
    layerData->addLine(prev, v, &matrix);
  }
  else {
    layerData->addQuad(prev, v, v + e * thickness, prev + e * thickness,
		       &matrix);
  }
}
/*!
  Sets the color number.
 */
void 
dimeLayerTable::setColorNumber(const int16 colnum)
{
  this->colorNumber = colnum;
  if (this->layerInfo) this->layerInfo->setColorNumber(DXFABS(this->colorNumber));
}