Skip to content

Commit

Permalink
使用MgShapeIterator迭代图形,为MgComposite增加控制点。
Browse files Browse the repository at this point in the history
  • Loading branch information
rhcad committed Oct 22, 2013
1 parent 6fd4fb4 commit 0e7b2d6
Show file tree
Hide file tree
Showing 17 changed files with 138 additions and 130 deletions.
25 changes: 7 additions & 18 deletions android/core/jni/touchvg_java_wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22501,22 +22501,22 @@ SWIGEXPORT void JNICALL Java_touchvg_core_touchvgJNI_delete_1MgShapeIterator(JNI
}


SWIGEXPORT jlong JNICALL Java_touchvg_core_touchvgJNI_MgShapeIterator_1getFirstShape(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
jlong jresult = 0 ;
SWIGEXPORT jboolean JNICALL Java_touchvg_core_touchvgJNI_MgShapeIterator_1hasNext(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
jboolean jresult = 0 ;
MgShapeIterator *arg1 = (MgShapeIterator *) 0 ;
MgShape *result = 0 ;
bool result;

(void)jenv;
(void)jcls;
(void)jarg1_;
arg1 = *(MgShapeIterator **)&jarg1;
result = (MgShape *)(arg1)->getFirstShape();
*(MgShape **)&jresult = result;
result = (bool)(arg1)->hasNext();
jresult = (jboolean)result;
return jresult;
}


SWIGEXPORT jlong JNICALL Java_touchvg_core_touchvgJNI_MgShapeIterator_1getNextShape(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
SWIGEXPORT jlong JNICALL Java_touchvg_core_touchvgJNI_MgShapeIterator_1getNext(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
jlong jresult = 0 ;
MgShapeIterator *arg1 = (MgShapeIterator *) 0 ;
MgShape *result = 0 ;
Expand All @@ -22525,23 +22525,12 @@ SWIGEXPORT jlong JNICALL Java_touchvg_core_touchvgJNI_MgShapeIterator_1getNextSh
(void)jcls;
(void)jarg1_;
arg1 = *(MgShapeIterator **)&jarg1;
result = (MgShape *)(arg1)->getNextShape();
result = (MgShape *)(arg1)->getNext();
*(MgShape **)&jresult = result;
return jresult;
}


SWIGEXPORT void JNICALL Java_touchvg_core_touchvgJNI_MgShapeIterator_1freeIterator(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
MgShapeIterator *arg1 = (MgShapeIterator *) 0 ;

(void)jenv;
(void)jcls;
(void)jarg1_;
arg1 = *(MgShapeIterator **)&jarg1;
(arg1)->freeIterator();
}


SWIGEXPORT jlong JNICALL Java_touchvg_core_touchvgJNI_new_1MgLine(JNIEnv *jenv, jclass jcls) {
jlong jresult = 0 ;
MgLine *result = 0 ;
Expand Down
13 changes: 4 additions & 9 deletions android/core/src/touchvg/core/MgShapeIterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,13 @@ public MgShapeIterator(MgShapes shapes) {
this(touchvgJNI.new_MgShapeIterator(MgShapes.getCPtr(shapes), shapes), true);
}

public MgShape getFirstShape() {
long cPtr = touchvgJNI.MgShapeIterator_getFirstShape(swigCPtr, this);
return (cPtr == 0) ? null : new MgShape(cPtr, false);
public boolean hasNext() {
return touchvgJNI.MgShapeIterator_hasNext(swigCPtr, this);
}

public MgShape getNextShape() {
long cPtr = touchvgJNI.MgShapeIterator_getNextShape(swigCPtr, this);
public MgShape getNext() {
long cPtr = touchvgJNI.MgShapeIterator_getNext(swigCPtr, this);
return (cPtr == 0) ? null : new MgShape(cPtr, false);
}

public void freeIterator() {
touchvgJNI.MgShapeIterator_freeIterator(swigCPtr, this);
}

}
5 changes: 2 additions & 3 deletions android/core/src/touchvg/core/touchvgJNI.java
Original file line number Diff line number Diff line change
Expand Up @@ -792,9 +792,8 @@ public class touchvgJNI {
public final static native boolean MgShapes_isKindOf(long jarg1, MgShapes jarg1_, int jarg2);
public final static native long new_MgShapeIterator(long jarg1, MgShapes jarg1_);
public final static native void delete_MgShapeIterator(long jarg1);
public final static native long MgShapeIterator_getFirstShape(long jarg1, MgShapeIterator jarg1_);
public final static native long MgShapeIterator_getNextShape(long jarg1, MgShapeIterator jarg1_);
public final static native void MgShapeIterator_freeIterator(long jarg1, MgShapeIterator jarg1_);
public final static native boolean MgShapeIterator_hasNext(long jarg1, MgShapeIterator jarg1_);
public final static native long MgShapeIterator_getNext(long jarg1, MgShapeIterator jarg1_);
public final static native long new_MgLine();
public final static native void delete_MgLine(long jarg1);
public final static native long MgLine_create();
Expand Down
Binary file modified android/test/libs/armeabi/libdemocmds.so
Binary file not shown.
Binary file modified android/test/libs/armeabi/libtouchvg.so
Binary file not shown.
6 changes: 2 additions & 4 deletions core/mgr_src/cmdbasic/mgcmderase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,15 @@ bool MgCmdErase::isIntersectMode(const MgMotion*)
bool MgCmdErase::touchMoved(const MgMotion* sender)
{
Box2d snap(sender->startPtM, sender->pointM);
void *it = NULL;
MgShape* shape = m_boxsel ? sender->view->shapes()->getFirstShape(it) : NULL;
MgShapeIterator it(m_boxsel ? sender->view->shapes() : NULL);

m_delIds.clear();
for (; shape; shape = sender->view->shapes()->getNextShape(it)) {
while (MgShape* shape = it.getNext()) {
if (isIntersectMode(sender) ? shape->shape()->hitTestBox(snap)
: snap.contains(shape->shape()->getExtent())) {
m_delIds.push_back(shape->getID());
}
}
sender->view->shapes()->freeIterator(it);
sender->view->redraw();

return true;
Expand Down
5 changes: 2 additions & 3 deletions core/mgr_src/cmdmgr/mgcmdmgr2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,14 @@ void MgCmdManagerImpl::eraseWnd(const MgMotion* sender)
{
Box2d snap(sender->view->xform()->getWndRectM());
std::vector<int> delIds;
void *it = NULL;
MgShapes* s = sender->view->shapes();
MgShapeIterator it(s);

for (MgShape* shape = s->getFirstShape(it); shape; shape = s->getNextShape(it)) {
while (MgShape* shape = it.getNext()) {
if (shape->shape()->hitTestBox(snap)) {
delIds.push_back(shape->getID());
}
}
s->freeIterator(it);

if (!delIds.empty()
&& sender->view->shapeWillDeleted(s->findShape(delIds.front()))) {
Expand Down
12 changes: 4 additions & 8 deletions core/mgr_src/cmdmgr/mgcmdselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -842,20 +842,18 @@ bool MgCmdSelect::touchMoved(const MgMotion* sender)

if (m_clones.empty() && m_boxsel) { // 没有选中图形时就滑动多选
Box2d snap(sender->startPtM, sender->pointM);
void *it = NULL;
MgShape* shape = sender->view->shapes()->getFirstShape(it);
MgShapeIterator it(sender->view->shapes());

m_selIds.clear();
m_id = 0;
m_hit.segment = -1;
for (; shape; shape = sender->view->shapes()->getNextShape(it)) {
while (MgShape* shape = it.getNext()) {
if (isIntersectMode(sender) ? shape->shape()->hitTestBox(snap)
: snap.contains(shape->shape()->getExtent())) {
m_selIds.push_back(shape->getID());
m_id = shape->getID();
}
}
sender->view->shapes()->freeIterator(it);
sender->view->redraw();
}

Expand Down Expand Up @@ -1039,7 +1037,7 @@ bool MgCmdSelect::selectAll(const MgMotion* sender)
{
MgShapesLock locker(MgShapesLock::ReadOnly, sender->view);
size_t oldn = m_selIds.size();
void* it = NULL;
MgShapeIterator it(sender->view->shapes());

m_selIds.clear();
m_handleIndex = 0;
Expand All @@ -1048,12 +1046,10 @@ bool MgCmdSelect::selectAll(const MgMotion* sender)
m_boxsel = false;
m_hit.segment = -1;

for (MgShape* shape = sender->view->shapes()->getFirstShape(it);
shape; shape = sender->view->shapes()->getNextShape(it)) {
while (MgShape* shape = it.getNext()) {
m_selIds.push_back(shape->getID());
m_id = shape->getID();
}
sender->view->shapes()->freeIterator(it);
sender->view->redraw();

if (oldn != m_selIds.size() || !m_selIds.empty()) {
Expand Down
7 changes: 2 additions & 5 deletions core/mgr_src/cmdmgr/mgsnapimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,9 @@ static void snapPoints(const MgMotion* sender, const Point2d& orignPt,
Box2d snapbox(orignPt, 2 * arr[0].dist, 0); // 捕捉容差框
GiTransform* xf = sender->view->xform();
Box2d wndbox(xf->getWndRectM());
void* it = NULL;
MgShapeIterator it(sender->view->shapes());

for (const MgShape* sp = sender->view->shapes()->getFirstShape(it);
sp; sp = sender->view->shapes()->getNextShape(it)) {

while (const MgShape* sp = it.getNext()) {
if (skipShape(ignoreids, sp)) {
continue;
}
Expand All @@ -235,7 +233,6 @@ static void snapPoints(const MgMotion* sender, const Point2d& orignPt,
snapGrid(sender, orignPt, shape, ignoreHandle, sp, arr, matchpt);
}
}
sender->view->shapes()->freeIterator(it);
}

// hotHandle: 绘新图时,起始步骤为-1,后续步骤>0;拖动一个或多个整体图形时为-1,拖动顶点时>=0
Expand Down
2 changes: 1 addition & 1 deletion core/pub_inc/shape/mgcomposite.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class MgComposite : public MgBaseShape
Point2d _getHandlePoint(int index) const;
int _getHandleType(int index) const;
bool _setHandlePoint(int index, const Point2d& pt, float tol);
bool _isHandleFixed(int index) const { return index > 0; }
bool _isHandleFixed(int index) const;
void _update();
void _clearCachedData();
void _transform(const Matrix2d& mat);
Expand Down
35 changes: 28 additions & 7 deletions core/pub_inc/shape/mgshapes.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class MgShapes : public MgObject
#ifndef SWIG
MgShape* getFirstShape(void*& it) const;
MgShape* getNextShape(void*& it) const;
void freeIterator(void*& it);
void freeIterator(void*& it) const;
typedef bool (*Filter)(const MgShape*);
#endif

Expand Down Expand Up @@ -103,21 +103,42 @@ class MgShapes : public MgObject

//! 遍历图形的辅助类
/*! \ingroup CORE_SHAPE
遍历过程中要避免增删图形。
*/
class MgShapeIterator
{
public:
MgShapeIterator(const MgShapes* shapes) : _s(shapes), _it(NULL) {}
~MgShapeIterator() { freeIterator(); }

MgShape* getFirstShape() { return _s->getFirstShape(_it); }
MgShape* getNextShape() { return _s->getNextShape(_it); }
void freeIterator() { _s->getNextShape(_it); }
//! 给定图形列表(可为空)构造迭代器
MgShapeIterator(const MgShapes* shapes) : _s(shapes), _it(NULL), _sp(NULL) {}
~MgShapeIterator() { if (_it && _s) _s->freeIterator(_it); }

//! 检查是否还有图形可遍历
bool hasNext() {
if (!_it && _s) {
_sp = _s->getFirstShape(_it);
}
return !!_sp;
}

//! 得到当前遍历位置的图形
/*! 可使用 while (MgShape* sp = it.getNext()) {...} 遍历。
*/
MgShape* getNext() {
if (!_it && _s) {
_sp = _s->getFirstShape(_it);
}
MgShape* sp = _sp;
if (_sp && _s) {
_sp = _s->getNextShape(_it);
}
return sp;
}

private:
MgShapeIterator();
const MgShapes* _s;
void* _it;
MgShape* _sp;
};

#endif // TOUCHVG_MGSHAPES_H_
Loading

0 comments on commit 0e7b2d6

Please sign in to comment.