Acad::ErrorStatus AsdkSmiley::osnapQuad( const AcGePoint3d& pickPoint, AcGePoint3dArray& snapPoints) const { AcGeVector3d xoff(0,0,0); AcGeVector3d yoff(0,0,0); // Osnap quad to the face's quad points // xoff.x = yoff.y = radius(); AcGePoint3d center( center() ); snapPoints.append( center + xoff ); snapPoints.append( center + yoff ); snapPoints.append( center - xoff ); snapPoints.append( center - yoff ); // Osnap quad to the eyes' quad points // AcGePoint3dArray eyearray; AcGePoint3d eyecen; eyes( eyearray ); for( int i = 0; i < eyearray.length(); i++ ){ eyecen = eyearray.at( i ); xoff.x = meyesize; yoff.y = meyesize; snapPoints.append( eyecen + xoff ); snapPoints.append( eyecen + yoff ); snapPoints.append( eyecen - xoff ); snapPoints.append( eyecen - yoff ); } return Acad::eOk; }
int CArxHelper::CreatePLine(AcDbPolyline*& pPolyline, const AcGePoint3dArray& arrPt, double dWith, BOOL bClose) { pPolyline = new AcDbPolyline(arrPt.length()); for(int i = 0; i < arrPt.length(); i++) { pPolyline->addVertexAt(i,arrPt.at(i).convert2d(AcGePlane::kXYPlane),0.0); } pPolyline->setConstantWidth(dWith); pPolyline->setClosed(bClose); return 0; }
Acad::ErrorStatus AsdkSmiley::getGripPoints( AcGePoint3dArray& gripPoints, AcDbIntArray& osnapMasks, AcDbIntArray& geomIds) const { assertReadEnabled(); // Grip points to face // AcGePoint3d center( center() ); gripPoints.append( center ); AcGeVector3d xoff( radius(), 0, 0 ), yoff( 0, radius(), 0 ); gripPoints.append( center + xoff ); gripPoints.append( center + yoff ); gripPoints.append( center - xoff ); gripPoints.append( center - yoff ); // Grip points to mouth // AcGeLineSeg3d chord( mouthLeft(), mouthRight() ); gripPoints.append( mouthLeft() ); gripPoints.append( mouthRight() ); gripPoints.append( chord.midPoint() ); gripPoints.append( mouthBottom() ); // Grip points to eyes // AcGePoint3dArray eyearray; AcGePoint3d eyecen; eyes( eyearray ); for( int i = 0; i < eyearray.length(); i++ ){ eyecen = eyearray.at( i ); gripPoints.append( eyecen ); AcGeVector3d xoff( meyesize, 0, 0 ), yoff( 0, meyesize, 0 ); gripPoints.append( eyecen + xoff ); gripPoints.append( eyecen + yoff ); gripPoints.append( eyecen - xoff ); gripPoints.append( eyecen - yoff ); } return Acad::eOk; }
Adesk::Boolean AsdkSmiley::worldDraw(AcGiWorldDraw *wd) { assertReadEnabled(); AcGeVector3d offset(0,0,0); AcGeCircArc3d face = mfacecircle; // If dragging, don't fill the smiley // if( wd->isDragging() ){ wd->subEntityTraits().setColor( colorIndex() ); wd->subEntityTraits().setFillType( kAcGiFillNever ); } else wd->subEntityTraits().setFillType( kAcGiFillAlways ); // Give the circle a GS marker of 1 // wd->subEntityTraits().setSelectionMarker( 1 ); wd->geometry().circle( face.center(), face.radius(), mnormal ); if( !wd->isDragging() ) wd->subEntityTraits().setColor( 250 ); // Give the eyes GS markers of 2 etc. // AcGePoint3dArray eyearray; eyes( eyearray ); for( int i = 0; i < eyearray.length(); i++ ){ wd->subEntityTraits().setSelectionMarker( i + 2 ); wd->geometry().circle( eyearray.at(i) + offset, meyesize, mnormal ); } AcGePoint3d smilecen( mouthCenter() + offset ), startpt( mouthLeft() + offset ), endpt( mouthRight() + offset ); AcGeVector3d startvec = startpt - smilecen, endvec = endpt - smilecen; double mouthangle = startvec.angleTo( endvec ); wd->subEntityTraits().setSelectionMarker( eyearray.length() + 2 ); wd->geometry().circularArc( smilecen, mouthRadius(), mnormal, startvec, mouthangle, kAcGiArcChord ); return Adesk::kTrue; }
Acad::ErrorStatus AsdkSmiley::osnapCen( const AcGePoint3d& pickPoint, AcGePoint3dArray& snapPoints) const { // Osnap center to the face's center // snapPoints.append( center() ); // Osnap center to the eyes' center // AcGePoint3dArray eyearray; eyes( eyearray ); for( int i = 0; i < eyearray.length(); i++ ){ snapPoints.append( eyearray.at( i )); } return Acad::eOk; }
void AsdkSmiley::saveAs(AcGiWorldDraw *wd, AcDb::SaveType saveType) { // saveType == AcDb::kR12Save for saveasr12 // saveType == AcDb::kR13Save for proxy graphics save // AcGiRegenType rtype = wd->regenType(); if( AcDb::kR12Save == saveType ) wd->subEntityTraits().setFillType( kAcGiFillNever ); else if( AcDb::kR13Save == saveType ) wd->subEntityTraits().setFillType( kAcGiFillAlways ); // Draw face // wd->geometry().circle( center(), radius(), mnormal ); if( AcDb::kR13Save == saveType ) wd->subEntityTraits().setColor( 250 ); // Draw eyes // AcGePoint3dArray eyearray; eyes( eyearray ); AcGeVector3d eyevec( -1, 0, 0 ); double eyeang = kPi; for( int i = 0; i < eyearray.length(); i++ ){ wd->geometry().circularArc( eyearray.at( i ), meyesize, mnormal, eyevec, eyeang ); } // Draw frown // AcGePoint3d smilecen = center(); smilecen[Y] -= radius() * 1.1; double smilerad = radius() * 0.8; AcGeVector3d smilevec( 1, 1, 0 ); double smileang = kPi / 2; wd->geometry().circularArc( smilecen, smilerad, mnormal, smilevec, smileang, kAcGiArcChord ); }
Acad::ErrorStatus AsdkSmiley::explode(AcDbVoidPtrArray& entities) const { assertReadEnabled(); AcDbCircle *pCircle = new AcDbCircle( center(), mnormal, radius() ); entities.append( pCircle ); // Create eyes // AcGePoint3dArray eyearray; eyes( eyearray ); for( int i = 0; i < eyearray.length(); i++ ){ AcDbCircle *pCircle = new AcDbCircle( eyearray.at(i), mnormal, meyesize ); entities.append( pCircle ); } // Create smile arc // AcGePoint3d smilecen( mouthCenter() ), startpt( mouthLeft() ), endpt( mouthRight() ); AcGeVector3d normvec( 1, 0, 0 ), startvec = startpt - smilecen, endvec = endpt - smilecen; double startang = 2 * kPi - startvec.angleTo( normvec ), endang = 2 * kPi - endvec.angleTo( normvec ); AcDbArc *pArc = new AcDbArc( smilecen, mnormal, mouthRadius(), startang, endang ); entities.append( pArc ); // Create smile arc chord // AcDbLine *pLine = new AcDbLine( startpt, endpt ); entities.append( pLine ); return Acad::eOk; }
int CArxHelper::CreateHatch(AcDbHatch*& pHatch, const AcGePoint3dArray& arrPt,double dScale) { AcGePoint2dArray vertices; AcGeDoubleArray bulges; for (int i = 0; i < arrPt.length(); ++ i) { vertices.append(arrPt.at(i).convert2d(AcGePlane::kXYPlane)); bulges.append(0.0); } if (vertices.length() > 0) { pHatch = new AcDbHatch(); AcGeVector3d normal(0.0, 0.0, 1.0); pHatch->setNormal(normal); pHatch->setElevation(0.0); pHatch->setAssociative(Adesk::kFalse); pHatch->setPattern(AcDbHatch::kPreDefined, _T("SOLID")); pHatch->appendLoop(AcDbHatch::kExternal,vertices,bulges); pHatch->evaluateHatch(); pHatch->setPatternScale(dScale); } return 0; }
Acad::ErrorStatus AsdkSmiley::moveGripPointsAt( const AcDbIntArray& indices, const AcGeVector3d& offset) { assertWriteEnabled(); AcGePoint3dArray eyearray; AcGePoint3d oldquad, newquad, newmouthcenter, newmouthbottom, smilecen, startpt, endpt, midpt, newpt; AcGeVector3d vecstart(0,0,0), vecend(0,0,0), newvec(0,0,0); eyes( eyearray ); for( int i = 0; i < indices.length(); i++ ) { int idx = indices[i]; switch( idx ) { // Stretch smiley center // case 0: setCenter( center() + offset ); continue; // Stretch smiley radius // case 1: oldquad = center() + AcGeVector3d( radius(), 0, 0 ); break; case 2: oldquad = center() + AcGeVector3d( 0, radius(), 0 ); break; case 3: oldquad = center() - AcGeVector3d( radius(), 0, 0 ); break; case 4: oldquad = center() - AcGeVector3d( 0, radius(), 0 ); break; // Stretch smiley mouth // case 5: // Left hand edge of mouth // setMouthLeft( mouthLeft() + offset ); ensureRadius(); continue; case 6: // Right hand edge of mouth // setMouthRight( mouthRight() + offset ); ensureRadius(); continue; case 7: // Middle mouth chord // setMouth( mouthLeft() + offset, mouthBottom() + offset, mouthRight() + offset ); ensureRadius(); continue; case 8: // Bottom of mouth arc // setMouthBottom( mouthBottom() + offset ); ensureRadius(); continue; // Stretch smiley eyes // default: if(( eyearray.length() * 5 ) + 9 > idx ){ // Get eye number, extracting it from the array // int eyepos = (int)(( idx - 9 ) / 5 ); AcGePoint3d eyecen = eyearray.at( eyepos ); // Handle the grip for the eye // int subidx = idx - 9; while ( subidx >= 5 ){ subidx -= 5; } switch( subidx ){ // Stretch eye center // case 0: // Keep the minimum eye height at zero // if( meyesheight+offset[Y] < 0 ) setEyesHeight( 0 ); else setEyesHeight( meyesheight + offset[Y] ); // Keep the eyes from overlapping // if( eyecen[X] < center()[X] ){ // left eye if( meyesapart - ( offset[X] * 2 ) < meyesize * 2 ) setEyesApart( meyesize * 2 ); else setEyesApart( meyesapart - ( offset[X] * 2 )); } else { // right eye if( meyesapart + ( offset[X] * 2 ) < meyesize * 2 ) setEyesApart( meyesize * 2 ); else setEyesApart( meyesapart + ( offset[X] * 2)); } ensureRadius(); continue; // Stretch eye radius // case 1: oldquad = eyecen + AcGeVector3d( meyesize, 0, 0 ); break; case 2: oldquad = eyecen + AcGeVector3d( 0, meyesize, 0 ); break; case 3: oldquad = eyecen - AcGeVector3d( meyesize, 0, 0 ); break; case 4: oldquad = eyecen - AcGeVector3d( 0, meyesize, 0 ); break; } newquad = oldquad + offset; // Keep eyes from touching // if( newquad.distanceTo( eyecen ) > meyesapart / 2 ) setEyeSize( meyesapart / 2 ); else setEyeSize( newquad.distanceTo( eyecen )); ensureRadius(); } continue; } newquad = oldquad + offset; scaleRadius( newquad.distanceTo( center() )); } return Acad::eOk; }